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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.14",
"version": "0.11.15",
"main": "./dist/web-component.umd.cjs",
"scripts": {
"dev": "vite dev",
Expand Down
104 changes: 53 additions & 51 deletions packages/create-invoice-form/src/lib/create-invoice-form.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<svelte:options customElement="create-invoice-form" />

<script lang="ts">
import { getAccount, watchAccount, WatchAccountReturnType } from "@wagmi/core";
import {
getAccount,
watchAccount,
WatchAccountReturnType,
} from "@wagmi/core";
import { Config as WagmiConfig } from "wagmi";
// Types
import { type GetAccountReturnType } from "@wagmi/core";
Expand All @@ -24,7 +28,7 @@
import Status from "@requestnetwork/shared-components/status.svelte";
import Modal from "@requestnetwork/shared-components/modal.svelte";
import { EncryptionTypes, CipherProviderTypes } from "@requestnetwork/types";
import { onDestroy, onMount, tick } from "svelte";
import { onDestroy, onMount, tick } from "svelte";

interface CipherProvider extends CipherProviderTypes.ICipherProvider {
disconnectWallet: () => void;
Expand All @@ -36,32 +40,19 @@
export let currencies: CurrencyTypes.CurrencyInput[] = [];
let cipherProvider: CipherProvider | undefined;

let account: GetAccountReturnType | undefined = wagmiConfig && getAccount(wagmiConfig);
let account: GetAccountReturnType | undefined =
wagmiConfig && getAccount(wagmiConfig);
let isTimeout = false;
let activeConfig = config ? config : defaultConfig;
let mainColor = activeConfig.colors.main;
let secondaryColor = activeConfig.colors.secondary;
let currencyManager = initializeCurrencyManager(currencies);

let invoiceCurrencyDropdown: { clear: () => void; };
let networkDropdown: { clear: () => void; };
let currencyDropdown: { clear: () => void; };

const extractUniqueNetworkNames = (): string[] => {
const networkSet = new Set<string>();

currencyManager.knownCurrencies.forEach(
(currency: CurrencyTypes.CurrencyDefinition) => {
if (currency.network) {
networkSet.add(currency.network);
}
}
);

return Array.from(networkSet);
};

let networks: string[] = extractUniqueNetworkNames();
let invoiceCurrencyDropdown: { clear: () => void };
let networkDropdown: { clear: () => void };
let currencyDropdown: { clear: () => void };
let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] = [];
let networks: string[] = [];

let network: string | undefined = undefined;
let currency: CurrencyTypes.CurrencyDefinition | undefined = undefined;
Expand All @@ -70,44 +61,55 @@
const handleNetworkChange = (newNetwork: string) => {
if (newNetwork) {
currencyDropdown.clear();
invoiceCurrency = invoiceCurrency?.type !== Types.RequestLogic.CURRENCY.ISO4217 ? currencyManager.knownCurrencies.find(currency => invoiceCurrency?.symbol === currency.symbol && currency.network === newNetwork) : invoiceCurrency;
network = newNetwork;

currency = undefined;

filteredSettlementCurrencies = currencyManager.knownCurrencies.filter((currency: CurrencyTypes.CurrencyDefinition) => {
if (!invoiceCurrency) {
return false;
}

// For ISO4217 currencies (like EUR)
if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) {
const hasValidPath =
currencyManager?.getConversionPath(
invoiceCurrency,
currency,
currency?.network
)?.length > 0;

return (
currency.type !== Types.RequestLogic.CURRENCY.ISO4217 && hasValidPath
);
}

// For other currency types (like ERC20)
return invoiceCurrency.hash === currency?.hash;
});;
filteredSettlementCurrencies = currencyManager.knownCurrencies.filter(
(currency: CurrencyTypes.CurrencyDefinition) => {
if (!invoiceCurrency) {
return false;
}

// For ISO4217 currencies (like EUR)
if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) {
const hasValidPath =
currencyManager?.getConversionPath(
invoiceCurrency,
currency,
currency?.network,
)?.length > 0;

return (
currency.type !== Types.RequestLogic.CURRENCY.ISO4217 &&
hasValidPath &&
currency.network === newNetwork
);
}

// For other currency types (like ERC20)
return invoiceCurrency.hash === currency?.hash;
},
);
}
};

let activeRequest: any = null;
let canSubmit = false;
let appStatus: APP_STATUS[] = [];
let formData = getInitialFormData();
let defaultCurrencies = currencyManager.knownCurrencies;
let filteredSettlementCurrencies: CurrencyTypes.CurrencyDefinition[] = [];
// Remove duplicate currencies and filter out currencies with '-' in the symbol
let defaultCurrencies = Object.values(currencyManager.knownCurrencies.reduce(
(unique: { [x: string]: any; }, currency: { symbol: string | number; }) => {
if (!unique[currency.symbol] && !currency.symbol.includes('-')) unique[currency.symbol] = currency;

return unique;
},
{},
));

const handleInvoiceCurrencyChange = (
value: CurrencyTypes.CurrencyDefinition
value: CurrencyTypes.CurrencyDefinition,
) => {
if (value !== invoiceCurrency) {
networkDropdown.clear();
Expand All @@ -122,10 +124,10 @@
if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) {
networks = (getCurrencySupportedNetworksForConversion(
invoiceCurrency.hash,
currencyManager
currencyManager,
) ?? []) as string[];
} else {
networks = extractUniqueNetworkNames();
networks = currencyManager.knownCurrencies.filter(currency => currency.symbol === invoiceCurrency?.symbol).map(currency => currency.network);
}
}
};
Expand Down Expand Up @@ -257,7 +259,7 @@
paymentNetwork: requestCreateParameters.paymentNetwork,
contentData: requestCreateParameters.contentData,
},
[payeeEncryptionParams, payerEncryptionParams]
[payeeEncryptionParams, payerEncryptionParams],
);
} else {
request = await requestNetwork.createRequest({
Expand Down
2 changes: 1 addition & 1 deletion packages/create-invoice-form/src/lib/invoice/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@
bind:this={invoiceCurrencyDropdown}
getValue={(currency) => currency.value.symbol}
getDisplayValue={(currency) =>
`${currency.value.symbol} ${currency.value.network ? `(${currency.value.network})` : ""}`}
`${currency.value.symbol}`}
placeholder="Invoice currency"
items={defaultCurrencies
?.filter((curr) => curr)
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.12",
"version": "0.11.13",
"main": "./dist/web-component.umd.cjs",
"scripts": {
"dev": "vite dev",
Expand Down
11 changes: 8 additions & 3 deletions packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,14 @@
}
function formatBalance(value: number, maxDecimals: number = 4): string {
return Number.isInteger(value)
? value.toString()
: value.toFixed(maxDecimals);
try {
return Number.isInteger(value)
? value.toString()
: value.toFixed(maxDecimals);
} catch (error) {
console.error("Error formatting balance:", error);
return "-";
}
}
async function checkBalance() {
Expand Down
Loading