|  | 
| 1 | 1 | <svelte:options customElement="create-invoice-form" /> | 
| 2 | 2 | 
 | 
| 3 | 3 | <script lang="ts"> | 
| 4 |  | -  import { getAccount, watchAccount, WatchAccountReturnType } from "@wagmi/core"; | 
|  | 4 | +  import { | 
|  | 5 | +    getAccount, | 
|  | 6 | +    watchAccount, | 
|  | 7 | +    WatchAccountReturnType, | 
|  | 8 | +  } from "@wagmi/core"; | 
| 5 | 9 |   import { Config as WagmiConfig } from "wagmi"; | 
| 6 | 10 |   // Types | 
| 7 | 11 |   import { type GetAccountReturnType } from "@wagmi/core"; | 
|  | 
| 24 | 28 |   import Status from "@requestnetwork/shared-components/status.svelte"; | 
| 25 | 29 |   import Modal from "@requestnetwork/shared-components/modal.svelte"; | 
| 26 | 30 |   import { EncryptionTypes, CipherProviderTypes } from "@requestnetwork/types"; | 
| 27 |  | -    import { onDestroy, onMount, tick } from "svelte"; | 
|  | 31 | +  import { onDestroy, onMount, tick } from "svelte"; | 
| 28 | 32 | 
 | 
| 29 | 33 |   interface CipherProvider extends CipherProviderTypes.ICipherProvider { | 
| 30 | 34 |     disconnectWallet: () => void; | 
|  | 
| 36 | 40 |   export let currencies: CurrencyTypes.CurrencyInput[] = []; | 
| 37 | 41 |   let cipherProvider: CipherProvider | undefined; | 
| 38 | 42 | 
 | 
| 39 |  | -  let account: GetAccountReturnType | undefined = wagmiConfig && getAccount(wagmiConfig); | 
|  | 43 | +  let account: GetAccountReturnType | undefined = | 
|  | 44 | +    wagmiConfig && getAccount(wagmiConfig); | 
| 40 | 45 |   let isTimeout = false; | 
| 41 | 46 |   let activeConfig = config ? config : defaultConfig; | 
| 42 | 47 |   let mainColor = activeConfig.colors.main; | 
| 43 | 48 |   let secondaryColor = activeConfig.colors.secondary; | 
| 44 | 49 |   let currencyManager = initializeCurrencyManager(currencies); | 
| 45 | 50 | 
 | 
| 46 |  | -  let invoiceCurrencyDropdown: { clear: () => void; }; | 
| 47 |  | -  let networkDropdown: { clear: () => void; }; | 
| 48 |  | -  let currencyDropdown: { clear: () => void; }; | 
| 49 |  | -
 | 
| 50 |  | -  const extractUniqueNetworkNames = (): string[] => { | 
| 51 |  | -    const networkSet = new Set<string>(); | 
| 52 |  | -
 | 
| 53 |  | -    currencyManager.knownCurrencies.forEach( | 
| 54 |  | -      (currency: CurrencyTypes.CurrencyDefinition) => { | 
| 55 |  | -        if (currency.network) { | 
| 56 |  | -          networkSet.add(currency.network); | 
| 57 |  | -        } | 
| 58 |  | -      } | 
| 59 |  | -    ); | 
| 60 |  | -
 | 
| 61 |  | -    return Array.from(networkSet); | 
| 62 |  | -  }; | 
| 63 |  | -
 | 
| 64 |  | -  let networks: string[] = extractUniqueNetworkNames(); | 
|  | 51 | +  let invoiceCurrencyDropdown: { clear: () => void }; | 
|  | 52 | +  let networkDropdown: { clear: () => void }; | 
|  | 53 | +  let currencyDropdown: { clear: () => void }; | 
|  | 54 | +  let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] = []; | 
|  | 55 | +  let networks: string[] = []; | 
| 65 | 56 | 
 | 
| 66 | 57 |   let network: string | undefined = undefined; | 
| 67 | 58 |   let currency: CurrencyTypes.CurrencyDefinition | undefined = undefined; | 
|  | 
| 70 | 61 |   const handleNetworkChange = (newNetwork: string) => { | 
| 71 | 62 |     if (newNetwork) { | 
| 72 | 63 |       currencyDropdown.clear(); | 
|  | 64 | +      invoiceCurrency = invoiceCurrency?.type !== Types.RequestLogic.CURRENCY.ISO4217 ? currencyManager.knownCurrencies.find(currency => invoiceCurrency?.symbol === currency.symbol && currency.network === newNetwork) : invoiceCurrency; | 
| 73 | 65 |       network = newNetwork; | 
| 74 |  | -
 | 
| 75 | 66 |       currency = undefined; | 
| 76 | 67 | 
 | 
| 77 |  | -      filteredSettlementCurrencies = currencyManager.knownCurrencies.filter((currency: CurrencyTypes.CurrencyDefinition) => { | 
| 78 |  | -      if (!invoiceCurrency) { | 
| 79 |  | -        return false; | 
| 80 |  | -      } | 
| 81 |  | -
 | 
| 82 |  | -      // For ISO4217 currencies (like EUR) | 
| 83 |  | -      if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) { | 
| 84 |  | -        const hasValidPath = | 
| 85 |  | -          currencyManager?.getConversionPath( | 
| 86 |  | -            invoiceCurrency, | 
| 87 |  | -            currency, | 
| 88 |  | -            currency?.network | 
| 89 |  | -          )?.length > 0; | 
| 90 |  | -
 | 
| 91 |  | -        return ( | 
| 92 |  | -          currency.type !== Types.RequestLogic.CURRENCY.ISO4217 && hasValidPath | 
| 93 |  | -        ); | 
| 94 |  | -      } | 
| 95 |  | -
 | 
| 96 |  | -      // For other currency types (like ERC20) | 
| 97 |  | -      return invoiceCurrency.hash === currency?.hash; | 
| 98 |  | -    });; | 
|  | 68 | +      filteredSettlementCurrencies = currencyManager.knownCurrencies.filter( | 
|  | 69 | +        (currency: CurrencyTypes.CurrencyDefinition) => { | 
|  | 70 | +          if (!invoiceCurrency) { | 
|  | 71 | +            return false; | 
|  | 72 | +          } | 
|  | 73 | +
 | 
|  | 74 | +          // For ISO4217 currencies (like EUR) | 
|  | 75 | +          if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) { | 
|  | 76 | +            const hasValidPath = | 
|  | 77 | +              currencyManager?.getConversionPath( | 
|  | 78 | +                invoiceCurrency, | 
|  | 79 | +                currency, | 
|  | 80 | +                currency?.network, | 
|  | 81 | +              )?.length > 0; | 
|  | 82 | +
 | 
|  | 83 | +            return ( | 
|  | 84 | +              currency.type !== Types.RequestLogic.CURRENCY.ISO4217 && | 
|  | 85 | +              hasValidPath && | 
|  | 86 | +              currency.network === newNetwork | 
|  | 87 | +            ); | 
|  | 88 | +          } | 
|  | 89 | +
 | 
|  | 90 | +          // For other currency types (like ERC20) | 
|  | 91 | +          return invoiceCurrency.hash === currency?.hash; | 
|  | 92 | +        }, | 
|  | 93 | +      ); | 
| 99 | 94 |     } | 
| 100 | 95 |   }; | 
| 101 | 96 | 
 | 
| 102 | 97 |   let activeRequest: any = null; | 
| 103 | 98 |   let canSubmit = false; | 
| 104 | 99 |   let appStatus: APP_STATUS[] = []; | 
| 105 | 100 |   let formData = getInitialFormData(); | 
| 106 |  | -  let defaultCurrencies = currencyManager.knownCurrencies; | 
| 107 |  | -  let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] = []; | 
|  | 101 | +  // Remove duplicate currencies and filter out currencies with '-' in the symbol | 
|  | 102 | +  let defaultCurrencies = Object.values(currencyManager.knownCurrencies.reduce( | 
|  | 103 | +    (unique: { [x: string]: any; }, currency: { symbol: string | number; }) => { | 
|  | 104 | +      if (!unique[currency.symbol] && !currency.symbol.includes('-')) unique[currency.symbol] = currency; | 
|  | 105 | +
 | 
|  | 106 | +      return unique; | 
|  | 107 | +    }, | 
|  | 108 | +    {}, | 
|  | 109 | +  )); | 
| 108 | 110 | 
 | 
| 109 | 111 |   const handleInvoiceCurrencyChange = ( | 
| 110 |  | -    value: CurrencyTypes.CurrencyDefinition | 
|  | 112 | +    value: CurrencyTypes.CurrencyDefinition, | 
| 111 | 113 |   ) => { | 
| 112 | 114 |     if (value !== invoiceCurrency) { | 
| 113 | 115 |       networkDropdown.clear(); | 
|  | 
| 122 | 124 |       if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) { | 
| 123 | 125 |         networks = (getCurrencySupportedNetworksForConversion( | 
| 124 | 126 |           invoiceCurrency.hash, | 
| 125 |  | -          currencyManager | 
|  | 127 | +          currencyManager, | 
| 126 | 128 |         ) ?? []) as string[]; | 
| 127 | 129 |       } else { | 
| 128 |  | -        networks = extractUniqueNetworkNames(); | 
|  | 130 | +        networks = currencyManager.knownCurrencies.filter(currency => currency.symbol === invoiceCurrency?.symbol).map(currency => currency.network); | 
| 129 | 131 |       } | 
| 130 | 132 |     } | 
| 131 | 133 |   }; | 
|  | 
| 257 | 259 |               paymentNetwork: requestCreateParameters.paymentNetwork, | 
| 258 | 260 |               contentData: requestCreateParameters.contentData, | 
| 259 | 261 |             }, | 
| 260 |  | -            [payeeEncryptionParams, payerEncryptionParams] | 
|  | 262 | +            [payeeEncryptionParams, payerEncryptionParams], | 
| 261 | 263 |           ); | 
| 262 | 264 |         } else { | 
| 263 | 265 |           request = await requestNetwork.createRequest({ | 
|  | 
0 commit comments