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(background): better error message for connectWallet #396

Merged
merged 4 commits into from
Jul 8, 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
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": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this convention for future:

  • error_* for error messages
  • action_* for button/link actions
  • state_* mostly everything else
  • and rest can be anything I guess?

Can't use / or . or : unfortunately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest error_openPayments_invalidClient for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not going for openPayments here as this error is specific to one we show during connect wallet. When it happens during payment (openPayments_invalidClient again), we go for "key revoked" state which has its own error messages. We might show a different one during reconnectWallet even.

"message": "Failed to connect. Please make sure you have added the public key to the correct 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",
sidvishnoi marked this conversation as resolved.
Show resolved Hide resolved
"allowJs": true,
"jsx": "react",
"sourceMap": true,
Expand Down
Loading