Skip to content

Commit

Permalink
feat: filter payment chain based on available networks
Browse files Browse the repository at this point in the history
  • Loading branch information
aimensahnoun committed Jan 16, 2025
1 parent 84d89b0 commit 172c2f3
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions packages/create-invoice-form/src/lib/create-invoice-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,47 @@
currency = undefined;
filteredSettlementCurrencies = [];
network = undefined;
networks = [];
const availableNetworks = new Set(
currencyManager.knownCurrencies.map((currency) => currency.network)
);
if (invoiceCurrency.type === Types.RequestLogic.CURRENCY.ISO4217) {
networks = (getCurrencySupportedNetworksForConversion(
invoiceCurrency.hash,
currencyManager
) ?? []) as string[];
const conversionNetworks = new Set(
getCurrencySupportedNetworksForConversion(
invoiceCurrency.hash,
currencyManager
)
);
networks = [...availableNetworks].filter(
(network) =>
conversionNetworks.has(network) &&
(config.supportedNetworks
? config.supportedNetworks.includes(network)
: true)
);
console.log("networks: ", networks);
} else {
const baseSymbol = invoiceCurrency.symbol.split("-")[0];
networks = currencyManager.knownCurrencies
.filter((currency) => {
const currencyBaseSymbol = currency.symbol.split("-")[0];
return currencyBaseSymbol === baseSymbol;
})
.map((currency) => currency.network);
networks = [...availableNetworks].filter((network) => {
const hasToken = currencyManager.knownCurrencies.some(
(currency) =>
currency.network === network &&
currency.symbol.split("-")[0] === baseSymbol
);
return (
hasToken &&
(config.supportedNetworks
? config.supportedNetworks.includes(network)
: true)
);
});
}
networks = [...new Set(networks)];
}
};
Expand Down

0 comments on commit 172c2f3

Please sign in to comment.