Skip to content

Commit

Permalink
feat(pera): add auto-connect for Pera Discover browser
Browse files Browse the repository at this point in the history
Add automatic connection attempt when Pera wallet is initialized in the Pera
Discover browser environment. The connection attempt is handled silently with
appropriate logging for success and failure cases.
  • Loading branch information
drichar committed Dec 6, 2024
1 parent d1a9696 commit 5947c62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/use-wallet/src/wallets/pera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ export class PeraWallet extends BaseWallet {
super({ id, metadata, getAlgodClient, store, subscribe, networks })
this.options = options
this.store = store

const isPeraDiscover = window.navigator.userAgent.includes('pera')

if (isPeraDiscover) {
this.logger.info('Pera Discover browser detected, auto connecting...')
void this.connect()
.then(() => {
this.logger.info('Auto-connect successful')
})
.catch((error) => {
this.logger.warn('Auto-connect failed:', error.message)
})
}
}

static defaultMetadata = {
Expand Down
13 changes: 13 additions & 0 deletions packages/use-wallet/src/wallets/pera2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export class PeraWallet extends BaseWallet {
}
this.options = options
this.store = store

const isPeraDiscover = window.navigator.userAgent.includes('pera')

if (isPeraDiscover) {
this.logger.info('Pera Discover browser detected, auto connecting...')
void this.connect()
.then(() => {
this.logger.info('Auto-connect successful')
})
.catch((error) => {
this.logger.warn('Auto-connect failed:', error.message)
})
}
}

static defaultMetadata = {
Expand Down

0 comments on commit 5947c62

Please sign in to comment.