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 9, 2025
1 parent c49ee67 commit 220b38c
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 179 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<script lang="ts">
import type { Readable } from "svelte/store"
import { truncate } from "$lib/utilities/format.ts"
import { formatUnits } from "viem"
import { Button } from "$lib/components/ui/button"
import type { CubeFaces } from "$lib/components/TransferFrom/components/Cube/types.ts"
import type { RawIntentsStore } from "$lib/components/TransferFrom/transfer/raw-intents.ts"
import type { IntentsStore, AssetListItem } from "$lib/components/TransferFrom/transfer/intents.ts"
import type { Readable } from "svelte/store"
import { truncate } from "$lib/utilities/format.ts"
import { formatUnits } from "viem"
import { Button } from "$lib/components/ui/button"
import type { CubeFaces } from "$lib/components/TransferFrom/components/Cube/types.ts"
import type { RawIntentsStore } from "$lib/components/TransferFrom/transfer/raw-intents.ts"
import type { IntentsStore, AssetListItem } from "$lib/components/TransferFrom/transfer/intents.ts"
interface Props {
stores: {
rawIntents: RawIntentsStore
intents: Readable<IntentsStore>
}
rotateTo: (face: CubeFaces) => void
interface Props {
stores: {
rawIntents: RawIntentsStore
intents: Readable<IntentsStore>
}
rotateTo: (face: CubeFaces) => void
}
export let stores: Props["stores"]
export let rotateTo: Props["rotateTo"]
export let stores: Props["stores"]
export let rotateTo: Props["rotateTo"]
let { rawIntents, intents } = stores
let { rawIntents, intents } = stores
function setAsset(denom: string) {
rawIntents.updateField("asset", denom)
rotateTo("intentFace")
}
function setAsset(denom: string) {
rawIntents.updateField("asset", denom)
rotateTo("intentFace")
}
</script>

<div class="flex flex-col h-full w-full">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<!-- ChainSelector.svelte -->
<script lang="ts">
import type { Readable } from "svelte/store"
import type { ContextStore } from "$lib/components/TransferFrom/transfer/context.ts"
import type { RawIntentsStore } from "$lib/components/TransferFrom/transfer/raw-intents.ts"
import type { CubeFaces } from "$lib/components/TransferFrom/components/Cube/types.ts"
import { Button } from "$lib/components/ui/button"
import { TRANSFER_DEBUG } from "$lib/components/TransferFrom/transfer/config.ts"
import type { Readable } from "svelte/store"
import type { ContextStore } from "$lib/components/TransferFrom/transfer/context.ts"
import type { RawIntentsStore } from "$lib/components/TransferFrom/transfer/raw-intents.ts"
import type { CubeFaces } from "$lib/components/TransferFrom/components/Cube/types.ts"
import { Button } from "$lib/components/ui/button"
import { TRANSFER_DEBUG } from "$lib/components/TransferFrom/transfer/config.ts"
interface Props {
stores: {
rawIntents: RawIntentsStore
context: Readable<ContextStore>
}
rotateTo: (face: CubeFaces) => void
selected: "source" | "destination"
interface Props {
stores: {
rawIntents: RawIntentsStore
context: Readable<ContextStore>
}
rotateTo: (face: CubeFaces) => void
selected: "source" | "destination"
}
export let stores: Props["stores"]
export let rotateTo: Props["rotateTo"]
export let selected: Props["selected"]
export let stores: Props["stores"]
export let rotateTo: Props["rotateTo"]
export let selected: Props["selected"]
let expandedChainId: string | null = null
let expandedChainId: string | null = null
let { rawIntents, context } = stores
let { rawIntents, context } = stores
function setChain(selected: "source" | "destination", chainId: string) {
rawIntents.updateField(selected, chainId)
rotateTo("intentFace")
}
function setChain(selected: "source" | "destination", chainId: string) {
rawIntents.updateField(selected, chainId)
rotateTo("intentFace")
}
function toggleExpand(chainId: string) {
expandedChainId = expandedChainId === chainId ? null : chainId
}
function toggleExpand(chainId: string) {
expandedChainId = expandedChainId === chainId ? null : chainId
}
</script>

<div class="flex flex-col h-full w-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import Direction from "$lib/components/TransferFrom/components/Direction.svelte"
import SelectedAsset from "$lib/components/TransferFrom/components/SelectedAsset.svelte"
import type { Readable } from "svelte/store"
import type {
ValidationStore,
} from "$lib/components/TransferFrom/transfer/validation.ts"
import type { ValidationStore } from "$lib/components/TransferFrom/transfer/validation.ts"
import { Button } from "$lib/components/ui/button"
import type { IntentsStore } from "$lib/components/TransferFrom/transfer/intents.ts"
import type { CubeFaces } from "$lib/components/TransferFrom/components/Cube/types.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ let transferState: Writable<TransferState> = writable({ kind: "PRE_TRANSFER" })
const transfer = async () => {
if (!$validation.isValid) return
let parsedAmount = parseUnits($validation.transfer.amount, $validation.transfer.asset.metadata.decimals)
let parsedAmount = parseUnits(
$validation.transfer.amount,
$validation.transfer.asset.metadata.decimals
)
/** --- APTOS START --- */
if ($validation.transfer.sourceChain.rpc_type === "aptos") {
Expand Down
32 changes: 16 additions & 16 deletions app/src/lib/components/TransferFrom/components/SelectedAsset.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<script lang="ts">
import type { Readable } from "svelte/store"
import { Button } from "$lib/components/ui/button"
import { truncate } from "$lib/utilities/format.ts"
import type { IntentsStore } from "$lib/components/TransferFrom/transfer/intents.ts"
import type { ValidationStore } from "$lib/components/TransferFrom/transfer/validation.ts"
import type { RawIntentsStore } from "$lib/components/TransferFrom/transfer/raw-intents.ts"
import type { Readable } from "svelte/store"
import { Button } from "$lib/components/ui/button"
import { truncate } from "$lib/utilities/format.ts"
import type { IntentsStore } from "$lib/components/TransferFrom/transfer/intents.ts"
import type { ValidationStore } from "$lib/components/TransferFrom/transfer/validation.ts"
import type { RawIntentsStore } from "$lib/components/TransferFrom/transfer/raw-intents.ts"
interface Props {
rawIntents: RawIntentsStore
intents: Readable<IntentsStore>
validation: Readable<ValidationStore>
onSelectAsset: () => void
}
interface Props {
rawIntents: RawIntentsStore
intents: Readable<IntentsStore>
validation: Readable<ValidationStore>
onSelectAsset: () => void
}
export let rawIntents: Props["rawIntents"]
export let intents: Props["intents"]
export let validation: Props["validation"]
export let onSelectAsset: Props["onSelectAsset"]
export let rawIntents: Props["rawIntents"]
export let intents: Props["intents"]
export let validation: Props["validation"]
export let onSelectAsset: Props["onSelectAsset"]
</script>

<div class="flex flex-col w-full gap-2">
Expand Down
8 changes: 3 additions & 5 deletions app/src/lib/components/TransferFrom/transfer/balances.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

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 type {BalanceData} from "$lib/queries/balance";
import {derived, type Readable, writable} from "svelte/store";
import type { BalanceData } from "$lib/queries/balance"
import { derived, type Readable, writable } from "svelte/store"

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

export const balanceStore = writable<BalanceData[][]>([])
export const balanceStore = writable<Array<Array<BalanceData>>>([])
43 changes: 20 additions & 23 deletions app/src/lib/components/TransferFrom/transfer/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,34 @@ export interface ContextStore {
}

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

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

if (!chainBalances || chainBalances.length === 0) {
return {
chainId: chain.chain_id,
balances: []
}
}
return chains.map((chain, chainIndex) => {
const chainBalances = $rawBalances[chainIndex]

if (!chainBalances || chainBalances.length === 0) {
return {
chainId: chain.chain_id,
balances: chainBalances
balances: []
}
})
}
) as Readable<BalancesList>
}

return {
chainId: chain.chain_id,
balances: chainBalances
}
})
}) as Readable<BalancesList>

return derived([userAddress, balances], ([$userAddress, $balances]) => ({
chains,
userAddress: $userAddress,
balances: $balances
}))
}
}
11 changes: 4 additions & 7 deletions app/src/lib/components/TransferFrom/transfer/intents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ export function createIntentStore(
}))
})

const selectedAsset = derived(
[sourceAssets, rawIntents],
([$sourceAssets, $rawIntents]) => {
return $sourceAssets.find(x => x.metadata.denom === $rawIntents.asset) ?? null
}
)
const selectedAsset = derived([sourceAssets, rawIntents], ([$sourceAssets, $rawIntents]) => {
return $sourceAssets.find(x => x.metadata.denom === $rawIntents.asset) ?? null
})

return derived(
[sourceChain, destinationChain, selectedAsset, sourceAssets, rawIntents],
Expand All @@ -67,4 +64,4 @@ export function createIntentStore(
amount: $rawIntents.amount
})
)
}
}
15 changes: 6 additions & 9 deletions app/src/lib/components/TransferFrom/transfer/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export function createValidationStore(
// Amount validation
if ($rawIntents.amount && $intents.selectedAsset) {
try {
const parsedAmount = parseUnits($rawIntents.amount, $intents.selectedAsset.metadata.decimals ?? 0)
const parsedAmount = parseUnits(
$rawIntents.amount,
$intents.selectedAsset.metadata.decimals ?? 0
)
if (parsedAmount <= 0n) {
errors.amount = "Amount must be greater than 0"
}
Expand Down Expand Up @@ -120,13 +123,7 @@ export function createValidationStore(
([$rawIntents, $intents, $context, $errors]) => {
if (Object.keys($errors).length > 0) return undefined

if (
!(
$intents.sourceChain &&
$intents.destinationChain &&
$intents.selectedAsset
)
) {
if (!($intents.sourceChain && $intents.destinationChain && $intents.selectedAsset)) {
return undefined
}

Expand All @@ -151,4 +148,4 @@ export function createValidationStore(
? { transfer: $transfer as ValidTransfer, errors: $errors, isValid: true }
: { transfer: undefined, errors: $errors, isValid: false }
})
}
}
Loading

0 comments on commit 220b38c

Please sign in to comment.