Skip to content

Commit

Permalink
fix: aligned fix with previous flow
Browse files Browse the repository at this point in the history
  • Loading branch information
isordo committed Sep 21, 2023
1 parent 46982d5 commit 50210ed
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,15 +982,6 @@ export class DAppClient extends Client {

this.analytics.track('event', 'DAppClient', 'Permission requested')

await this.init()

const transport = await this.transport

if (transport instanceof WalletConnectTransport && !transport.pairings?.length) {
await this.channelClosedHandler()
throw new Error('Pairing expired.')
}

const { message, connectionInfo } = await this.makeRequest<
PermissionRequest,
PermissionResponse
Expand Down Expand Up @@ -1560,6 +1551,17 @@ export class DAppClient extends Client {
logger.timeLog(messageId, 'init done')
logger.log('makeRequest', 'after init')

const transport = await this.transport

if (
requestInput.type === BeaconMessageType.PermissionRequest &&
transport instanceof WalletConnectTransport &&
!transport.pairings?.length
) {
await this.channelClosedHandler()
throw new Error('Pairing expired.')
}

if (await this.addRequestAndCheckIfRateLimited()) {
this.events
.emit(BeaconEvent.LOCAL_RATE_LIMIT_REACHED)
Expand Down Expand Up @@ -1607,7 +1609,7 @@ export class DAppClient extends Client {
logger.log('makeRequest', 'sending message', request)
logger.timeLog('makeRequest', messageId, 'sending')
try {
await (await this.transport).send(payload, peer)
await transport.send(payload, peer)
} catch (sendError) {
this.events.emit(BeaconEvent.INTERNAL_ERROR, {
text: 'Unable to send message. If this problem persists, please reset the connection and pair your wallet again.',
Expand Down Expand Up @@ -1676,6 +1678,17 @@ export class DAppClient extends Client {
throw new Error('rate limit reached')
}

const transport = await this.transport

if (
requestInput.type === BeaconMessageType.PermissionRequest &&
transport instanceof WalletConnectTransport &&
!transport.pairings?.length
) {
await this.channelClosedHandler()
throw new Error('Pairing expired.')
}

// if (!(await this.checkPermissions(requestInput.type as BeaconMessageType))) {
// this.events.emit(BeaconEvent.NO_PERMISSIONS).catch((emitError) => console.warn(emitError))

Expand Down Expand Up @@ -1714,7 +1727,7 @@ export class DAppClient extends Client {
logger.log('makeRequest', 'sending message', request)
logger.timeLog('makeRequest', messageId, 'sending')
try {
await (await this.transport).send(payload, peer)
await transport.send(payload, peer)
} catch (sendError) {
this.events.emit(BeaconEvent.INTERNAL_ERROR, {
text: 'Unable to send message. If this problem persists, please reset the connection and pair your wallet again.',
Expand Down

0 comments on commit 50210ed

Please sign in to comment.