Skip to content

Commit 4876766

Browse files
committed
Merge branch 'main' of github.com:RequestNetwork/web-components into 70-add-column-for-payment-chain-in-the-invoice-dashboard
2 parents 141410c + 6ef80ec commit 4876766

File tree

9 files changed

+396
-360
lines changed

9 files changed

+396
-360
lines changed

packages/create-invoice-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/create-invoice-form",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",

packages/create-invoice-form/src/lib/create-invoice-form.svelte

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,53 +58,55 @@
5858
5959
const handleNetworkChange = (newNetwork: string) => {
6060
if (newNetwork) {
61-
const newCurrencies = currencyManager.knownCurrencies.filter(
62-
(currency: CurrencyTypes.CurrencyDefinition) =>
63-
currency.type === Types.RequestLogic.CURRENCY.ISO4217 ||
64-
currency.network === newNetwork
65-
);
66-
6761
network = newNetwork;
68-
defaultCurrencies = newCurrencies;
62+
63+
invoiceCurrency = undefined;
6964
currency = undefined;
65+
66+
defaultCurrencies = currencyManager.knownCurrencies.filter(
67+
(curr: CurrencyTypes.CurrencyDefinition) =>
68+
curr.type === Types.RequestLogic.CURRENCY.ISO4217 ||
69+
curr.network === newNetwork
70+
);
7071
}
7172
};
7273
7374
let activeRequest: any = null;
7475
let canSubmit = false;
7576
let appStatus: APP_STATUS[] = [];
7677
let formData = getInitialFormData();
77-
let defaultCurrencies = currencyManager.knownCurrencies.filter(
78-
(currency: CurrencyTypes.CurrencyDefinition) =>
79-
currency.type === Types.RequestLogic.CURRENCY.ISO4217 || network
80-
? currency.network === network
81-
: true
82-
);
78+
let defaultCurrencies = currencyManager.knownCurrencies;
8379
8480
const handleInvoiceCurrencyChange = (
8581
value: CurrencyTypes.CurrencyDefinition
8682
) => {
87-
invoiceCurrency = value;
88-
network = undefined;
89-
currency = undefined;
83+
if (value !== invoiceCurrency) {
84+
invoiceCurrency = value;
85+
currency = undefined;
9086
91-
if (
92-
invoiceCurrency &&
93-
invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217
94-
) {
95-
networks = getCurrencySupportedNetworksForConversion(
96-
invoiceCurrency.hash,
97-
currencyManager
98-
);
99-
} else {
100-
networks = extractUniqueNetworkNames();
87+
if (value.type !== Types.RequestLogic.CURRENCY.ISO4217) {
88+
network = value.network;
89+
}
10190
}
10291
};
10392
10493
const handleCurrencyChange = (value: CurrencyTypes.CurrencyDefinition) => {
10594
currency = value;
10695
};
10796
97+
$: {
98+
if (invoiceCurrency) {
99+
if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) {
100+
networks = getCurrencySupportedNetworksForConversion(
101+
invoiceCurrency.hash,
102+
currencyManager
103+
);
104+
} else {
105+
networks = extractUniqueNetworkNames();
106+
}
107+
}
108+
}
109+
108110
let invoiceTotals = {
109111
amountWithoutTax: 0,
110112
totalTaxAmount: 0,

packages/create-invoice-form/src/lib/invoice/form-view.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
>
233233
<span>Due: </span>
234234
<span
235-
>{currency ? currency.symbol : ""}
235+
>{invoiceCurrency ? invoiceCurrency.symbol : ""}
236236
{" "}
237237
{invoiceTotals.totalAmount.toFixed(2)}</span
238238
>

packages/create-invoice-form/src/lib/invoice/form.svelte

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
export let formData: CustomFormData;
2828
export let handleInvoiceCurrencyChange: (value: string) => void;
2929
export let handleCurrencyChange: (value: string) => void;
30-
3130
export let handleNetworkChange: (chainId: string) => void;
3231
export let networks;
3332
export let defaultCurrencies: any = [];
@@ -117,21 +116,6 @@
117116
}
118117
};
119118
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-
135119
const addInvoiceItem = () => {
136120
const newItem = {
137121
name: "",
@@ -398,19 +382,6 @@
398382
</div>
399383
</Accordion>
400384
</div>
401-
402-
<Dropdown
403-
{config}
404-
selectedValue={invoiceCurrency
405-
? `${invoiceCurrency.symbol} ${invoiceCurrency?.network ? `(${invoiceCurrency?.network})` : ""}`
406-
: undefined}
407-
placeholder="Invoice currency (labeling)"
408-
options={defaultCurrencies.map((currency) => ({
409-
value: currency,
410-
label: `${currency.symbol} ${currency?.network ? `(${currency?.network})` : ""}`,
411-
}))}
412-
onchange={handleInvoiceCurrencyChange}
413-
/>
414385
<Dropdown
415386
{config}
416387
placeholder="Payment chain"
@@ -425,18 +396,63 @@
425396
})}
426397
onchange={handleNetworkChange}
427398
/>
399+
<Dropdown
400+
{config}
401+
selectedValue={invoiceCurrency
402+
? `${invoiceCurrency.symbol} ${invoiceCurrency?.network ? `(${invoiceCurrency?.network})` : ""}`
403+
: undefined}
404+
placeholder="Invoice currency (labeling)"
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+
})) ?? []}
418+
onchange={handleInvoiceCurrencyChange}
419+
/>
428420
<Dropdown
429421
{config}
430422
placeholder="Settlement currency"
431423
selectedValue={currency
432424
? `${currency.symbol ?? "Unknown"} (${currency?.network ?? "Unknown"})`
433425
: undefined}
434426
options={defaultCurrencies
435-
.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+
})
436452
.map((currency) => ({
437453
value: currency,
438-
label: `${currency.symbol ?? "Unknown"} (${currency?.network ?? "Unknown"})`,
439-
}))}
454+
label: `${currency?.symbol ?? "Unknown"} ${currency?.network ? `(${currency.network})` : ""}`,
455+
})) ?? []}
440456
onchange={handleCurrencyChange}
441457
/>
442458
</div>

packages/create-invoice-form/src/lib/utils/resetForm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export function getInitialFormData() {
1616
{
1717
name: "",
1818
quantity: 1,
19-
unitPrice: "",
20-
discount: "",
19+
unitPrice: 0,
20+
discount: 0,
2121
tax: {
22-
amount: "",
22+
amount: 0,
2323
type: "percentage" as "fixed" | "percentage",
2424
},
2525
currency: "",

packages/invoice-dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/invoice-dashboard",
3-
"version": "0.11.0",
3+
"version": "0.11.1",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",

0 commit comments

Comments
 (0)