Skip to content

Commit

Permalink
Hotfix for WalletConnect connection (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Jan 24, 2024
1 parent aaaa221 commit fd6ed08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const WalletConnectActiveSessions = () => {
<ul>
<li>Namespace: {session.requiredNamespaces?.polkadot?.chains?.join(', ')}</li>
<li>Methods: {session.requiredNamespaces?.polkadot?.methods?.join(', ')}</li>
<li>Events: {session.requiredNamespaces?.polkadot?.events?.join(', ')}</li>
<li>Expiring: {expiryDate.toDateString()}</li>
</ul>
</div>
Expand Down
33 changes: 18 additions & 15 deletions packages/ui/src/components/modals/WalletConnectSessionProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P
return getAccountsWithNamespace(accountsToShare)
}, [getAccountsWithNamespace, selectedMultiProxy?.multisigs, selectedMultiProxy?.proxy])

const { methods, events, chains } = useMemo(
() =>
sessionProposal?.params.requiredNamespaces?.polkadot || {
methods: [],
events: [],
chains: []
},
[sessionProposal?.params.requiredNamespaces?.polkadot]
)

useEffect(() => {
if (!web3wallet || !sessionProposal) return

const wCRequestedNetwork = sessionProposal?.params.requiredNamespaces?.polkadot?.chains?.[0]
const wCRequestedNetwork = chains?.[0]

if (wCRequestedNetwork !== currentNamespace) {
setErrorMessage(
Expand All @@ -42,7 +52,7 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P
- Current: ${currentNamespace}`
)
}
}, [currentNamespace, sessionProposal, web3wallet])
}, [chains, currentNamespace, sessionProposal, web3wallet])

const onApprove = useCallback(() => {
if (!web3wallet || !sessionProposal) return
Expand All @@ -53,8 +63,8 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P
namespaces: {
polkadot: {
accounts: accountsToShare,
methods: sessionProposal.params.requiredNamespaces?.polkadot?.methods,
events: []
methods,
events
}
}
})
Expand All @@ -63,7 +73,7 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P
onClose()
refresh()
})
}, [accountsToShare, onClose, refresh, sessionProposal, web3wallet])
}, [accountsToShare, events, methods, onClose, refresh, sessionProposal, web3wallet])

const onReject = useCallback(() => {
if (!web3wallet || !sessionProposal) return
Expand Down Expand Up @@ -99,16 +109,9 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P
<br />
<AppInfoStyled>Website:</AppInfoStyled> {sessionProposal?.params.proposer.metadata.url}
<br />
<AppInfoStyled>Methods:</AppInfoStyled>{' '}
{sessionProposal?.params.requiredNamespaces?.polkadot?.methods?.map(
(method, index) =>
`${method}${
index ===
(sessionProposal?.params.requiredNamespaces?.polkadot?.methods?.length - 1 || 0)
? ''
: ', '
}`
)}
<AppInfoStyled>Methods:</AppInfoStyled> {methods.join(', ')}
<br />
<AppInfoStyled>Events:</AppInfoStyled> {events.join(', ')}
</Grid>
<Grid
item
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/hooks/useWalletConnectEventsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function useWalletConnectEventsManager() {
// Open session proposal modal for confirmation / rejection
const onSessionProposal = useCallback(
(proposal: SignClientTypes.EventArguments['session_proposal']) => {
console.info('WalletConnect session_proposal', proposal)
openWalletConnectSessionModal({ sessionProposal: proposal })
},
[openWalletConnectSessionModal]
Expand All @@ -30,7 +31,7 @@ export default function useWalletConnectEventsManager() {
console.error('web3Wallet is undefined')
return
}
console.log('---> session_request', requestEvent)
console.info('WalletConnect session_request', requestEvent)
const { topic, params } = requestEvent
const { request } = params
const requestSession = web3wallet.engine.signClient.session.get(topic)
Expand Down

0 comments on commit fd6ed08

Please sign in to comment.