Skip to content

Commit

Permalink
Retry wallet connect init every 2 seconds if it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits authored and paullinator committed Jan 11, 2024
1 parent e6304d2 commit ae7c9e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- changed: Do not write tx.metadata in fiat sell transactions
- changed: Use new EdgeTransaction.savedAction to show extended transaction info in tx list and tx details
- changed: Use new EdgeTxAction data for Thorchain and Tron stake plugins
- changed: Rettry failed WalletConnect initializations
- fixed: USP vs legacy landing experiment distribution
- fixed: Paybis sell from Tron USDT
- fixed: Remove `minWidth` style from stake option card
Expand Down
33 changes: 23 additions & 10 deletions src/components/services/WalletConnectService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import { ENV } from '../../env'
import { useAsyncEffect } from '../../hooks/useAsyncEffect'
import { getAccounts, getClient, getWalletIdFromSessionNamespace, waitingClients, walletConnectClient } from '../../hooks/useWalletConnect'
import { asLegacyTokenId } from '../../types/types'
import { snooze } from '../../util/utils'
import { WcSmartContractModal } from '../modals/WcSmartContractModal'
import { Airship, showError } from '../services/AirshipInstance'

const TWO_SECONDS = 2000

interface Props {
account: EdgeAccount
}
Expand Down Expand Up @@ -68,17 +71,27 @@ export const WalletConnectService = (props: Props) => {
projectId = ENV.WALLET_CONNECT_INIT.projectId
}

walletConnectClient.client = await Web3Wallet.init({
core: new Core({
projectId
}),
metadata: {
name: 'Edge Wallet',
description: 'Edge Wallet',
url: 'https://www.edge.app',
icons: ['https://content.edge.app/Edge_logo_Icon.png']
// If init fails, retry every 2 seconds
let retrySeconds = 0
while (walletConnectClient.client == null) {
try {
await snooze(retrySeconds)
walletConnectClient.client = await Web3Wallet.init({
core: new Core({
projectId
}),
metadata: {
name: 'Edge Wallet',
description: 'Edge Wallet',
url: 'https://www.edge.app',
icons: ['https://content.edge.app/Edge_logo_Icon.png']
}
})
} catch (e) {
console.error('WalletConnectService init error', e)
if (retrySeconds < TWO_SECONDS) retrySeconds = TWO_SECONDS
}
})
}
}

const handleSessionRequestSync = (event: Web3WalletTypes.SessionRequest) => {
Expand Down

0 comments on commit ae7c9e0

Please sign in to comment.