Skip to content

Commit

Permalink
chore(app): pre commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Swepool committed Jan 8, 2025
1 parent 86149a3 commit 3bfe20b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 45 deletions.
6 changes: 3 additions & 3 deletions app/src/lib/components/TransferFrom/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import Chains from "$lib/components/TransferFrom/components/Cube/faces/Chains.sv
import Assets from "$lib/components/TransferFrom/components/Cube/faces/Assets.svelte"
import Transfer from "$lib/components/TransferFrom/components/Cube/faces/Transfer.svelte"
import Cube from "$lib/components/TransferFrom/components/Cube/index.svelte"
import type {Chain, UserAddresses} from "$lib/types.ts";
import {userBalancesQuery} from "$lib/queries/balance";
import {balanceStore, userAddress} from "$lib/components/TransferFrom/transfer/balances.ts";
import type { Chain, UserAddresses } from "$lib/types.ts"
import { userBalancesQuery } from "$lib/queries/balance"
import { balanceStore, userAddress } from "$lib/components/TransferFrom/transfer/balances.ts"
export let chains: Array<Chain>
Expand Down
14 changes: 7 additions & 7 deletions app/src/lib/components/TransferFrom/transfer/balances.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {derived, type Readable, writable} from "svelte/store";
import type {UserAddresses} from "$lib/types.ts";
import {userAddrCosmos} from "$lib/wallet/cosmos";
import {userAddrEvm} from "$lib/wallet/evm";
import {userAddressAptos} from "$lib/wallet/aptos";
import type {QueryObserverResult} from "@tanstack/query-core";
import { derived, type Readable, writable } from "svelte/store"
import type { UserAddresses } from "$lib/types.ts"
import { userAddrCosmos } from "$lib/wallet/cosmos"
import { userAddrEvm } from "$lib/wallet/evm"
import { userAddressAptos } from "$lib/wallet/aptos"
import type { QueryObserverResult } from "@tanstack/query-core"

export let userAddress: Readable<UserAddresses> = derived(
[userAddrCosmos, userAddrEvm, userAddressAptos],
Expand All @@ -14,4 +14,4 @@ export let userAddress: Readable<UserAddresses> = derived(
})
)

export let balanceStore = writable<QueryObserverResult<any>[]>([])
export let balanceStore = writable<Array<QueryObserverResult<any>>>([])
59 changes: 28 additions & 31 deletions app/src/lib/components/TransferFrom/transfer/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { derived, type Readable } from "svelte/store"
import type { Chain, UserAddresses } from "$lib/types"
import type { Address } from "$lib/wallet/types"
import { balanceStore, userAddress } from "./balances"
import { balanceStore, userAddress } from "./balances.ts"

export type BalanceRecord = {
balance: bigint
Expand All @@ -24,44 +24,41 @@ export interface ContextStore {
}

export function createContextStore(chains: Array<Chain>): Readable<ContextStore> {
const balances = derived(
balanceStore,
($rawBalances) => {
if (!$rawBalances?.length) {
return chains.map(chain => ({
chainId: chain.chain_id,
balances: []
}))
}

return chains.map((chain, chainIndex) => {
const balanceResult = $rawBalances[chainIndex]
const balances = derived(balanceStore, $rawBalances => {
if ($rawBalances?.length === 0) {
return chains.map(chain => ({
chainId: chain.chain_id,
balances: []
}))
}

if (!balanceResult?.isSuccess || balanceResult.data instanceof Error) {
console.log(`No balances fetched yet for chain ${chain.chain_id}`)
return {
chainId: chain.chain_id,
balances: []
}
}
return chains.map((chain, chainIndex) => {
const balanceResult = $rawBalances[chainIndex]

if (!balanceResult?.isSuccess || balanceResult.data instanceof Error) {
console.log(`No balances fetched yet for chain ${chain.chain_id}`)
return {
chainId: chain.chain_id,
balances: balanceResult.data.map(balance => ({
...balance,
balance: BigInt(balance.balance),
gasToken: balance.gasToken ?? false,
address: balance.address as Address,
symbol: balance.symbol || balance.address
}))
balances: []
}
})
}
) as Readable<BalancesList>
}

return {
chainId: chain.chain_id,
balances: balanceResult.data.map(balance => ({
...balance,
balance: BigInt(balance.balance),
gasToken: balance.gasToken ?? false,
address: balance.address as Address,
symbol: balance.symbol || balance.address
}))
}
})
}) as Readable<BalancesList>

return derived([userAddress, balances], ([$userAddress, $balances]) => ({
chains,
userAddress: $userAddress,
balances: $balances
}))
}
}
6 changes: 2 additions & 4 deletions app/src/lib/components/TransferFrom/transfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import {
createValidationStore,
type ValidationStore
} from "$lib/components/TransferFrom/transfer/validation.ts"
import type { Chain, UserAddresses } from "$lib/types"
import type { QueryObserverResult } from "@tanstack/svelte-query"

import type { Chain } from "$lib/types"

export interface TransferStore {
rawIntents: RawIntentsStore
Expand All @@ -35,4 +33,4 @@ export function createTransferStore(chains: Array<Chain>): TransferStore {
intents,
validation
}
}
}

0 comments on commit 3bfe20b

Please sign in to comment.