@@ -18,83 +18,7 @@ import {
1818 isComplete as isAptosComplete
1919} from " $lib/services/transfer-ucs03-aptos"
2020import ChainAsset from " $lib/components/Transfer/ChainAsset/index.svelte"
21- import { balancesStore } from " $lib/stores/balances.svelte.ts"
22- import { wallets } from " $lib/stores/wallets.svelte.ts"
23- import { Effect , Fiber , Option } from " effect"
24- import { tokensStore } from " $lib/stores/tokens.svelte.ts"
2521
26- $effect (() => {
27- transfer .getQuoteToken ()
28- transfer .getWethQuoteToken ()
29-
30- })
31-
32- $effect (() => {
33- if (Option .isSome (transfer .sourceChain )) {
34- tokensStore .fetchTokens (transfer .sourceChain .value .universal_chain_id )
35- }
36- })
37-
38- // Keep track of current fiber and chain
39- let currentFetchFiber = $state <Fiber .RuntimeFiber <void , never > | null >(null )
40- let currentChainId = $state <string | null >(null )
41- let lastFetchKey = $state (" " )
42-
43- $effect (() => {
44- // Get the current source chain
45- const sourceChain = Option .getOrNull (transfer .sourceChain )
46-
47- // If the chain changed, interrupt the existing fiber
48- if (sourceChain ?.universal_chain_id !== currentChainId ) {
49- if (currentFetchFiber ) {
50- console .log (` Interrupting fiber for chain: ${currentChainId } ` )
51- Effect .runPromise (Fiber .interrupt (currentFetchFiber ))
52- currentFetchFiber = null
53- }
54-
55- // Update the current chain ID
56- currentChainId = sourceChain ?.universal_chain_id || null
57-
58- // Reset the lastFetchKey when changing chains
59- lastFetchKey = " "
60- }
61-
62- // Exit if no source chain
63- if (! sourceChain ) return
64-
65- // Check for wallet address
66- const addressOption = wallets .getAddressForChain (sourceChain )
67- if (! Option .isSome (addressOption )) return
68-
69- const address = addressOption .value
70-
71- // Get tokens data
72- const tokensOption = tokensStore .data .get (sourceChain .universal_chain_id ) ?? Option .none ()
73-
74- // Only proceed if we have tokens
75- if (! Option .isSome (tokensOption )) return
76-
77- // Create a unique key for this combination of chain + address
78- const fetchKey = ` ${sourceChain .universal_chain_id }:${address } `
79-
80- // Check if we need to fetch new balances
81- if (fetchKey !== lastFetchKey ) {
82- const tokens = tokensOption .value
83- const denoms = tokens .map (token => token .denom )
84-
85- // Get the chainKey to access the fiber from balancesStore
86- const chainKey = ` ${sourceChain .universal_chain_id }:${address } ` as const
87-
88- // Fetch balances for all tokens
89- balancesStore .fetchBalances (sourceChain , address , denoms )
90-
91- // Store the new fiber reference
92- currentFetchFiber = balancesStore .chainFibers .get (chainKey ) || null
93-
94- // Update the last fetch key
95- lastFetchKey = fetchKey
96- }
97- })
9822function getStatus(
9923 state : TransferStateUnion
10024): " empty" | " filling" | " processing" | " failed" | " complete" {
0 commit comments