diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 979f21a6..cda65151 100755 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -128,13 +128,6 @@ "connectWallet_action_connect": { "message": "Connect" }, - "connectWallet_text_footerNotice": { - "message": "We'll automatically connect with your wallet provider." - }, - "connectWallet_text_footerNoticeLearnMore": { - "message": "Learn more", - "description": "Learn more about how this works" - }, "connectWallet_error_urlRequired": { "message": "Wallet address is required." }, @@ -172,9 +165,31 @@ "connectWallet_error_grantRejected": { "message": "Connect wallet cancelled. You rejected the request." }, + "connectWalletKeyService_text_consentP1": { + "message": "We'll automatically connect with your wallet provider." + }, + "connectWalletKeyService_text_consentLearnMore": { + "message": "Learn more", + "description": "Learn more about how this works" + }, + "connectWalletKeyService_text_consentP2": { + "message": "By agreeing, you provide us consent to automatically access your wallet to securely add a key." + }, + "connectWalletKeyService_text_consentP3": { + "message": "Please note, this process does not involve accessing or handling your funds." + }, + "connectWalletKeyService_label_consentAccept": { + "message": "Agree" + }, + "connectWalletKeyService_label_consentDecline": { + "message": "Decline" + }, "connectWalletKeyService_error_notImplemented": { "message": "Automatic key addition is not implemented for given wallet provider yet." }, + "connectWalletKeyService_error_noConsent": { + "message": "You declined consent for automatic key addition." + }, "connectWalletKeyService_error_failed": { "message": "Automatic key addition failed at step “$STEP_ID$” with message “$MESSAGE$”.", "placeholders": { diff --git a/src/background/services/keyAutoAdd.ts b/src/background/services/keyAutoAdd.ts index 2a08df54..2ead6816 100644 --- a/src/background/services/keyAutoAdd.ts +++ b/src/background/services/keyAutoAdd.ts @@ -168,6 +168,15 @@ export class KeyAutoAddService { })); } } + + static supports(walletAddress: WalletAddress): boolean { + try { + void walletAddressToProvider(walletAddress); + return true; + } catch { + return false; + } + } } export function walletAddressToProvider(walletAddress: WalletAddress): { diff --git a/src/background/services/openPayments.ts b/src/background/services/openPayments.ts index 1f7ecec0..d7a23725 100644 --- a/src/background/services/openPayments.ts +++ b/src/background/services/openPayments.ts @@ -340,7 +340,13 @@ export class OpenPaymentsService { this.setConnectState(null); return; } - const { walletAddressUrl, amount, recurring, skipAutoKeyShare } = params; + const { + walletAddressUrl, + amount, + recurring, + autoKeyAdd, + autoKeyAddConsent, + } = params; const walletAddress = await getWalletInformation(walletAddressUrl); const exchangeRates = await getExchangeRates(); @@ -385,8 +391,19 @@ export class OpenPaymentsService { if ( isErrorWithKey(error) && error.key === 'connectWallet_error_invalidClient' && - !skipAutoKeyShare + autoKeyAdd ) { + if (!KeyAutoAddService.supports(walletAddress)) { + this.updateConnectStateError(error); + throw new ErrorWithKey( + 'connectWalletKeyService_error_notImplemented', + ); + } + if (!autoKeyAddConsent) { + this.updateConnectStateError(error); + throw new ErrorWithKey('connectWalletKeyService_error_noConsent'); + } + // add key to wallet and try again try { const tabId = await this.addPublicKeyToWallet(walletAddress); diff --git a/src/popup/components/ConnectWalletForm.tsx b/src/popup/components/ConnectWalletForm.tsx index ece16642..ff655dd9 100644 --- a/src/popup/components/ConnectWalletForm.tsx +++ b/src/popup/components/ConnectWalletForm.tsx @@ -28,6 +28,7 @@ interface Inputs { walletAddressUrl: string; amount: string; recurring: boolean; + autoKeyAddConsent: boolean; } interface ConnectWalletFormProps { @@ -62,9 +63,14 @@ export const ConnectWalletForm = ({ const [recurring, setRecurring] = React.useState( defaultValues.recurring || false, ); + const [autoKeyShareFailed, setAutoKeyShareFailed] = React.useState( isAutoKeyAddFailed(state), ); + const [showConsent, setShowConsent] = React.useState(false); + const autoKeyAddConsent = React.useRef( + defaultValues.autoKeyAddConsent || false, + ); const resetState = React.useCallback(async () => { await clearConnectState(); @@ -156,12 +162,8 @@ export const ConnectWalletForm = ({ [saveValue, currencySymbol, t], ); - const handleSubmit = async (ev: React.FormEvent) => { - ev.preventDefault(); - if (!walletAddressInfo) { - setErrors((_) => ({ ..._, walletAddressUrl: 'Not fetched yet?!' })); - return; - } + const handleSubmit = async (ev?: React.FormEvent) => { + ev?.preventDefault(); const errWalletAddressUrl = validateWalletAddressUrl(walletAddressUrl); const errAmount = validateAmount(amount, currencySymbol.symbol); @@ -186,7 +188,8 @@ export const ConnectWalletForm = ({ walletAddressUrl: toWalletAddressUrl(walletAddressUrl), amount, recurring, - skipAutoKeyShare, + autoKeyAdd: !skipAutoKeyShare, + autoKeyAddConsent: autoKeyAddConsent.current, }); if (res.success) { onConnect(); @@ -194,6 +197,10 @@ export const ConnectWalletForm = ({ if (isErrorWithKey(res.error)) { const error = res.error; if (error.key.startsWith('connectWalletKeyService_error_')) { + if (error.key === 'connectWalletKeyService_error_noConsent') { + setShowConsent(true); + return; + } setErrors((_) => ({ ..._, keyPair: t(error) })); } else { setErrors((_) => ({ ..._, connect: t(error) })); @@ -223,6 +230,26 @@ export const ConnectWalletForm = ({ } }, [defaultValues.walletAddressUrl, handleWalletAddressUrlChange]); + if (showConsent) { + return ( + { + autoKeyAddConsent.current = true; + // saveValue('autoKeyAddConsent', true); + setShowConsent(false); + handleSubmit(); + }} + onDecline={() => { + setErrors((_) => ({ + ..._, + keyPair: t('connectWalletKeyService_error_noConsent'), + })); + setShowConsent(false); + }} + /> + ); + } + return (
{t('connectWallet_action_connect')} + +
+ ); +}; - {!errors.keyPair && !autoKeyShareFailed && ( -