|
12 | 12 | import { erc20Tokens } from '$eth/derived/erc20.derived'; |
13 | 13 | import { harvestAutopilots } from '$eth/derived/harvest-autopilots.derived'; |
14 | 14 | import { icpAccountIdentifierText } from '$icp/derived/ic.derived'; |
| 15 | + import { |
| 16 | + OnramperRateLimitedError, |
| 17 | + OnramperSecretNotConfiguredError |
| 18 | + } from '$lib/canisters/errors'; |
15 | 19 | import BuyUnavailableNotice from '$lib/components/buy/BuyUnavailableNotice.svelte'; |
16 | 20 | import { BUY_MODAL_ONRAMPER_IFRAME } from '$lib/constants/test-ids.constants'; |
17 | 21 | import { btcAddressMainnet, ethAddress, solAddressMainnet } from '$lib/derived/address.derived'; |
|
21 | 25 | import { networkBitcoin, networkEthereum, networkSolana } from '$lib/derived/network.derived'; |
22 | 26 | import { networks } from '$lib/derived/networks.derived'; |
23 | 27 | import { enabledTokens } from '$lib/derived/tokens.derived'; |
| 28 | + import { |
| 29 | + PLAUSIBLE_EVENT_ONRAMPER_ERROR_TYPES, |
| 30 | + PLAUSIBLE_EVENT_RESULT_STATUSES |
| 31 | + } from '$lib/enums/plausible'; |
| 32 | + import { trackOnramperOpen } from '$lib/services/analytics.services'; |
24 | 33 | import { i18n } from '$lib/stores/i18n.store'; |
25 | 34 | import { token } from '$lib/stores/token.store'; |
26 | 35 | import { consoleError } from '$lib/utils/console.utils'; |
| 36 | + import { getTokenIdentifier } from '$lib/utils/identifier.utils'; |
27 | 37 | import { buildOnramperLink, mapOnramperNetworkWallets } from '$lib/utils/onramper.utils'; |
28 | 38 |
|
29 | 39 | let vault = $derived( |
|
73 | 83 | let src = $state<string | undefined>(undefined); |
74 | 84 | let signingFailed = $state(false); |
75 | 85 |
|
| 86 | + let tokenPayload = $derived( |
| 87 | + nonNullish($token) |
| 88 | + ? { |
| 89 | + network: $token.network.id.description ?? '', |
| 90 | + symbol: $token.symbol, |
| 91 | + name: $token.name, |
| 92 | + address: getTokenIdentifier($token) |
| 93 | + } |
| 94 | + : undefined |
| 95 | + ); |
| 96 | +
|
| 97 | + const classifyOnramperError = (error: unknown): PLAUSIBLE_EVENT_ONRAMPER_ERROR_TYPES => |
| 98 | + error instanceof OnramperSecretNotConfiguredError |
| 99 | + ? PLAUSIBLE_EVENT_ONRAMPER_ERROR_TYPES.SECRET_NOT_CONFIGURED |
| 100 | + : error instanceof OnramperRateLimitedError |
| 101 | + ? PLAUSIBLE_EVENT_ONRAMPER_ERROR_TYPES.RATE_LIMITED |
| 102 | + : PLAUSIBLE_EVENT_ONRAMPER_ERROR_TYPES.SIGNING_FAILED; |
| 103 | +
|
76 | 104 | // Resolve the signed widget URL through the backend canister whenever the inputs change. Build |
77 | 105 | // the link asynchronously (the canister returns the HMAC over the sensitive parameters) and |
78 | 106 | // guard against late resolutions overwriting newer state via a cancellation token. |
|
104 | 132 | .then((url) => { |
105 | 133 | if (!cancelled) { |
106 | 134 | src = url; |
| 135 | +
|
| 136 | + trackOnramperOpen({ |
| 137 | + token: tokenPayload, |
| 138 | + status: PLAUSIBLE_EVENT_RESULT_STATUSES.SUCCESS |
| 139 | + }); |
107 | 140 | } |
108 | 141 | }) |
109 | 142 | .catch((error: unknown) => { |
110 | 143 | if (!cancelled) { |
111 | 144 | consoleError('Could not sign OnRamper widget URL', error); |
112 | 145 | signingFailed = true; |
| 146 | +
|
| 147 | + trackOnramperOpen({ |
| 148 | + token: tokenPayload, |
| 149 | + status: PLAUSIBLE_EVENT_RESULT_STATUSES.ERROR, |
| 150 | + errorType: classifyOnramperError(error), |
| 151 | + errorMessage: error instanceof Error ? error.message : undefined |
| 152 | + }); |
113 | 153 | } |
114 | 154 | }); |
115 | 155 |
|
|
155 | 195 | <!-- "In order to do customer verification before purchase, we require the following permissions to be given to the app. So this is definitely merely for the KYC and also for fraud detection algorithms i suppose" --> |
156 | 196 |
|
157 | 197 | {#if signingFailed} |
158 | | - <BuyUnavailableNotice /> |
| 198 | + <BuyUnavailableNotice reason="signing-failed" /> |
159 | 199 | {:else} |
160 | 200 | <div |
161 | 201 | class="absolute top-0 right-0 bottom-0 left-0 bg-surface text-brand-primary transition-all duration-500 ease-in-out" |
|
0 commit comments