-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional payment error cleanup & documentation
- Loading branch information
Showing
3 changed files
with
54 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
<!-- | ||
@component | ||
Displays relevant user-facing error message based on the type of payment error encountered.render | ||
@example | ||
```svelte | ||
<PaymentError | ||
error={paymentError} | ||
symbol={denominationToken.symbol} | ||
transactionCopy="See tx info above" | ||
> | ||
``` | ||
--> | ||
<script lang="ts"> | ||
import type { ErrorInfo, TokenInfo, GetTokenBalanceReturnType } from '$lib/eth-defi/helpers'; | ||
import { type ErrorInfo, errorCausedBy } from '$lib/eth-defi/helpers'; | ||
export let error: ErrorInfo | any; | ||
export let denominationToken: TokenInfo | GetTokenBalanceReturnType; | ||
export let viewTransactionCopy: string; | ||
export let symbol: string; | ||
export let transactionCopy: string; | ||
const causedBy = errorCausedBy.bind(null, error); | ||
// TODO: move this (and generic `walk` function) to an `error` helper | ||
// walk the error's causes and return true if any match the provided error name | ||
function causedBy(name: string, err: any = error) { | ||
if (err?.name === name) return true; | ||
if (err?.cause) return causedBy(name, err.cause); | ||
return false; | ||
} | ||
const state = error.state ?? 'unknown'; | ||
const authorizingOrApproving = ['authorizing', 'approving'].includes(state); | ||
const processing = state.startsWith('processing'); | ||
const confirming = state === 'confirming'; | ||
</script> | ||
|
||
{#if error.state === 'authorizing'} | ||
{#if causedBy('NavigationLostStateError')} | ||
Wallet request state lost due to window navigation; please cancel the request in your wallet and try again. | ||
{:else if authorizingOrApproving} | ||
{#if causedBy('UserRejectedRequestError')} | ||
Authorization to transfer {denominationToken.symbol} tokens from your wallet was refused. To proceed with share purchase, | ||
please try again and accept the signature request. | ||
Authorization to transfer {symbol} tokens from your wallet was refused by user. To proceed with share purchase, please | ||
try again and approve the request. | ||
{:else if error.name === 'UnknownRpcError' && error.details.includes('eth_signTypedData_v4')} | ||
Authorization failed because your wallet does not support typed data signatures. Consider using TrustWallet, Rainbow | ||
or a browser extension wallet like MetaMask. | ||
{:else if causedBy('NavigationLostStateError')} | ||
Authorization request lost due to window navigation; please cancel wallet request and try again. | ||
{:else} | ||
Authorization to transfer {denominationToken.symbol} tokens from your wallet failed. | ||
{error.shortMessage ?? error.details ?? 'Failure reason unknown.'} | ||
{/if} | ||
{/if} | ||
|
||
{#if error.state === 'approving'} | ||
{#if causedBy('UserRejectedRequestError')} | ||
Approval for {denominationToken.symbol} spending cap was refused. To proceed with share purchase, please try again and | ||
approve the request. | ||
{:else if causedBy('NavigationLostStateError')} | ||
Approval request lost due to window navigation; please cancel wallet request and try again. | ||
{:else} | ||
Approval for {denominationToken.symbol} spending cap failed. | ||
Authorization to transfer {symbol} tokens from your wallet failed. | ||
{error.shortMessage ?? error.details ?? 'Failure reason unknown.'} | ||
{/if} | ||
{/if} | ||
|
||
{#if error.state === 'confirming'} | ||
{:else if confirming} | ||
{#if causedBy('GetSharePriceError')} | ||
Error fetching share price; unable to calculate minSharesQuantity. Aborting payment contract request. | ||
{:else if causedBy('NavigationLostStateError')} | ||
Payment request lost due to window navigation; please cancel wallet request and try again. | ||
{:else if causedBy('UserRejectedRequestError')} | ||
Request to buy shares using your wallet was refused by user. To proceed with share purchase, please try again and | ||
approve the request. | ||
{:else} | ||
Payment confirmation from wallet account failed. | ||
{error.shortMessage ?? error.details ?? 'Failure reason unknown.'} | ||
{/if} | ||
{/if} | ||
|
||
{#if error.state.startsWith('processing')} | ||
{:else if processing} | ||
{error.shortMessage ?? error.details ?? 'Unable to verify transaction status.'} | ||
{viewTransactionCopy} | ||
{transactionCopy} | ||
{:else} | ||
An unexpected error occurred during "{state}" step. | ||
{error.name}: {error.shortMessage ?? error.details ?? 'Failure reason unknown.'} | ||
{/if} |