diff --git a/.storybook/preview.ts b/.storybook/preview.ts
index 1fc8da9b8..74fabe68e 100644
--- a/.storybook/preview.ts
+++ b/.storybook/preview.ts
@@ -8,7 +8,7 @@ export const parameters = {
const preview: Preview = {
loaders: [
async () => ({
- settings: await (await fetch(`https://bridge-api.layerswap.io/api/settings?version=sandbox`)).json(),
+ settings: await (await fetch(`https://bridge-api-dev.layerswap.cloud/api/networks?version=sandbox`)).json(),
}),
],
parameters: {
diff --git a/components/Input/CurrencyFormField.tsx b/components/Input/CurrencyFormField.tsx
index aeeb7d342..1f7dd0550 100644
--- a/components/Input/CurrencyFormField.tsx
+++ b/components/Input/CurrencyFormField.tsx
@@ -22,6 +22,8 @@ const BalanceComponent = dynamic(() => import("./dynamic/Balance"), {
loading: () => <>>,
});
+const CurrencyDetails = dynamic(() => import("./dynamic/CurrencyFormItems"), {});
+
const CurrencyFormField: FC<{ direction: string }> = ({ direction }) => {
const {
values,
@@ -116,7 +118,8 @@ const CurrencyFormField: FC<{ direction: string }> = ({ direction }) => {
direction === "from" ? sourceRoutes?.data : destinationRoutes?.data,
direction,
balances[walletAddress || ''],
- query
+ query,
+ direction === 'from' ? from?.internal_name : to?.internal_name
)
const currencyAsset = direction === 'from' ? fromCurrency?.asset : toCurrency?.asset;
@@ -198,7 +201,10 @@ const CurrencyFormField: FC<{ direction: string }> = ({ direction }) => {
return (
-
setWalletAddress(v)} />
+ {
+ (direction == "from" ? values.from : values.to) &&
+ setWalletAddress(v)} />
+ }
[] {
+ query?: QueryParams,
+ network?: string): SelectMenuItem[] {
const { to, from } = values
const lockAsset = direction === 'from' ? query?.lockFromAsset
: query?.lockToAsset
@@ -240,8 +247,6 @@ export function GenerateCurrencyMenuItems(
return currencies?.map(c => {
const currency = c
const displayName = currency.display_asset ?? currency.asset;
- const balance = balances?.find(b => b?.token === c?.asset && (direction === 'from' ? from : to)?.internal_name === b.network)
- const formatted_balance_amount = balance ? Number(truncateDecimals(balance?.amount, c.precision)) : ''
const res: SelectMenuItem = {
baseObject: c,
@@ -250,7 +255,7 @@ export function GenerateCurrencyMenuItems(
order: CurrencySettings.KnownSettings[c.asset]?.Order ?? 5,
imgSrc: resolveImgSrc && resolveImgSrc(c),
isAvailable: currencyIsAvailable(c),
- details: `${formatted_balance_amount}`,
+ menuItemDetails: ,
type: "currency"
};
diff --git a/components/Input/dynamic/CurrencyFormItems.tsx b/components/Input/dynamic/CurrencyFormItems.tsx
new file mode 100644
index 000000000..eab79c19e
--- /dev/null
+++ b/components/Input/dynamic/CurrencyFormItems.tsx
@@ -0,0 +1,46 @@
+import { truncateDecimals } from "../../utils/RoundDecimals";
+import { NetworkCurrency } from "../../../Models/CryptoNetwork";
+import { useBalancesState } from "../../../context/balances";
+import useWallet from "../../../hooks/useWallet";
+import { useMemo } from "react";
+import { SwapFormValues } from "../../DTOs/SwapFormValues";
+
+const FormItems = ({ values, network, currency }: { values: SwapFormValues, network: string | undefined, currency: NetworkCurrency }) => {
+
+ const { to, from } = values
+ const { balances: allBalances } = useBalancesState()
+ const { wallets, getAutofillProvider: getProvider } = useWallet()
+
+ for (const key in allBalances) {
+ const matchingWallet = wallets.find(wallet => wallet.address === key);
+ if (!matchingWallet) {
+ delete allBalances[key];
+ }
+ }
+
+ const sourceWalletProvider = useMemo(() => {
+ return from && getProvider(from)
+ }, [from, getProvider])
+
+ const destinationWalletProvider = useMemo(() => {
+ return to && getProvider(to)
+ }, [to, getProvider])
+
+ const sourceNetworkWallet = sourceWalletProvider?.getConnectedWallet()
+ const destinationNetworkWallet = destinationWalletProvider?.getConnectedWallet()
+
+ const balance = allBalances[(sourceNetworkWallet ? sourceNetworkWallet?.address : destinationNetworkWallet?.address) || ""]?.find(b => b?.token === currency?.asset && network === b.network)
+ const formatted_balance_amount = balance ? Number(truncateDecimals(balance?.amount, currency.precision)) : ''
+
+ return (
+ balance &&
+ {Number(formatted_balance_amount) ?
+ {formatted_balance_amount}
+ :
+ ""
+ }
+
+ )
+}
+
+export default FormItems
\ No newline at end of file
diff --git a/components/Select/Shared/Props/selectMenuItem.tsx b/components/Select/Shared/Props/selectMenuItem.tsx
index 735bf9d97..1ea80b63e 100644
--- a/components/Select/Shared/Props/selectMenuItem.tsx
+++ b/components/Select/Shared/Props/selectMenuItem.tsx
@@ -1,9 +1,11 @@
+import { SwapFormValues } from "../../../DTOs/SwapFormValues";
import { CurrencyDisabledReason } from "../../../Input/CurrencyFormField";
import { LayerDisabledReason } from "../../Popover/PopoverSelect";
export class SelectMenuItem implements ISelectMenuItem {
id: string;
name: string;
+ menuItemDetails?: React.ReactNode;
order: number;
imgSrc: string;
isAvailable: {
@@ -33,6 +35,7 @@ export class SelectMenuItem implements ISelectMenuItem {
export interface ISelectMenuItem {
id: string;
name: string;
+ menuItemDetails?: React.ReactNode;
imgSrc: string;
group?: string;
isAvailable: {
diff --git a/components/Select/Shared/SelectItem.tsx b/components/Select/Shared/SelectItem.tsx
index ac9bd2ab5..3f009573b 100644
--- a/components/Select/Shared/SelectItem.tsx
+++ b/components/Select/Shared/SelectItem.tsx
@@ -18,9 +18,8 @@ export default function SelectItem({ item }: { item: ISelectMenuItem }) {
{item.name}
{
- item.details &&
- {item.details}
+ {item.details || item.menuItemDetails}
}
diff --git a/hooks/useBalance.ts b/hooks/useBalance.ts
index 377cc99f6..7d1a5deb0 100644
--- a/hooks/useBalance.ts
+++ b/hooks/useBalance.ts
@@ -13,7 +13,6 @@ import { NetworkCurrency } from "../Models/CryptoNetwork"
import useQueryBalances from "../lib/balances/query/useQueryBalances"
import { useQueryState } from "../context/query"
-
export default function useBalanceProvider() {
const BalanceProviders: BalanceProvider[] = [
@@ -37,7 +36,7 @@ export default function useBalanceProvider() {
setAllGases
} = useBalancesUpdate()
- const { getAutofillProvider } = useWallet()
+ const { getAutofillProvider, wallets } = useWallet()
const fetchBalance = async (network: Layer) => {
const provider = getAutofillProvider(network)