|  | 
| 1 | 1 | <script lang="ts"> | 
| 2 | 2 |   // Components | 
| 3 | 3 |   import Button from "@requestnetwork/shared-components/button.svelte"; | 
| 4 |  | -  import Dropdown from "@requestnetwork/shared-components/dropdown.svelte"; | 
| 5 | 4 |   import Input from "@requestnetwork/shared-components/input.svelte"; | 
| 6 | 5 |   import Labels from "@requestnetwork/shared-components/labels.svelte"; | 
| 7 | 6 |   import Accordion from "@requestnetwork/shared-components/accordion.svelte"; | 
|  | 
| 19 | 18 |   import { calculateItemTotal } from "@requestnetwork/shared-utils/invoiceTotals"; | 
| 20 | 19 |   import { checkAddress } from "@requestnetwork/shared-utils/checkEthAddress"; | 
| 21 | 20 |   import { inputDateFormat } from "@requestnetwork/shared-utils/formatDate"; | 
| 22 |  | -  import { Types } from "@requestnetwork/request-client.js"; | 
| 23 | 21 |   import { CurrencyTypes, CipherProviderTypes } from "@requestnetwork/types"; | 
| 24 | 22 |   import isEmail from "validator/es/lib/isEmail"; | 
| 25 | 23 | 
 | 
|  | 
| 31 | 29 |   export let handleNetworkChange: (chainId: string) => void; | 
| 32 | 30 |   export let networks; | 
| 33 | 31 |   export let defaultCurrencies: any = []; | 
| 34 |  | -  export let currencyManager: any; | 
| 35 |  | -  export let invoiceCurrency: CurrencyTypes.CurrencyDefinition | undefined; | 
| 36 |  | -  export let currency: | 
| 37 |  | -    | CurrencyTypes.ERC20Currency | 
| 38 |  | -    | CurrencyTypes.NativeCurrency | 
| 39 |  | -    | undefined; | 
| 40 |  | -  export let network: any; | 
|  | 32 | +  export let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] = []; | 
| 41 | 33 |   export let cipherProvider: CipherProviderTypes.ICipherProvider | undefined; | 
| 42 | 34 | 
 | 
|  | 35 | +  export let invoiceCurrencyDropdown; | 
|  | 36 | +  export let networkDropdown; | 
|  | 37 | +  export let currencyDropdown; | 
|  | 38 | +
 | 
| 43 | 39 |   let validationErrors = { | 
| 44 | 40 |     payeeAddress: false, | 
| 45 | 41 |     clientAddress: false, | 
|  | 
| 53 | 49 |   }; | 
| 54 | 50 | 
 | 
| 55 | 51 |   let showPayeeAddressInput = false; | 
| 56 |  | -  let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] = []; | 
| 57 | 52 | 
 | 
| 58 | 53 |   const validateEmail = (email: string, type: "sellerInfo" | "buyerInfo") => { | 
| 59 | 54 |     validationErrors[`${type}`].email = !isEmail(email); | 
|  | 
| 160 | 155 |     formData.payeeAddress = formData.creatorId; | 
| 161 | 156 |   } | 
| 162 | 157 | 
 | 
| 163 |  | -  $: { | 
| 164 |  | -    // Filter settlement currencies whenever network, invoiceCurrency, or currencyManager changes | 
| 165 |  | -    filteredSettlementCurrencies = defaultCurrencies.filter((currency) => { | 
| 166 |  | -      if (!invoiceCurrency) { | 
| 167 |  | -        return false; | 
| 168 |  | -      } | 
| 169 |  | -
 | 
| 170 |  | -      // For ISO4217 currencies (like EUR) | 
| 171 |  | -      if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) { | 
| 172 |  | -        const hasValidPath = | 
| 173 |  | -          currencyManager?.getConversionPath( | 
| 174 |  | -            invoiceCurrency, | 
| 175 |  | -            currency, | 
| 176 |  | -            currency.network | 
| 177 |  | -          )?.length > 0; | 
| 178 |  | -
 | 
| 179 |  | -        return ( | 
| 180 |  | -          currency.type !== Types.RequestLogic.CURRENCY.ISO4217 && hasValidPath | 
| 181 |  | -        ); | 
| 182 |  | -      } | 
| 183 |  | -
 | 
| 184 |  | -      // For other currency types (like ERC20) | 
| 185 |  | -      return invoiceCurrency.hash === currency.hash; | 
| 186 |  | -    }); | 
| 187 |  | -  } | 
| 188 |  | -
 | 
| 189 | 158 |   $: if (!formData.issuedOn) { | 
| 190 | 159 |     formData.issuedOn = inputDateFormat(new Date()); | 
| 191 | 160 |   } | 
|  | 
| 433 | 402 |             </div> | 
| 434 | 403 |           </Accordion> | 
| 435 | 404 |         </div> | 
| 436 |  | - | 
| 437 | 405 |         <div class="searchable-dropdown-container"> | 
| 438 | 406 |           <SearchableDropdown | 
|  | 407 | +            bind:this={invoiceCurrencyDropdown} | 
| 439 | 408 |             getValue={(currency) => currency.value.symbol} | 
| 440 | 409 |             getDisplayValue={(currency) => | 
| 441 | 410 |               `${currency.value.symbol} ${currency.value.network ? `(${currency.value.network})` : ""}`} | 
| 442 | 411 |             placeholder="Invoice currency" | 
| 443 | 412 |             items={defaultCurrencies | 
| 444 |  | -              ?.filter((curr) => { | 
| 445 |  | -                if (!curr) return false; | 
| 446 |  | -                return ( | 
| 447 |  | -                  curr.type === Types.RequestLogic.CURRENCY.ISO4217 || | 
| 448 |  | -                  (curr.network && curr.network === network) | 
| 449 |  | -                ); | 
| 450 |  | -              }) | 
|  | 413 | +              ?.filter((curr) => curr) | 
| 451 | 414 |               .map((currency) => ({ | 
| 452 | 415 |                 value: currency, | 
| 453 | 416 |                 label: `${currency?.symbol ?? "Unknown"} ${currency?.network ? `(${currency.network})` : ""}`, | 
| 454 | 417 |                 type: "invoiceCurrency", | 
| 455 | 418 |               })) ?? []} | 
| 456 | 419 |             onSelect={handleInvoiceCurrencyChange} | 
| 457 | 420 |           /> | 
|  | 421 | +        </div> | 
|  | 422 | +        <div class="searchable-dropdown-container">  | 
| 458 | 423 |           <SearchableDropdown | 
|  | 424 | +            bind:this={networkDropdown} | 
| 459 | 425 |             items={networks | 
| 460 | 426 |               .filter((networkItem) => networkItem) | 
| 461 | 427 |               .map((networkItem) => { | 
|  | 
| 471 | 437 |             onSelect={handleNetworkChange} | 
| 472 | 438 |           /> | 
| 473 | 439 |           <SearchableDropdown | 
|  | 440 | +            bind:this={currencyDropdown} | 
| 474 | 441 |             items={filteredSettlementCurrencies.map((currency) => ({ | 
| 475 | 442 |               value: currency, | 
| 476 | 443 |               type: "settlementCurrency", | 
|  | 
| 481 | 448 |               `${currency.value.symbol} (${currency.value.network})`} | 
| 482 | 449 |             onSelect={handleCurrencyChange} | 
| 483 | 450 |           /> | 
|  | 451 | +        </div> | 
|  | 452 | +        <div> | 
| 484 | 453 |           {#if cipherProvider} | 
| 485 | 454 |             <Input | 
| 486 | 455 |               type="checkbox" | 
|  | 
0 commit comments