|
20 | 20 | } from "../utils/request"; |
21 | 21 | import Spinner from "./spinner.svelte"; |
22 | 22 | import WalletInfo from "./wallet-info.svelte"; |
| 23 | + import { ethers } from "ethers"; |
23 | 24 |
|
24 | 25 | export let selectedCurrency: Currency; |
25 | 26 | export let amountInUSD: number; |
|
36 | 37 | export let onPaymentSuccess: (request: any) => void; |
37 | 38 | export let onPaymentError: (error: string) => void; |
38 | 39 | export let invoiceNumber: string | undefined; |
| 40 | + export let feeAddress: string; |
| 41 | + export let feeAmountInUSD: number; |
39 | 42 |
|
40 | 43 | const COUNTDOWN_INTERVAL = 30; |
41 | 44 |
|
|
44 | 47 | let intervalId: NodeJS.Timeout; |
45 | 48 | let exchangeRate: number = 0; |
46 | 49 | let error: string = ""; |
| 50 | + let feeAmountInCrypto: number = 0; |
47 | 51 |
|
48 | 52 | $: isLoadingPrice = true; |
49 | 53 | $: isPaying = false; |
| 54 | + $: totalPayment = amountInCrypto + feeAmountInCrypto; |
50 | 55 |
|
51 | 56 | const currencySymbol = selectedCurrency.symbol.includes( |
52 | 57 | selectedCurrency.network |
|
72 | 77 | const rate = data.data.rates[lookupSymbol]; |
73 | 78 | exchangeRate = parseFloat(rate); |
74 | 79 | amountInCrypto = amountInUSD * exchangeRate; |
| 80 | + feeAmountInCrypto = feeAmountInUSD * exchangeRate; |
75 | 81 | } catch (error) { |
76 | 82 | alert("Unable to fetch exchange rate. Please try again later"); |
77 | 83 | } finally { |
|
145 | 151 | > |
146 | 152 | </div> |
147 | 153 | </div> |
148 | | - <div class="payment-confirmation-tab payment-confirmation-seller-address"> |
| 154 | + <div class="payment-confirmation-tab payment-confirmation-address"> |
149 | 155 | <h4>Payment to</h4> |
150 | | - <a |
151 | | - href={getExplorerUrl(selectedCurrency.network, sellerAddress)} |
152 | | - target="_blank" |
153 | | - > |
154 | | - <span>{sellerAddress}</span> |
155 | | - </a> |
156 | | - <button |
157 | | - on:click={() => { |
158 | | - navigator.clipboard.writeText(sellerAddress); |
159 | | - }} |
160 | | - > |
161 | | - <CopyIcon /> |
162 | | - </button> |
| 156 | + <div class="address-container"> |
| 157 | + <a |
| 158 | + href={getExplorerUrl(selectedCurrency.network, sellerAddress)} |
| 159 | + target="_blank" |
| 160 | + > |
| 161 | + <span>{sellerAddress}</span> |
| 162 | + </a> |
| 163 | + <button |
| 164 | + on:click={() => { |
| 165 | + navigator.clipboard.writeText(sellerAddress); |
| 166 | + }} |
| 167 | + > |
| 168 | + <CopyIcon /> |
| 169 | + </button> |
| 170 | + </div> |
163 | 171 | </div> |
| 172 | + {#if feeAddress !== ethers.constants.AddressZero && feeAmountInUSD > 0} |
| 173 | + <div class="payment-confirmation-tab payment-confirmation-address"> |
| 174 | + <h4>Fee to</h4> |
| 175 | + <div class="address-container"> |
| 176 | + <a |
| 177 | + href={getExplorerUrl(selectedCurrency.network, feeAddress)} |
| 178 | + target="_blank" |
| 179 | + > |
| 180 | + <span>{feeAddress}</span> |
| 181 | + </a> |
| 182 | + <button |
| 183 | + on:click={() => { |
| 184 | + navigator.clipboard.writeText(feeAddress); |
| 185 | + }} |
| 186 | + > |
| 187 | + <CopyIcon /> |
| 188 | + </button> |
| 189 | + </div> |
| 190 | + </div> |
| 191 | + <div class="payment-confirmation-tab"> |
| 192 | + <h4>Fee Amount</h4> |
| 193 | + <span> |
| 194 | + ${feeAmountInUSD} USD / {trimTrailingDecimalZeros(feeAmountInCrypto)} |
| 195 | + {currencySymbol} |
| 196 | + </span> |
| 197 | + </div> |
| 198 | + {/if} |
164 | 199 | <div class="payment-confirmation-tab"> |
165 | 200 | <h4>Payment network</h4> |
166 | 201 | <span>{NETWORK_LABEL[selectedCurrency.network]}</span> |
167 | 202 | </div> |
168 | 203 | <div class="payment-confirmation-tab"> |
169 | 204 | <h4>Total</h4> |
170 | | - <span>{trimTrailingDecimalZeros(amountInCrypto)} {currencySymbol}</span> |
| 205 | + <span>{trimTrailingDecimalZeros(totalPayment)} {currencySymbol}</span> |
171 | 206 | </div> |
172 | 207 |
|
173 | 208 | {#if !isPaying} |
|
216 | 251 | try { |
217 | 252 | const requestParameters = prepareRequestParameters({ |
218 | 253 | currency: selectedCurrency, |
| 254 | + feeAddress, |
| 255 | + feeAmountInUSD, |
| 256 | + feeAmountInCrypto, |
219 | 257 | productInfo, |
220 | 258 | sellerInfo, |
221 | 259 | buyerInfo, |
222 | 260 | payerAddress, |
223 | 261 | amountInCrypto, |
| 262 | + totalAmountInCrypto: totalPayment, |
224 | 263 | exchangeRate, |
225 | 264 | amountInUSD, |
226 | 265 | builderId, |
|
286 | 325 | width: 100%; |
287 | 326 | gap: 16px; |
288 | 327 |
|
289 | | - .payment-confirmation-seller-address { |
290 | | - display: flex; |
291 | | - align-items: center; |
292 | | - gap: 2px; |
293 | | - font-size: 12px; |
294 | | -
|
295 | | - button { |
296 | | - background: none; |
297 | | - border: none; |
298 | | - padding: 0; |
299 | | - margin: 0; |
300 | | - cursor: pointer; |
301 | | - display: inline-flex; |
302 | | - align-items: center; |
303 | | - justify-content: center; |
304 | | - } |
305 | | - } |
306 | 328 | &-amount-info { |
307 | 329 | display: flex; |
308 | 330 | align-items: center; |
|
351 | 373 | font-weight: 500; |
352 | 374 | font-size: 14px; |
353 | 375 | } |
| 376 | +
|
| 377 | + &.payment-confirmation-address { |
| 378 | + flex-direction: column; |
| 379 | + align-items: flex-start; |
| 380 | + gap: 8px; |
| 381 | +
|
| 382 | + h4 { |
| 383 | + margin: 0; |
| 384 | + } |
| 385 | +
|
| 386 | + .address-container { |
| 387 | + display: flex; |
| 388 | + align-items: center; |
| 389 | + gap: 8px; |
| 390 | + width: 100%; |
| 391 | +
|
| 392 | + a { |
| 393 | + flex-grow: 1; |
| 394 | + text-decoration: none; |
| 395 | + color: inherit; |
| 396 | + font-size: 14px; |
| 397 | +
|
| 398 | + span { |
| 399 | + display: inline-block; |
| 400 | + width: 100%; |
| 401 | + overflow: hidden; |
| 402 | + text-overflow: ellipsis; |
| 403 | + white-space: nowrap; |
| 404 | + } |
| 405 | + } |
| 406 | +
|
| 407 | + button { |
| 408 | + background: none; |
| 409 | + border: none; |
| 410 | + padding: 0; |
| 411 | + margin: 0; |
| 412 | + cursor: pointer; |
| 413 | + display: flex; |
| 414 | + align-items: center; |
| 415 | + justify-content: center; |
| 416 | + } |
| 417 | + } |
| 418 | + } |
354 | 419 | } |
355 | 420 |
|
356 | 421 | &-warning { |
|
0 commit comments