diff --git a/app/src/lib/components/TransferFrom/components/Cube/FaceWrapper.svelte b/app/src/lib/components/TransferFrom/components/Cube/FaceWrapper.svelte index 05e44ff759..531d6b86f9 100644 --- a/app/src/lib/components/TransferFrom/components/Cube/FaceWrapper.svelte +++ b/app/src/lib/components/TransferFrom/components/Cube/FaceWrapper.svelte @@ -1,5 +1,5 @@
-
+ \ No newline at end of file diff --git a/app/src/lib/components/TransferFrom/components/Cube/faces/Assets.svelte b/app/src/lib/components/TransferFrom/components/Cube/faces/Assets.svelte index d44299c058..c4c10ca611 100644 --- a/app/src/lib/components/TransferFrom/components/Cube/faces/Assets.svelte +++ b/app/src/lib/components/TransferFrom/components/Cube/faces/Assets.svelte @@ -4,6 +4,11 @@ import type {Readable} from "svelte/store"; import type {ContextStore} from "$lib/components/TransferFrom/transfer/context.ts"; import type {CubeFaces} from "$lib/components/TransferFrom/types.ts"; + import {showUnsupported} from "$lib/stores/user.ts"; + import {getSupportedAsset} from "$lib/utilities/helpers.ts"; + import {truncate} from "$lib/utilities/format.ts"; + import {formatUnits} from "viem"; + import {Button} from "$lib/components/ui/button"; interface Props { stores: { @@ -17,7 +22,41 @@ export let stores: Props["stores"] export let rotateTo: Props["rotateTo"] - $: ({intents, validation, context} = stores) + let {intents, validation, context} = stores + + function setAsset(address: string) { + intents.updateField('asset', address) + rotateTo("intentFace") + } + - \ No newline at end of file +
+
+ {#each $context.balances as asset} + {@const supportedAsset = getSupportedAsset($context.sourceChain, asset.address)} + {#if $showUnsupported || supportedAsset} +
+ +
+ {/if} + {/each} +
+ +
+ +
+
diff --git a/app/src/lib/components/TransferFrom/components/Cube/faces/Chains.svelte b/app/src/lib/components/TransferFrom/components/Cube/faces/Chains.svelte index f83fdc7bc7..2c165ce769 100644 --- a/app/src/lib/components/TransferFrom/components/Cube/faces/Chains.svelte +++ b/app/src/lib/components/TransferFrom/components/Cube/faces/Chains.svelte @@ -4,6 +4,9 @@ import type {Readable} from "svelte/store"; import type {ContextStore} from "$lib/components/TransferFrom/transfer/context.ts"; import type {CubeFaces} from "$lib/components/TransferFrom/types.ts"; + import {Button} from "$lib/components/ui/button"; + import {truncate} from "$lib/utilities/format.ts"; + import {formatUnits} from "viem"; interface Props { stores: { @@ -12,17 +15,31 @@ context: Readable } rotateTo: (face: CubeFaces) => void - select: "source" | "destination" + selected: "source" | "destination" } - export let stores: Props["stores"] - export let rotateTo: Props["rotateTo"] - export let select: Props["select"] + export let stores: Props["stores"]; + export let rotateTo: Props["rotateTo"]; + export let selected: Props["selected"]; - $: ({intents, validation, context} = stores) + $: ({intents, validation, context} = stores); + + function setChain(selected: "source" | "destination", chainId: string) { + intents.updateField(selected, chainId); + console.log(selected, chainId); + rotateTo("intentFace"); + } -

Select chain

-{#each $context.chains as chain} - -{/each} \ No newline at end of file +
+
+ {#each $context.chains as chain} + + {/each} +
+ +
diff --git a/app/src/lib/components/TransferFrom/components/Cube/faces/Intent.svelte b/app/src/lib/components/TransferFrom/components/Cube/faces/Intent.svelte index cb7b0ffabb..6481bbd0f2 100644 --- a/app/src/lib/components/TransferFrom/components/Cube/faces/Intent.svelte +++ b/app/src/lib/components/TransferFrom/components/Cube/faces/Intent.svelte @@ -1,6 +1,6 @@
- rotateTo("sourceFace")} - getDestinationChain={() => rotateTo("destinationFace")} - /> - rotateTo("assetsFace")} - /> + rotateTo("sourceFace")} getDestinationChain={() => rotateTo("destinationFace")}/> + rotateTo("assetsFace")}/>
{$context?.sourceChain?.display_name.split(" ")[0]} @@ -31,9 +31,9 @@ variant="outline" type="button" size="sm" - class="border-2 border-white min-w-[150px] font-bold" + class="border-2 border-white font-bold" on:click={getDestinationChain} > - {$context?.destinationChain?.display_name.split(" ")[0] ?? "To"} + {$context?.destinationChain?.display_name.split(" ")[0] ?? "To chain"}
diff --git a/app/src/lib/components/TransferFrom/components/AssetDialog.svelte b/app/src/lib/components/TransferFrom/components/SelectedAsset.svelte similarity index 78% rename from app/src/lib/components/TransferFrom/components/AssetDialog.svelte rename to app/src/lib/components/TransferFrom/components/SelectedAsset.svelte index f0b418ecb0..03beabf2ef 100644 --- a/app/src/lib/components/TransferFrom/components/AssetDialog.svelte +++ b/app/src/lib/components/TransferFrom/components/SelectedAsset.svelte @@ -15,12 +15,10 @@ export let onSelectAsset: Props["onSelectAsset"] - \ No newline at end of file diff --git a/app/src/lib/components/TransferFrom/index.svelte b/app/src/lib/components/TransferFrom/index.svelte index e799bdc15d..00f3b065b1 100644 --- a/app/src/lib/components/TransferFrom/index.svelte +++ b/app/src/lib/components/TransferFrom/index.svelte @@ -1,7 +1,7 @@ @@ -17,11 +20,11 @@
- +
- +
diff --git a/app/src/lib/components/TransferFrom/transfer/context.ts b/app/src/lib/components/TransferFrom/transfer/context.ts index e521329631..883f96f2d0 100644 --- a/app/src/lib/components/TransferFrom/transfer/context.ts +++ b/app/src/lib/components/TransferFrom/transfer/context.ts @@ -8,32 +8,24 @@ import type { Chain, UserAddresses } from "$lib/types" import { useQueryClient } from "@tanstack/svelte-query" import type { Address } from "$lib/wallet/types" -export type AddressBalance = { +type BalanceRecord = { balance: bigint gasToken: boolean address: Address symbol: string } -export type NamedBalance = { - balance: bigint - address: string - name: string | null - symbol: string - gasToken: boolean -} - -export type EmptyBalance = {} - -export type Balance = AddressBalance | NamedBalance | EmptyBalance +type BalancesList = BalanceRecord[] export interface ContextStore { chains: Array userAddress: UserAddresses - sourceChain: Chain | undefined + sourceChain: Chain destinationChain: Chain | undefined - balances: Array - assetInfo: Balance | undefined + // Changed from Array to just BalancesList + balances: BalancesList + // Changed from BalancesStore to single BalanceRecord + assetInfo: BalanceRecord | undefined } export function createContextStore(intents: IntentStore): Readable { @@ -47,19 +39,20 @@ export function createContextStore(intents: IntentStore): Readable return (filter ? data.filter(filter) : data) as T } - // Chain data const chains = queryData>(["chains"], chain => chain.enabled_staging) - // User address data const userAddress = derived( [userAddrCosmos, userAddrEvm, userAddressAptos], ([cosmos, evm, aptos]) => ({ evm, aptos, cosmos }) ) as Readable - // Chain selections - const sourceChain = derived(intents, intentsValue => - chains.find(chain => chain.chain_id === intentsValue.source) - ) + const sourceChain = derived(intents, intentsValue => { + const chain = chains.find(chain => chain.chain_id === intentsValue.source) + if (!chain) { + throw new Error(`No chain found for source ${intentsValue.source}`) + } + return chain + }) const destinationChain = derived(intents, intentsValue => chains.find(chain => chain.chain_id === intentsValue.destination) @@ -88,7 +81,7 @@ export function createContextStore(intents: IntentStore): Readable balance: BigInt(balance.balance) })) } - ) + ) as Readable const assetInfo = derived([balances, intents], ([balancesValue, intentsValue]) => balancesValue.find(x => x?.address === intentsValue.asset) @@ -105,4 +98,4 @@ export function createContextStore(intents: IntentStore): Readable assetInfo: $assetInfo }) ) -} +} \ No newline at end of file diff --git a/app/src/lib/components/TransferFrom/transfer/validation.ts b/app/src/lib/components/TransferFrom/transfer/validation.ts index 684086b4b6..e9451dfe06 100644 --- a/app/src/lib/components/TransferFrom/transfer/validation.ts +++ b/app/src/lib/components/TransferFrom/transfer/validation.ts @@ -111,7 +111,6 @@ export function createValidationStore( } const errors: FieldErrors = {} - //Example if (formFields.source && formFields.destination && formFields.source === formFields.destination) { errors.destination = "Source and destination chains must be different" } diff --git a/app/src/lib/queries/balance/index.ts b/app/src/lib/queries/balance/index.ts index 3aea0d924d..bf355cf543 100644 --- a/app/src/lib/queries/balance/index.ts +++ b/app/src/lib/queries/balance/index.ts @@ -9,15 +9,7 @@ import type { Chain, UserAddresses } from "$lib/types.ts" import { getBalancesFromAlchemy } from "./evm/alchemy.ts" import { getBalancesFromRoutescan } from "./evm/routescan.ts" -export function userBalancesQuery({ - userAddr, - chains, - connected = true -}: { - userAddr: UserAddresses - chains: Array - connected?: boolean -}) { +export function userBalancesQuery({userAddr, chains, connected = true}: { userAddr: UserAddresses, chains: Array, connected?: boolean }) { return createQueries({ queries: chains.map(chain => ({ queryKey: [