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

feat: use new UX flow for connecting wallet #619

Merged
merged 51 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1c62f83
feat: use new UX flow for connecting wallet
sidvishnoi Sep 20, 2024
0abbe8e
validation improvements
sidvishnoi Sep 20, 2024
b84f142
reset walletAddressInfo on walletAddressUrl change
sidvishnoi Sep 20, 2024
2f89f23
make Amount field readOnly so it's focusable with tab
sidvishnoi Sep 20, 2024
4c1575b
correctly reset walletAddressInfo to null on change
sidvishnoi Sep 20, 2024
b4229b3
wip: try basic implementation for keyShare
sidvishnoi Sep 20, 2024
fdee425
improvements to ConnectWalletForm UI when key share error
sidvishnoi Sep 23, 2024
073fc64
make key-sharing part of connectWallet
sidvishnoi Sep 23, 2024
be29f25
remove keyShare logic from this PR
sidvishnoi Sep 23, 2024
7ed05fa
cleanup, nits
sidvishnoi Sep 23, 2024
fcbcfa4
disable submit button by default as Bibi asked
sidvishnoi Sep 23, 2024
ec8ef27
fix: try adding key only if not already added
sidvishnoi Sep 23, 2024
ae77a5b
cleanup; remove keyShareService from this PR
sidvishnoi Sep 23, 2024
f5658b0
extract `allowOnlyNumericInput`
sidvishnoi Sep 23, 2024
89a4bd1
copy updates
sidvishnoi Sep 23, 2024
09a2f4a
move copy to messages.json
sidvishnoi Sep 23, 2024
5492262
add missing copy in messages.json; add some descriptions; nits
sidvishnoi Sep 23, 2024
4f953d6
nit: call setError only if there's an error
sidvishnoi Sep 23, 2024
f666a00
update copy: labels
sidvishnoi Sep 23, 2024
ca775a2
add errorWithKey helpers
sidvishnoi Sep 23, 2024
50d6e63
Merge branch 'main' into setup-page/new-flow
sidvishnoi Sep 23, 2024
c229081
fix(ConnectWalletForm): make amount & recurring toggle inline
sidvishnoi Sep 23, 2024
07c4833
don't hide header when there's errors now that we've more space
sidvishnoi Sep 23, 2024
5bd3dbe
fix isErrorWithKey exception when string or null is passed
sidvishnoi Sep 23, 2024
025dcb9
sync with error-keys PR
sidvishnoi Sep 24, 2024
24f317e
fix: handle error when url doesn't return JSON response
sidvishnoi Sep 24, 2024
c88fcc0
update E2E tests
sidvishnoi Sep 24, 2024
17d729e
Merge branch 'main' into setup-page/new-flow
sidvishnoi Sep 24, 2024
9a6e922
fix: update _locales and some usage
sidvishnoi Sep 24, 2024
1fdadd2
refactor: move onBlur handlers to separate functions (allow reuse)
sidvishnoi Sep 25, 2024
af2aa7b
default amount to 5.00
sidvishnoi Sep 25, 2024
eb84eeb
fix typo in copy
sidvishnoi Sep 25, 2024
8774b2d
remove AutomaticKeyPair notice
sidvishnoi Sep 25, 2024
e162711
form layout improvements; prevent scroll when errors/key are shown
sidvishnoi Sep 25, 2024
966016c
perf: useCallback in some places
sidvishnoi Sep 25, 2024
80e42b4
disable spell check on wallet url input
sidvishnoi Sep 25, 2024
d84d6ea
use enterkeyhint=go in url input
sidvishnoi Sep 25, 2024
5451a92
Input.tsx: add comment for id use
sidvishnoi Sep 25, 2024
eda07cd
provide better interface when pasting url into input
sidvishnoi Sep 25, 2024
3b15f78
fix stray ' in copy
sidvishnoi Sep 25, 2024
bbefb8f
better error handling with paste, default (stored) values
sidvishnoi Sep 25, 2024
956eef6
Revert "remove AutomaticKeyPair notice"
sidvishnoi Sep 25, 2024
8506441
replace AutomaticKeyPairNote with Footer; update msg
sidvishnoi Sep 25, 2024
8448aeb
nit
sidvishnoi Sep 25, 2024
1b794cb
update copy to reduce mention of "key"
sidvishnoi Sep 25, 2024
0d2011d
Merge branch 'setup-page/new-flow' of github.com:interledger/web-mone…
sidvishnoi Sep 25, 2024
a01c5fd
Merge branch 'main' into setup-page/new-flow
sidvishnoi Sep 25, 2024
6809546
Merge branch 'main' into setup-page/new-flow
sidvishnoi Sep 26, 2024
53f3592
strongly typed PopupTransientState
sidvishnoi Sep 26, 2024
9f08c84
better error handling
sidvishnoi Sep 26, 2024
0d4e508
disable connect button when in progress
sidvishnoi Sep 26, 2024
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
67 changes: 66 additions & 1 deletion src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,73 @@
"outOfFundsAddFunds_action_addRecurring": {
"message": "Add funds"
},
"connectWallet_text_title": {
"message": "Let's get you set up!"
},
"connectWallet_text_desc": {
"message": "Just a few quick steps to connect the extension to your wallet"
},
"connectWallet_label_walletAddress": {
"message": "Enter wallet address/payment pointer"
},
"connectWallet_labelGroup_amount": {
"message": "Enter amount to allocate from wallet"
},
"connectWallet_label_amount": {
"message": "Amount"
},
"connectWallet_label_recurring": {
"message": "Renew monthly"
},
"connectWallet_label_publicKey": {
"message": "Please copy this key and paste it into your wallet manually and then connect."
sidvishnoi marked this conversation as resolved.
Show resolved Hide resolved
},
"connectWallet_text_publicKeyLearnMore": {
"message": "Learn more."
},
"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."
},
"connectWallet_error_urlInvalidUrl": {
"message": "Invalid wallet address URL."
},
"connectWallet_error_urlInvalidNotHttps": {
"message": "Wallet address must be a https:// URL or a payment pointer."
},
"connectWallet_error_amountRequired": {
"message": "Amount is required."
},
"connectWallet_error_amountInvalidNumber": {
"message": "Please provide a valid number as amount."
},
"connectWallet_error_amountMinimum": {
"message": "An amount greater than $AMOUNT$ is required.",
"placeholders": {
"AMOUNT": { "content": "$1", "example": "$2.05" }
}
},
"connectWallet_error_failedAutoKeyAdd": {
"message": "We couldn't automatically share the key-pair with your provider."
sidvishnoi marked this conversation as resolved.
Show resolved Hide resolved
},
"connectWallet_error_failedAutoKeyAddWhy": {
"message": "Why?",
"description": "Clicking this will show reason for why automatic key-adding failed."
},
"connectWallet_error_invalidClient": {
"message": "Failed to connect. Please make sure you have added the public key to the correct wallet address."
"message": "Failed to connect. Please make sure you have added the key to the correct wallet address."
},
"connectWalletKeyService_error_notImplemented": {
"message": "Automatic key addition is not implemented for given wallet provider yet."
},
"allInvalidLinks_state_text": {
"message": "At the moment, you can not pay this website."
Expand Down
40 changes: 32 additions & 8 deletions src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import type { Tabs } from 'webextension-polyfill';
import { getExchangeRates, getRateOfPay, toAmount } from '../utils';
import { exportJWK, generateEd25519KeyPair } from '@/shared/crypto';
import { bytesToHex } from '@noble/hashes/utils';
import { getWalletInformation } from '@/shared/helpers';
import { ErrorWithKey, getWalletInformation } from '@/shared/helpers';
import { AddFundsPayload, ConnectWalletPayload } from '@/shared/messages';
import {
DEFAULT_RATE_OF_PAY,
MAX_RATE_OF_PAY,
MIN_RATE_OF_PAY,
} from '../config';
import { OPEN_PAYMENTS_REDIRECT_URL } from '@/shared/defines';
import type { Cradle } from '../container';
import type { Cradle } from '@/background/container';

interface KeyInformation {
privateKey: string;
Expand Down Expand Up @@ -311,6 +311,7 @@ export class OpenPaymentsService {
walletAddressUrl,
amount,
recurring,
skipAutoKeyShare,
}: ConnectWalletPayload) {
const walletAddress = await getWalletInformation(walletAddressUrl);
const exchangeRates = await getExchangeRates();
Expand Down Expand Up @@ -343,12 +344,31 @@ export class OpenPaymentsService {
});

await this.initClient(walletAddress.id);
await this.completeGrant(
amount,
walletAddress,
recurring,
InteractionIntent.CONNECT,
);

try {
await this.completeGrant(
amount,
walletAddress,
recurring,
InteractionIntent.CONNECT,
);
} catch (error) {
if (
error.message === this.t('connectWallet_error_invalidClient') &&
!skipAutoKeyShare
) {
// add key to wallet and try again
await this.addPublicKeyToWallet(walletAddress);
await this.completeGrant(
amount,
walletAddress,
recurring,
InteractionIntent.CONNECT,
);
} else {
throw error;
}
}

await this.storage.set({
walletAddress,
Expand Down Expand Up @@ -484,6 +504,10 @@ export class OpenPaymentsService {
return grantDetails;
}

private async addPublicKeyToWallet(_walletAddress: WalletAddress) {
throw new ErrorWithKey('connectWalletKeyService_error_notImplemented');
Copy link
Member Author

Choose a reason for hiding this comment

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

This will be implemented in follow-up PRs. This PR changes the UI and handles the fallback case where we fail to add key for some reason.

}

private async redirectToWelcomeScreen(
tabId: NonNullable<Tabs.Tab['id']>,
result: GrantResult,
Expand Down
Loading