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

Improve investor wizard error messaging #592

Merged
merged 3 commits into from
Sep 21, 2023
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
15 changes: 10 additions & 5 deletions src/lib/wallet/ConnectWallet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { fade } from 'svelte/transition';
import type { ApiChain } from '$lib/helpers/chain.js';
import { AlertList, Button } from '$lib/components';
import { wallet, WalletSummary, WalletTile } from '$lib/wallet';
import { type ConnectorType, wallet, WalletSummary, WalletTile } from '$lib/wallet';

export let chainId: MaybeNumber;
export let chainInfo: Record<string, ApiChain>;
Expand All @@ -13,9 +13,9 @@
error = undefined;
}

function handleConnectMetaMask() {
function connectWallet(type: ConnectorType) {
error = undefined;
wallet.connectMetaMask(chainId).catch((e) => (error = e));
wallet.connect(type, chainId).catch((e) => (error = e));
}
</script>

Expand All @@ -27,11 +27,11 @@
</div>
{:else}
<div class="wallet-options">
<WalletTile name="Browser Wallet" slug="browser-wallet" on:click={handleConnectMetaMask}>
<WalletTile name="Browser Wallet" slug="browser-wallet" on:click={() => connectWallet('Injected')}>
Connect to your<br />
browser-based wallet
</WalletTile>
<WalletTile name="WalletConnect" slug="walletconnect" on:click={() => wallet.connectWalletConnect(chainId)}>
<WalletTile name="WalletConnect" slug="walletconnect" on:click={() => connectWallet('WalletConnect')}>
Scan a QR code<br />
with your mobile wallet
</WalletTile>
Expand All @@ -57,6 +57,11 @@
signing in or importing an account). Open your wallet extension to complete or cancel this operation and try
again.
</AlertItem>
{:else if error.name === 'ChainNotConfiguredForConnectorError'}
<AlertItem title="Chain not configured">
Chain {chainId} ({chainInfo[chainId].chain_name}) is not configured on your wallet. Please add the missing
chain (or <em>network</em>) and try again.
</AlertItem>
{:else}
<AlertItem title={error.name}>
{error.message}
Expand Down
17 changes: 6 additions & 11 deletions src/lib/wallet/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function getRpcUrl({ id }: Chain) {
return http && { http };
}

export type ConnectorType = 'Injected' | 'WalletConnect';

type CommonWallet = {
name: string;
address: Address;
Expand Down Expand Up @@ -86,18 +88,11 @@ function initWalletClient(connectors: Connector[]) {
initialized = true;
}

async function connectMetaMask(chainId: MaybeNumber) {
await connect({
chainId,
connector: connectors.find((c) => c instanceof InjectedConnector)!
});
}

function connectWalletConnect(chainId: MaybeNumber) {
connect({
function connectWallet(type: ConnectorType, chainId: MaybeNumber) {
return connect({
chainId,
connector: connectors.find((c) => c instanceof WalletConnectConnector)!
connector: connectors.find((c) => c.constructor.name === `${type}Connector`)!
});
}

export const wallet = { subscribe, connectMetaMask, connectWalletConnect, disconnect };
export const wallet = { subscribe, connect: connectWallet, disconnect };
9 changes: 4 additions & 5 deletions src/routes/wizard/deposit/payment/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@
To proceed with share purchase, please try again and accept the signature request.
`;
} else {
errorMessage = `
Authorization to transfer ${denominationToken.symbol} tokens from your wallet account
failed for an unknown reason.
`;
errorMessage = `Authorization to transfer ${denominationToken.symbol} tokens from your wallet failed. `;
errorMessage += err.shortMessage ?? 'Failure reason unknown.';
}
return 'failed';
}
Expand All @@ -108,7 +106,8 @@

fail(err) {
console.error('confirmPayment error:', err);
errorMessage = 'Payment confirmation from wallet account failed.';
errorMessage = 'Payment confirmation from wallet account failed. ';
errorMessage += err.shortMessage ?? 'Failure reason unknown.';
return 'failed';
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/routes/wizard/redeem/shares-redemption/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

fail(err) {
console.error('confirmRedemption error:', err);
errorMessage = 'Redemption confirmation from wallet account failed.';
errorMessage = err.shortMessage ?? 'Redemption confirmation from wallet account failed.';
return 'failed';
}
},
Expand Down