|
27 | 27 | export let formData: CustomFormData; |
28 | 28 | export let handleInvoiceCurrencyChange: (value: string) => void; |
29 | 29 | export let handleCurrencyChange: (value: string) => void; |
30 | | -
|
31 | 30 | export let handleNetworkChange: (chainId: string) => void; |
32 | 31 | export let networks; |
33 | 32 | export let defaultCurrencies: any = []; |
|
117 | 116 | } |
118 | 117 | }; |
119 | 118 |
|
120 | | - const filterSettlementCurrencies = ( |
121 | | - currency: CurrencyTypes.CurrencyDefinition |
122 | | - ) => { |
123 | | - return invoiceCurrency |
124 | | - ? invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217 |
125 | | - ? currency.type !== Types.RequestLogic.CURRENCY.ISO4217 && |
126 | | - currencyManager?.getConversionPath( |
127 | | - invoiceCurrency, |
128 | | - currency, |
129 | | - currency.network |
130 | | - )?.length > 0 |
131 | | - : invoiceCurrency.hash === currency.hash |
132 | | - : false; |
133 | | - }; |
134 | | -
|
135 | 119 | const addInvoiceItem = () => { |
136 | 120 | const newItem = { |
137 | 121 | name: "", |
|
418 | 402 | ? `${invoiceCurrency.symbol} ${invoiceCurrency?.network ? `(${invoiceCurrency?.network})` : ""}` |
419 | 403 | : undefined} |
420 | 404 | placeholder="Invoice currency (labeling)" |
421 | | - options={defaultCurrencies.map((currency) => ({ |
422 | | - value: currency, |
423 | | - label: `${currency.symbol} ${currency?.network ? `(${currency?.network})` : ""}`, |
424 | | - }))} |
| 405 | + options={defaultCurrencies |
| 406 | + ?.filter((curr) => { |
| 407 | + if (!curr) return false; |
| 408 | + |
| 409 | + return ( |
| 410 | + curr.type === Types.RequestLogic.CURRENCY.ISO4217 || |
| 411 | + (curr.network && curr.network === network) |
| 412 | + ); |
| 413 | + }) |
| 414 | + .map((currency) => ({ |
| 415 | + value: currency, |
| 416 | + label: `${currency?.symbol ?? "Unknown"} ${currency?.network ? `(${currency.network})` : ""}`, |
| 417 | + })) ?? []} |
425 | 418 | onchange={handleInvoiceCurrencyChange} |
426 | 419 | /> |
427 | 420 | <Dropdown |
|
431 | 424 | ? `${currency.symbol ?? "Unknown"} (${currency?.network ?? "Unknown"})` |
432 | 425 | : undefined} |
433 | 426 | options={defaultCurrencies |
434 | | - .filter((currency) => filterSettlementCurrencies(currency)) |
| 427 | + ?.filter((curr) => { |
| 428 | + if (!curr || !invoiceCurrency) return false; |
| 429 | + |
| 430 | + if ( |
| 431 | + invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217 |
| 432 | + ) { |
| 433 | + return ( |
| 434 | + (curr.type === Types.RequestLogic.CURRENCY.ERC20 || |
| 435 | + curr.type === Types.RequestLogic.CURRENCY.ISO4217) && |
| 436 | + curr.network === network |
| 437 | + ); |
| 438 | + } else if ( |
| 439 | + invoiceCurrency.type === Types.RequestLogic.CURRENCY.ERC20 |
| 440 | + ) { |
| 441 | + return ( |
| 442 | + curr.type === Types.RequestLogic.CURRENCY.ERC20 && |
| 443 | + curr.network === invoiceCurrency.network |
| 444 | + ); |
| 445 | + } else { |
| 446 | + return ( |
| 447 | + curr.type === Types.RequestLogic.CURRENCY.ERC20 && |
| 448 | + curr.network === invoiceCurrency.network |
| 449 | + ); |
| 450 | + } |
| 451 | + }) |
435 | 452 | .map((currency) => ({ |
436 | 453 | value: currency, |
437 | | - label: `${currency.symbol ?? "Unknown"} (${currency?.network ?? "Unknown"})`, |
438 | | - }))} |
| 454 | + label: `${currency?.symbol ?? "Unknown"} ${currency?.network ? `(${currency.network})` : ""}`, |
| 455 | + })) ?? []} |
439 | 456 | onchange={handleCurrencyChange} |
440 | 457 | /> |
441 | 458 | </div> |
|
0 commit comments