Skip to content

Commit

Permalink
handle more issues on errors gone on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Oct 2, 2024
1 parent a19404f commit 975e292
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ export class OpenPaymentsService {
);
} catch (error) {
if (
error.message === this.t('connectWallet_error_invalidClient') &&
isErrorWithKey(error) &&
error.key === 'connectWallet_error_invalidClient' &&
!skipAutoKeyShare
) {
// add key to wallet and try again
Expand Down Expand Up @@ -460,6 +461,9 @@ export class OpenPaymentsService {
amount: transformedAmount,
}).catch((err) => {
if (isInvalidClientError(err)) {
if (intent === InteractionIntent.CONNECT) {
throw new ErrorWithKey('connectWallet_error_invalidClient');
}
const msg = this.t('connectWallet_error_invalidClient');
throw new Error(msg, { cause: err });
}
Expand Down
10 changes: 7 additions & 3 deletions src/popup/components/ConnectWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export const ConnectWalletForm = ({
defaultValues.recurring || false,
);
const [autoKeyShareFailed, setAutoKeyShareFailed] = React.useState(
state?.status === 'error',
state?.status === 'error' ||
(state?.status === 'error:key' &&
typeof state.error !== 'string' &&
state.error.key.startsWith('connectWalletKeyService_error_')),
);

const [walletAddressInfo, setWalletAddressInfo] =
Expand Down Expand Up @@ -251,6 +254,7 @@ export const ConnectWalletForm = ({
autoComplete="on"
spellCheck={false}
enterKeyHint="go"
readOnly={isSubmitting}
onPaste={async (ev) => {
const input = ev.currentTarget;
let value = ev.clipboardData.getData('text');
Expand Down Expand Up @@ -298,7 +302,7 @@ export const ConnectWalletForm = ({
placeholder="5.00"
className="max-w-32"
defaultValue={amount}
readOnly={!walletAddressInfo?.assetCode}
readOnly={!walletAddressInfo?.assetCode || isSubmitting}
addOn={<span className="text-weak">{currencySymbol.symbol}</span>}
aria-invalid={!!errors.amount}
aria-describedby={errors.amount}
Expand Down Expand Up @@ -337,7 +341,7 @@ export const ConnectWalletForm = ({
details: errors.keyPair,
whyText: t('connectWallet_error_failedAutoKeyAddWhy'),
}}
hideError={autoKeyShareFailed}
hideError={!errors.keyPair}
text={t('connectWallet_label_publicKey')}
learnMoreText={t('connectWallet_text_publicKeyLearnMore')}
publicKey={publicKey}
Expand Down

0 comments on commit 975e292

Please sign in to comment.