Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/create-invoice-form/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
54 changes: 28 additions & 26 deletions packages/create-invoice-form/src/lib/create-invoice-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,53 +58,55 @@
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
);
}
};
let activeRequest: any = null;
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;
}
}
};
const handleCurrencyChange = (value: CurrencyTypes.CurrencyDefinition) => {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
>
<span>Due: </span>
<span
>{currency ? currency.symbol : ""}
>{invoiceCurrency ? invoiceCurrency.symbol : ""}
{" "}
{invoiceTotals.totalAmount.toFixed(2)}</span
>
Expand Down
80 changes: 48 additions & 32 deletions packages/create-invoice-form/src/lib/invoice/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -398,19 +382,6 @@
</div>
</Accordion>
</div>

<Dropdown
{config}
selectedValue={invoiceCurrency
? `${invoiceCurrency.symbol} ${invoiceCurrency?.network ? `(${invoiceCurrency?.network})` : ""}`
: undefined}
placeholder="Invoice currency (labeling)"
options={defaultCurrencies.map((currency) => ({
value: currency,
label: `${currency.symbol} ${currency?.network ? `(${currency?.network})` : ""}`,
}))}
onchange={handleInvoiceCurrencyChange}
/>
<Dropdown
{config}
placeholder="Payment chain"
Expand All @@ -425,18 +396,63 @@
})}
onchange={handleNetworkChange}
/>
<Dropdown
{config}
selectedValue={invoiceCurrency
? `${invoiceCurrency.symbol} ${invoiceCurrency?.network ? `(${invoiceCurrency?.network})` : ""}`
: undefined}
placeholder="Invoice currency (labeling)"
options={defaultCurrencies
?.filter((curr) => {
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}
/>
<Dropdown
{config}
placeholder="Settlement currency"
selectedValue={currency
? `${currency.symbol ?? "Unknown"} (${currency?.network ?? "Unknown"})`
: undefined}
options={defaultCurrencies
.filter((currency) => 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}
/>
</div>
Expand Down
6 changes: 3 additions & 3 deletions packages/create-invoice-form/src/lib/utils/resetForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
2 changes: 1 addition & 1 deletion packages/invoice-dashboard/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down