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

Fix wc regression bug #648

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/ui/src/contexts/AccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface IAccountContext {
const AccountContext = createContext<IAccountContext | undefined>(undefined)

const AccountContextProvider = ({ children }: AccountContextProps) => {
const { currentNamespace } = useGetWalletConnectNamespace()
const { walletConnectId } = useGetWalletConnectNamespace()
const redotAccountList = useRedotAccounts()
const { chainInfo } = useApi()
const ownAccountList = useMemo(() => {
Expand All @@ -45,10 +45,10 @@ const AccountContextProvider = ({ children }: AccountContextProps) => {
// for this reason, we need to filter out the accounts that are not for the current network
// this only applies to wallet-connect accounts
const filteredAccounts = redotAccountList.filter((account) => {
return account.wallet.id !== 'wallet-connect' || account.genesisHash === currentNamespace
return account.wallet.id !== 'wallet-connect' || account.genesisHash === walletConnectId
})
return encodeAccounts(filteredAccounts, chainInfo.ss58Format)
}, [chainInfo, currentNamespace, redotAccountList])
}, [chainInfo, walletConnectId, redotAccountList])

const [selectedAccount, setSelected] = useState<InjectedPolkadotAccount | undefined>(
ownAccountList?.[0]
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/hooks/useSigningCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const useSigningCallback = ({ onSubmitting, onSuccess, onFinalized, onErr
error: (e: Error) => {
console.error(e)
const error = translateError(e)
addToast({ title: error.message ?? error.toString(), type: 'error' })
addToast({ title: error, type: 'error' })
onError && onError()
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/ui/src/hooks/useWalletConnectNamespace.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useApi } from '../contexts/ApiContext'
import { getWalletConnectId } from '../utils/getWalletConnectId'
import { getWalletConnectNameSpace } from '../utils/getWalletConnectNameSpace'

export const useGetWalletConnectNamespace = () => {
const { client } = useApi()
Expand All @@ -17,7 +18,9 @@ export const useGetWalletConnectNamespace = () => {
.finally(() => setIsLoading(false))
}, [client])

const namespace = useMemo(() => getWalletConnectId(genesisHash), [genesisHash])
const walletConnectId = useMemo(() => getWalletConnectId(genesisHash), [genesisHash])

const namespace = useMemo(() => getWalletConnectNameSpace(walletConnectId), [walletConnectId])

const getAccountsWithNamespace = useCallback(
(accounts: string[]) => {
Expand All @@ -26,5 +29,5 @@ export const useGetWalletConnectNamespace = () => {
[namespace]
)

return { currentNamespace: namespace, getAccountsWithNamespace, isLoading }
return { walletConnectId, currentNamespace: namespace, getAccountsWithNamespace, isLoading }
}
10 changes: 0 additions & 10 deletions packages/ui/src/utils/getAllNetworkWalletConnectIds.ts

This file was deleted.

14 changes: 14 additions & 0 deletions packages/ui/src/utils/getAllNetworkWalletConnectNameSpaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { networkList } from '../constants'
import { getWalletConnectId } from './getWalletConnectId'
import { getWalletConnectNameSpace } from './getWalletConnectNameSpace'

export const getAllNetworkWalletConnectNameSpaces = (): string[] => {
return (
Object.values(networkList)
.map((network) => network.genesisHash)
.filter(Boolean) as string[]
).map((genesisHash) => {
const id = getWalletConnectId(genesisHash)
return getWalletConnectNameSpace(id)
})
}
1 change: 1 addition & 0 deletions packages/ui/src/utils/getWalletConnectNameSpace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getWalletConnectNameSpace = (id: string) => `polkadot:${id}`
2 changes: 1 addition & 1 deletion packages/ui/src/utils/translateError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const translateError = (error: any) => {
return 'Not enough funds to pay for the tx'
}

return error.toString()
return error.message || error.toString()
}

export const translateErrorInfo = (errorInfo: string) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/walletConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { registerDotConnect } from 'dot-connect'
import { DAPP_NAME, WALLETCONNECT_PROJECT_ID } from './constants'
import { WalletConnect } from '@reactive-dot/wallet-walletconnect'
import { defineConfig } from '@reactive-dot/core'
import { getAllNetworkWalletConnectIds } from './utils/getAllNetworkWalletConnectIds'
import { getAllNetworkWalletConnectNameSpaces } from './utils/getAllNetworkWalletConnectNameSpaces'

export const config = defineConfig({
chains: {},
Expand All @@ -19,7 +19,7 @@ export const config = defineConfig({
icons: ['https://multix.chainsafe.io/android-chrome-192x192.png?raw=true']
}
},
optionalChainIds: getAllNetworkWalletConnectIds()
optionalChainIds: getAllNetworkWalletConnectNameSpaces()
})
]
})
Expand Down
Loading