Skip to content

Commit

Permalink
refactor coding
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwishing committed Oct 10, 2024
1 parent 1e0052d commit ad06286
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 36 deletions.
7 changes: 4 additions & 3 deletions src/lib/components/overview/balances.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script lang="ts">
import Switcher from '$lib/components/layout/switcher.svelte';
import Card from '$lib/components/layout/box/card.svelte';
import Stack from '$lib/components/layout/stack.svelte';
import { Asset } from '@wharfkit/antelope';
import Switcher from '../layout/switcher.svelte';
import Card from '../layout/box/card.svelte';
import Stack from '../layout/stack.svelte';
import type { TokenMeta } from '@wharfkit/common';
interface Props {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/overview/resource.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import CircleProgress from '$lib/components/circleprogress.svelte';
import Card from '$lib/components/layout/box/card.svelte';
import Stack from '$lib/components/layout/stack.svelte';
import type { Snippet } from 'svelte';
import type { Resource } from '@wharfkit/account';
import Card from '../layout/box/card.svelte';
import Stack from '../layout/stack.svelte';
interface Props {
children?: Snippet;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/overview/resources.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import type { Resource } from '@wharfkit/account';
import Grid from '../layout/grid.svelte';
import ResourceCard from './resource.svelte';
import type { NetworkState } from '$lib/state/network.svelte';
import Button from '../button/button.svelte';
import type { Snippet } from 'svelte';
import Grid from '$lib/components/layout/grid.svelte';
import ResourceCard from './resource.svelte';
import type { Resource } from '@wharfkit/account';
interface Props {
ramIntent?: Snippet;
cpuIntent?: Snippet;
Expand Down
1 change: 0 additions & 1 deletion src/lib/components/overview/tokens.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { Asset } from '@wharfkit/antelope';
import type { Snippet } from 'svelte';
import type { TokenBalance } from '@wharfkit/common';
Expand Down
4 changes: 2 additions & 2 deletions src/routes/[network]/(account)/accounts/[name]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
let totalTokenValue: Asset | undefined = $derived(context.account?.balance?.total);
let totalUsdValue: Asset | undefined = $derived(context.account?.value?.total);
let systemTokenMeta: TokenMeta | undefined = $derived.by(() => {
let systemTokenBlanace: TokenBalance | undefined = undefined;
let systemTokenBlanace: TokenBalance | undefined;
if (totalTokenValue) {
systemTokenBlanace = tokenBalances.find((item) =>
item.asset.symbol.equals(totalTokenValue!.symbol)
item.asset.symbol.equals(totalTokenValue.symbol)
);
}
return systemTokenBlanace?.metadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<script lang="ts">
import { getContext } from 'svelte';
import type { UnicoveContext } from '$lib/state/client.svelte';
import type { ActivityAction } from '$lib/types';
import type { Asset } from '@wharfkit/antelope';
import Button from '$lib/components/button/button.svelte';
const { data } = $props();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { getContext } from 'svelte';
import type { UnicoveContext } from '$lib/state/client.svelte';
import Stack from '$lib/components/layout/stack.svelte';
import TokenTable from '$lib/components/overview/tokens.svelte';
import BalanceCard from '$lib/components/overview/balances.svelte';
Expand All @@ -12,31 +13,20 @@
const { data } = $props();
const context = getContext<UnicoveContext>('state');
let totalTokenValue: Asset | undefined = $state();
let totalUsdValue: Asset | undefined = $state();
let systemTokenMeta: TokenMeta | undefined = $state();
let tokenBalances: TokenBalance[] = $state([]);
$effect(() => {
totalTokenValue = context.account?.balance?.total || undefined;
totalUsdValue = context.account?.value?.total || undefined;
if (context.account?.balances) {
tokenBalances = context.account.balances;
} else {
tokenBalances = [];
}
let systemTokenBlanace: TokenBalance | undefined = undefined;
let totalTokenValue: Asset | undefined = $derived(context.account?.balance?.total);
let totalUsdValue: Asset | undefined = $derived(context.account?.value?.total);
let systemTokenMeta: TokenMeta | undefined = $derived.by(() => {
let systemTokenBlanace: TokenBalance | undefined;
if (totalTokenValue) {
systemTokenBlanace = tokenBalances.find((item) =>
item.asset.symbol.equals(totalTokenValue!.symbol)
item.asset.symbol.equals(totalTokenValue.symbol)
);
}
systemTokenMeta = systemTokenBlanace?.metadata;
return systemTokenBlanace?.metadata;
});
let tokenBalances: TokenBalance[] = $derived(context.account?.balances || []);
const network = $derived(String(data.network));
</script>

Expand Down

0 comments on commit ad06286

Please sign in to comment.