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(wallets): prevent WalletConnect v1 session data collision #329

Merged
merged 1 commit into from
Dec 18, 2024
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
23 changes: 23 additions & 0 deletions packages/use-wallet/src/__tests__/wallets/defly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,29 @@ describe('DeflyWallet', () => {
expect(store.state.wallets[WalletId.DEFLY]).toBeUndefined()
expect(wallet.isConnected).toBe(false)
})

it('should skip reconnectSession if Pera is active', async () => {
const walletState: WalletState = {
accounts: [account1],
activeAccount: account1
}

store = new Store<State>({
...defaultState,
activeWallet: WalletId.PERA,
wallets: {
[WalletId.DEFLY]: walletState
}
})

wallet = createWalletWithStore(store)

await wallet.resumeSession()

expect(mockLogger.info).toHaveBeenCalledWith('Skipping reconnectSession for Defly (inactive)')
expect(mockDeflyWallet.reconnectSession).not.toHaveBeenCalled()
expect(store.state.wallets[WalletId.DEFLY]).toEqual(walletState)
})
})

describe('setActive', () => {
Expand Down
23 changes: 23 additions & 0 deletions packages/use-wallet/src/__tests__/wallets/pera.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,29 @@ describe('PeraWallet', () => {
expect(store.state.wallets[WalletId.PERA]).toBeUndefined()
expect(wallet.isConnected).toBe(false)
})

it('should skip reconnectSession if Defly is active', async () => {
const walletState: WalletState = {
accounts: [account1],
activeAccount: account1
}

store = new Store<State>({
...defaultState,
activeWallet: WalletId.DEFLY,
wallets: {
[WalletId.PERA]: walletState
}
})

wallet = createWalletWithStore(store)

await wallet.resumeSession()

expect(mockLogger.info).toHaveBeenCalledWith('Skipping reconnectSession for Pera (inactive)')
expect(mockPeraWallet.reconnectSession).not.toHaveBeenCalled()
expect(store.state.wallets[WalletId.PERA]).toEqual(walletState)
})
})

describe('setActive', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/use-wallet/src/wallets/defly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export class DeflyWallet extends BaseWallet {
return
}

// If Pera is active, skip reconnectSession for Defly
if (state.activeWallet === WalletId.PERA) {
this.logger.info('Skipping reconnectSession for Defly (inactive)')
return
}

this.logger.info('Resuming session...')

const client = this.client || (await this.initializeClient())
Expand Down
6 changes: 6 additions & 0 deletions packages/use-wallet/src/wallets/pera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ export class PeraWallet extends BaseWallet {
return
}

// If Defly is active, skip reconnectSession for Pera
if (state.activeWallet === WalletId.DEFLY) {
this.logger.info('Skipping reconnectSession for Pera (inactive)')
return
}

this.logger.info('Resuming session...')

const client = this.client || (await this.initializeClient())
Expand Down
Loading