Skip to content

Commit

Permalink
Merge pull request #73 from gnosis/wc2-gc-fix
Browse files Browse the repository at this point in the history
fix walletconnect on non-mainnet chains
  • Loading branch information
jfschwarz authored Aug 8, 2023
2 parents 57abb8b + 1185e43 commit cc7e9fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions extension/src/providers/useWalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,19 @@ interface WalletConnectResult {
chainId: number | null
}

const useWalletConnect = (connectionId: string): WalletConnectResult | null => {
const useWalletConnect = (
connectionId: string,
connectionChainId: number
): WalletConnectResult | null => {
const [provider, setProvider] =
useState<WalletConnectEthereumMultiProvider | null>(null)
const [connected, setConnected] = useState(
provider ? provider.connected : false
)
const [accounts, setAccounts] = useState(provider ? provider.accounts : [])
const [chainId, setChainId] = useState(provider ? provider.chainId : 1)
const [chainId, setChainId] = useState(
provider ? provider.chainId : connectionChainId
)

// effect to initialize the provider
useEffect(() => {
Expand All @@ -153,7 +158,7 @@ const useWalletConnect = (connectionId: string): WalletConnectResult | null => {
connectionId,
projectId: WALLETCONNECT_PROJECT_ID,
showQrModal: true,
chains: [1],
chains: [connectionChainId],
optionalChains: Object.keys(RPC).map((chainId) => Number(chainId)),
rpcMap: RPC,
})
Expand All @@ -165,7 +170,7 @@ const useWalletConnect = (connectionId: string): WalletConnectResult | null => {
setAccounts(provider.accounts)
setChainId(provider.chainId)
})
}, [connectionId])
}, [connectionId, connectionChainId])

// effect to subscribe to provider events
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/settings/Connection/ConnectButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ConnectButton: React.FC<{ id: string }> = ({ id }) => {
const { connected, connection } = useConnection(id)

const metamask = useMetaMask()
const walletConnect = useWalletConnect(connection.id)
const walletConnect = useWalletConnect(connection.id, connection.chainId || 1)

const connect = (
providerType: ProviderType,
Expand Down
2 changes: 1 addition & 1 deletion extension/src/settings/connectionHooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const useConnection = (id?: string) => {
}

const metamask = useMetaMask()
const walletConnect = useWalletConnect(connection.id)
const walletConnect = useWalletConnect(connection.id, connection.chainId || 1)

const provider: Eip1193Provider =
(connection.providerType === ProviderType.MetaMask
Expand Down

0 comments on commit cc7e9fd

Please sign in to comment.