Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to alwaysHex #61

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ const getWindowEthereum = () => {
}
}

// always get chainId as number
const alwaysNumber = (n) =>
Web3.utils.isHex(n) ? Web3.utils.hexToNumber(n) : n
// always get chainId as number EDIT: Always as hex
const alwaysHex = (n) => (Web3.utils.isHex(n) ? n : Web3.utils.toHex(n))

export const createStore = () => {
const { emit, get, subscribe, assign, deleteAll } = proxied()
Expand All @@ -53,7 +52,7 @@ export const createStore = () => {
}) => {
// console.log('switch1193Provider', { accounts, chainId }, get('web3'), get('eipProvider'))
if (!chainId) {
chainId = alwaysNumber(await get('web3').eth.getChainId())
chainId = alwaysHex(await get('web3').eth.getChainId())
}
if (!accounts) {
accounts = await get('web3').eth.getAccounts()
Expand All @@ -76,7 +75,7 @@ export const createStore = () => {

const accountsChangedHandler = (accounts) => switch1193Provider({ accounts })
const chainChangedHandler = (chainId) =>
switch1193Provider({ chainId: alwaysNumber(chainId) })
switch1193Provider({ chainId: alwaysHex(chainId) })
// TODO better error support ?
const disconnectHandler = (error) => switch1193Provider({ error })

Expand Down Expand Up @@ -138,7 +137,7 @@ export const createStore = () => {
return set1193Provider(provider, addressOrIndex)
init()
const web3 = new Web3(provider)
const chainId = alwaysNumber(await web3.eth.getChainId())
const chainId = alwaysHex(await web3.eth.getChainId())
let accounts = []
try {
// not all provider support accounts
Expand Down