Skip to content

Commit

Permalink
fix(background/openPayments): 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 1b9f496 commit 03f7e72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 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 connect the public key with the right wallet address?"
}
}
14 changes: 12 additions & 2 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 { tFactory, getWalletInformation } from '@/shared/helpers'
import { ConnectWalletPayload } from '@/shared/messages'
import {
DEFAULT_RATE_OF_PAY,
Expand Down Expand Up @@ -269,6 +270,7 @@ export class OpenPaymentsService {
}: ConnectWalletPayload) {
const walletAddress = await getWalletInformation(walletAddressUrl)
const exchangeRates = await getExchangeRates()
const t = tFactory(this.browser)

let rateOfPay = DEFAULT_RATE_OF_PAY
let minRateOfPay = MIN_RATE_OF_PAY
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 = t('error_connectWallet_invalidClient')
throw new Error(msg, { cause: err })

Check failure on line 316 in src/background/services/openPayments.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected 0-1 arguments, but got 2.
}
}
throw err
})

// Q: Should this be moved to continuation polling?
Expand Down

0 comments on commit 03f7e72

Please sign in to comment.