diff --git a/packages/create-invoice-form/package.json b/packages/create-invoice-form/package.json index 740d4b46..d2d1e90f 100644 --- a/packages/create-invoice-form/package.json +++ b/packages/create-invoice-form/package.json @@ -1,6 +1,6 @@ { "name": "@requestnetwork/create-invoice-form", - "version": "0.11.1", + "version": "0.11.2", "main": "./dist/web-component.umd.cjs", "scripts": { "dev": "vite dev", diff --git a/packages/create-invoice-form/src/lib/create-invoice-form.svelte b/packages/create-invoice-form/src/lib/create-invoice-form.svelte index bf05482b..b7d25443 100644 --- a/packages/create-invoice-form/src/lib/create-invoice-form.svelte +++ b/packages/create-invoice-form/src/lib/create-invoice-form.svelte @@ -58,15 +58,16 @@ const handleNetworkChange = (newNetwork: string) => { if (newNetwork) { - const newCurrencies = currencyManager.knownCurrencies.filter( - (currency: CurrencyTypes.CurrencyDefinition) => - currency.type === Types.RequestLogic.CURRENCY.ISO4217 || - currency.network === newNetwork - ); - network = newNetwork; - defaultCurrencies = newCurrencies; + + invoiceCurrency = undefined; currency = undefined; + + defaultCurrencies = currencyManager.knownCurrencies.filter( + (curr: CurrencyTypes.CurrencyDefinition) => + curr.type === Types.RequestLogic.CURRENCY.ISO4217 || + curr.network === newNetwork + ); } }; @@ -74,30 +75,18 @@ let canSubmit = false; let appStatus: APP_STATUS[] = []; let formData = getInitialFormData(); - let defaultCurrencies = currencyManager.knownCurrencies.filter( - (currency: CurrencyTypes.CurrencyDefinition) => - currency.type === Types.RequestLogic.CURRENCY.ISO4217 || network - ? currency.network === network - : true - ); + let defaultCurrencies = currencyManager.knownCurrencies; const handleInvoiceCurrencyChange = ( value: CurrencyTypes.CurrencyDefinition ) => { - invoiceCurrency = value; - network = undefined; - currency = undefined; + if (value !== invoiceCurrency) { + invoiceCurrency = value; + currency = undefined; - if ( - invoiceCurrency && - invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217 - ) { - networks = getCurrencySupportedNetworksForConversion( - invoiceCurrency.hash, - currencyManager - ); - } else { - networks = extractUniqueNetworkNames(); + if (value.type !== Types.RequestLogic.CURRENCY.ISO4217) { + network = value.network; + } } }; @@ -105,6 +94,19 @@ currency = value; }; + $: { + if (invoiceCurrency) { + if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) { + networks = getCurrencySupportedNetworksForConversion( + invoiceCurrency.hash, + currencyManager + ); + } else { + networks = extractUniqueNetworkNames(); + } + } + } + let invoiceTotals = { amountWithoutTax: 0, totalTaxAmount: 0, diff --git a/packages/create-invoice-form/src/lib/invoice/form-view.svelte b/packages/create-invoice-form/src/lib/invoice/form-view.svelte index 27af66a7..fdb1d84a 100644 --- a/packages/create-invoice-form/src/lib/invoice/form-view.svelte +++ b/packages/create-invoice-form/src/lib/invoice/form-view.svelte @@ -232,7 +232,7 @@ > Due: {currency ? currency.symbol : ""} + >{invoiceCurrency ? invoiceCurrency.symbol : ""} {" "} {invoiceTotals.totalAmount.toFixed(2)} diff --git a/packages/create-invoice-form/src/lib/invoice/form.svelte b/packages/create-invoice-form/src/lib/invoice/form.svelte index d0abf3b4..c5341cf0 100644 --- a/packages/create-invoice-form/src/lib/invoice/form.svelte +++ b/packages/create-invoice-form/src/lib/invoice/form.svelte @@ -27,7 +27,6 @@ export let formData: CustomFormData; export let handleInvoiceCurrencyChange: (value: string) => void; export let handleCurrencyChange: (value: string) => void; - export let handleNetworkChange: (chainId: string) => void; export let networks; export let defaultCurrencies: any = []; @@ -117,21 +116,6 @@ } }; - const filterSettlementCurrencies = ( - currency: CurrencyTypes.CurrencyDefinition - ) => { - return invoiceCurrency - ? invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217 - ? currency.type !== Types.RequestLogic.CURRENCY.ISO4217 && - currencyManager?.getConversionPath( - invoiceCurrency, - currency, - currency.network - )?.length > 0 - : invoiceCurrency.hash === currency.hash - : false; - }; - const addInvoiceItem = () => { const newItem = { name: "", @@ -398,19 +382,6 @@ - - ({ - value: currency, - label: `${currency.symbol} ${currency?.network ? `(${currency?.network})` : ""}`, - }))} - onchange={handleInvoiceCurrencyChange} - /> + { + if (!curr) return false; + + return ( + curr.type === Types.RequestLogic.CURRENCY.ISO4217 || + (curr.network && curr.network === network) + ); + }) + .map((currency) => ({ + value: currency, + label: `${currency?.symbol ?? "Unknown"} ${currency?.network ? `(${currency.network})` : ""}`, + })) ?? []} + onchange={handleInvoiceCurrencyChange} + /> filterSettlementCurrencies(currency)) + ?.filter((curr) => { + if (!curr || !invoiceCurrency) return false; + + if ( + invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217 + ) { + return ( + (curr.type === Types.RequestLogic.CURRENCY.ERC20 || + curr.type === Types.RequestLogic.CURRENCY.ISO4217) && + curr.network === network + ); + } else if ( + invoiceCurrency.type === Types.RequestLogic.CURRENCY.ERC20 + ) { + return ( + curr.type === Types.RequestLogic.CURRENCY.ERC20 && + curr.network === invoiceCurrency.network + ); + } else { + return ( + curr.type === Types.RequestLogic.CURRENCY.ERC20 && + curr.network === invoiceCurrency.network + ); + } + }) .map((currency) => ({ value: currency, - label: `${currency.symbol ?? "Unknown"} (${currency?.network ?? "Unknown"})`, - }))} + label: `${currency?.symbol ?? "Unknown"} ${currency?.network ? `(${currency.network})` : ""}`, + })) ?? []} onchange={handleCurrencyChange} /> diff --git a/packages/create-invoice-form/src/lib/utils/resetForm.ts b/packages/create-invoice-form/src/lib/utils/resetForm.ts index 682f8327..49677912 100644 --- a/packages/create-invoice-form/src/lib/utils/resetForm.ts +++ b/packages/create-invoice-form/src/lib/utils/resetForm.ts @@ -16,10 +16,10 @@ export function getInitialFormData() { { name: "", quantity: 1, - unitPrice: "", - discount: "", + unitPrice: 0, + discount: 0, tax: { - amount: "", + amount: 0, type: "percentage" as "fixed" | "percentage", }, currency: "", diff --git a/packages/invoice-dashboard/package.json b/packages/invoice-dashboard/package.json index 04b3110e..5ab52866 100644 --- a/packages/invoice-dashboard/package.json +++ b/packages/invoice-dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@requestnetwork/invoice-dashboard", - "version": "0.11.0", + "version": "0.11.1", "main": "./dist/web-component.umd.cjs", "scripts": { "dev": "vite dev",