From 56d6ba14e7f02c4d7ea351c80fd41e01f2c6f112 Mon Sep 17 00:00:00 2001 From: kurt Date: Tue, 15 Oct 2024 18:53:49 +0800 Subject: [PATCH] code formatting --- src/lib/state/network.svelte.ts | 19 ++++++++----------- src/lib/types.ts | 4 ++-- .../resources/components/forms/powerup.svelte | 6 +++--- .../resources/components/forms/rex.svelte | 4 ++-- .../resources/components/forms/staking.svelte | 12 ++++++------ .../resources/components/state/prices.svelte | 8 ++++---- .../[network]/(account)/resources/utils.ts | 17 +++++++---------- 7 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/lib/state/network.svelte.ts b/src/lib/state/network.svelte.ts index 2ca09b449..1c13b99aa 100644 --- a/src/lib/state/network.svelte.ts +++ b/src/lib/state/network.svelte.ts @@ -1,11 +1,4 @@ -import { - APIClient, - Asset, - FetchProvider, - Int128, - Serializer, - type AssetType -} from '@wharfkit/antelope'; +import { APIClient, Asset, FetchProvider, Int128, type AssetType } from '@wharfkit/antelope'; import { Chains, ChainDefinition, TokenMeta } from '@wharfkit/common'; import { RAMState, Resources, REXState, PowerUpState, type SampleUsage } from '@wharfkit/resources'; import { chainIdsToIndices } from '@wharfkit/session'; @@ -44,7 +37,7 @@ export class NetworkState { public resources?: Resources = $state(); public rexstate?: REXState = $state(); public powerupstate?: PowerUpState = $state(); - public sampledUsage?: SampledUsage = $state(); + public sampleUsage?: SampleUsage = $state(); public tokenmeta?: TokenMeta[] = $state(); public tokenstate?: DelphiOracleTypes.datapoints = $state(); public tokenprice = $derived.by(() => { @@ -114,8 +107,12 @@ export class NetworkState { } try { - console.log("#####", json.sampleUsage); - this.sampledUsage = SampledUsage.from(json.sampleUsage); + const sampledUsage = SampledUsage.from(json.sampleUsage); + this.sampleUsage = { + account: sampledUsage.account, + cpu: sampledUsage.cpu, + net: sampledUsage.net + }; } catch (error) { console.log('SampleUsage Parse', error); console.log(json); diff --git a/src/lib/types.ts b/src/lib/types.ts index 31251c583..033436b28 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -56,6 +56,6 @@ export interface LightAPIBalanceResponse { @Struct.type('sampledusage') export class SampledUsage extends Struct { @Struct.field(API.v1.AccountObject) declare account: API.v1.AccountObject; - @Struct.field(UInt128) declare cpu: UInt128; - @Struct.field(UInt128) declare net: UInt128; + @Struct.field(UInt128) declare cpu: UInt128; + @Struct.field(UInt128) declare net: UInt128; } diff --git a/src/routes/[network]/(account)/resources/components/forms/powerup.svelte b/src/routes/[network]/(account)/resources/components/forms/powerup.svelte index cec2d2309..37f7165bb 100644 --- a/src/routes/[network]/(account)/resources/components/forms/powerup.svelte +++ b/src/routes/[network]/(account)/resources/components/forms/powerup.svelte @@ -34,20 +34,20 @@ } if ( context.network.powerupstate && - context.network.sampledUsage && + context.network.sampleUsage && context.network.chain.systemToken ) { rentState.frac = getPowerupFrac( resourceType, context.network.powerupstate, - context.network.sampledUsage, + context.network.sampleUsage, Number(rentState.amount) ); rentState.pricePerUnit = getPowerupPrice( resourceType, context.network.powerupstate, - context.network.sampledUsage, + context.network.sampleUsage, context.network.chain.systemToken.symbol ); } diff --git a/src/routes/[network]/(account)/resources/components/forms/rex.svelte b/src/routes/[network]/(account)/resources/components/forms/rex.svelte index 094c038a4..a4eac6dc3 100644 --- a/src/routes/[network]/(account)/resources/components/forms/rex.svelte +++ b/src/routes/[network]/(account)/resources/components/forms/rex.svelte @@ -28,13 +28,13 @@ rentState.balance = context.account.balance ? context.account.balance.liquid : undefined; if ( context.network.rexstate && - context.network.sampledUsage && + context.network.sampleUsage && context.network.chain.systemToken ) { rentState.pricePerUnit = getRexPrice( resourceType, context.network.rexstate, - context.network.sampledUsage, + context.network.sampleUsage, context.network.chain.systemToken.symbol ); } diff --git a/src/routes/[network]/(account)/resources/components/forms/staking.svelte b/src/routes/[network]/(account)/resources/components/forms/staking.svelte index bfde80375..73b07f4ae 100644 --- a/src/routes/[network]/(account)/resources/components/forms/staking.svelte +++ b/src/routes/[network]/(account)/resources/components/forms/staking.svelte @@ -5,7 +5,7 @@ import Stack from '$lib/components/layout/stack.svelte'; import Transaction from '$lib/components/transaction.svelte'; - import { Checksum256, Asset } from '@wharfkit/antelope'; + import { Checksum256 } from '@wharfkit/antelope'; import type { TransactResult } from '@wharfkit/session'; import { RentState } from './state.svelte'; @@ -24,7 +24,7 @@ if ( context.account && context.network && - context.network.sampledUsage && + context.network.sampleUsage && context.network.chain.systemToken ) { if (context.account.name) { @@ -34,7 +34,7 @@ rentState.balance = context.account.balance ? context.account.balance.liquid : undefined; rentState.pricePerUnit = getStakingPrice( resourceType, - context.network.sampledUsage, + context.network.sampleUsage, context.network.chain.systemToken.symbol ); } else { @@ -128,9 +128,9 @@

{/if} {#if rentState.pricePerUnit} -

- Price:{rentState.pricePerUnit} -

+

+ Price:{rentState.pricePerUnit} +

{/if} {#if rentState.error} diff --git a/src/routes/[network]/(account)/resources/components/state/prices.svelte b/src/routes/[network]/(account)/resources/components/state/prices.svelte index 700165b3d..646b0b37b 100644 --- a/src/routes/[network]/(account)/resources/components/state/prices.svelte +++ b/src/routes/[network]/(account)/resources/components/state/prices.svelte @@ -27,12 +27,12 @@ let stakingPrice: Asset | undefined = $state(); $effect(() => { - if (context.network && context.network.sampledUsage && context.network.chain.systemToken) { + if (context.network && context.network.sampleUsage && context.network.chain.systemToken) { powerupPrice = context.network.powerupstate ? getPowerupPrice( resource, context.network.powerupstate, - context.network.sampledUsage, + context.network.sampleUsage, context.network.chain.systemToken.symbol ) : undefined; @@ -40,13 +40,13 @@ ? getRexPrice( resource, context.network.rexstate, - context.network.sampledUsage, + context.network.sampleUsage, context.network.chain.systemToken.symbol ) : undefined; stakingPrice = getStakingPrice( resource, - context.network.sampledUsage, + context.network.sampleUsage, context.network.chain.systemToken.symbol ); } else { diff --git a/src/routes/[network]/(account)/resources/utils.ts b/src/routes/[network]/(account)/resources/utils.ts index 7bd8a744a..accc3f191 100644 --- a/src/routes/[network]/(account)/resources/utils.ts +++ b/src/routes/[network]/(account)/resources/utils.ts @@ -1,10 +1,7 @@ import { ResourceType } from './types'; import { PowerUpState } from '@wharfkit/resources'; -import type { REXState } from '@wharfkit/resources'; +import type { REXState, SampleUsage } from '@wharfkit/resources'; import { Asset } from '@wharfkit/antelope'; -import { SampledUsage } from '$lib/types'; -import { UInt128 } from '@wharfkit/antelope'; -import BN from 'bn.js'; export const calSize = (available: number) => { let size = 0; @@ -51,7 +48,7 @@ export const getUnit = (resourceType: ResourceType) => { export const getPowerupPrice = ( resourceType: ResourceType, powerupstate: PowerUpState, - sampleUsage: SampledUsage, + sampleUsage: SampleUsage, systemTokenSymbol: Asset.Symbol ) => { switch (resourceType) { @@ -69,17 +66,17 @@ export const getPowerupPrice = ( export const getRexPrice = ( resourceType: ResourceType, rexState: REXState, - sampledUsage: SampledUsage, + sampledUsage: SampleUsage, systemTokenSymbol: Asset.Symbol ) => { switch (resourceType) { case ResourceType.NET: const netPrice = rexState.net_price_per_kb(sampledUsage, 30); - console.log("netPrice = ", netPrice); + console.log('netPrice = ', netPrice); return compatPriceWithPrecision(netPrice, systemTokenSymbol); case ResourceType.CPU: const cpuPrice = rexState.cpu_price_per_ms(sampledUsage, 30); - console.log("cpuPrice = ", cpuPrice); + console.log('cpuPrice = ', cpuPrice); return compatPriceWithPrecision(cpuPrice, systemTokenSymbol); default: throw new Error(`unsupport resource type: ${resourceType}`); @@ -96,7 +93,7 @@ function compatPriceWithPrecision(price: number, coreTokenSymbol: Asset.Symbol) export const getStakingPrice = ( resourceType: ResourceType, - sampledUsage: SampledUsage, + sampledUsage: SampleUsage, systemTokenSymbol: Asset.Symbol ) => { const { account } = sampledUsage; @@ -115,7 +112,7 @@ export const getStakingPrice = ( export const getPowerupFrac = ( resourceType: ResourceType, powerupstate: PowerUpState, - sampledUsage: SampledUsage, + sampledUsage: SampleUsage, amount: number ) => { switch (resourceType) {