Skip to content

Commit

Permalink
fix(background): better error message for connectWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Jul 5, 2024
1 parent caf3d93 commit 0585d57
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
},
"siteNotMonetized": {
"message": "This website is not monetized."
},
"error_connectWallet_invalidClient": {
"message": "Failed to connect. Did you copy the public key to the right wallet address?"
}
}
16 changes: 13 additions & 3 deletions src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import type { AccessToken, GrantDetails, WalletAmount } from 'shared/types'
import {
type AuthenticatedClient,
createAuthenticatedClient
createAuthenticatedClient,
OpenPaymentsClientError
} from '@interledger/open-payments/dist/client'
import {
isFinalizedGrant,
Expand All @@ -25,7 +26,7 @@ import {
import { StorageService } from '@/background/services/storage'
import { exportJWK, generateEd25519KeyPair } from '@/shared/crypto'
import { bytesToHex } from '@noble/hashes/utils'
import { getWalletInformation } from '@/shared/helpers'
import { getWalletInformation, type Translation } from '@/shared/helpers'
import { ConnectWalletPayload } from '@/shared/messages'
import {
DEFAULT_RATE_OF_PAY,
Expand Down Expand Up @@ -97,7 +98,8 @@ export class OpenPaymentsService {
constructor(
private browser: Browser,
private storage: StorageService,
private deduplicator: Deduplicator
private deduplicator: Deduplicator,
private t: Translation
) {
void this.initialize()
}
Expand Down Expand Up @@ -307,6 +309,14 @@ export class OpenPaymentsService {
clientNonce,
walletAddress,
amount: transformedAmount
}).catch((err) => {
if (err instanceof OpenPaymentsClientError) {
if (err.status === 400 && err.code === 'invalid_client') {
const msg = this.t('error_connectWallet_invalidClient')
throw new Error(msg, { cause: err })
}
}
throw err
})

// Q: Should this be moved to continuation polling?
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"baseUrl": "./src",
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2020",
"target": "ES2022",
"allowJs": true,
"jsx": "react",
"sourceMap": true,
Expand Down

0 comments on commit 0585d57

Please sign in to comment.