Skip to content

Commit

Permalink
format resurces.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwishing committed Oct 2, 2024
1 parent 127efe0 commit ed1b51f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/pages/resources/resources.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { derived, Readable } from 'svelte/store'
import { Int64, API, Asset } from '@greymass/eosio'
import { Resources, SampleUsage, PowerUpState, RAMState, REXState } from '@greymass/eosio-resources'
import { activeBlockchain } from '~/store'
import { BNPrecision } from '@greymass/eosio-resources'
import {derived, Readable} from 'svelte/store'
import {API, Asset} from '@greymass/eosio'
import {Resources, SampleUsage, PowerUpState, RAMState, REXState, BNPrecision} from '@greymass/eosio-resources'
import {activeBlockchain} from '~/store'

import { getClient } from '../../api-client'
import { ChainConfig, ChainFeatures, resourceFeatures } from '~/config'
import {getClient} from '../../api-client'
import {ChainConfig, ChainFeatures, resourceFeatures} from '~/config'

const getResourceClient = (chain: ChainConfig) => {
const api = getClient(chain)
const options: any = { api }
const options: any = {api}
if (chain.resourceSampleAccount) {
options.sampleAccount = chain.resourceSampleAccount
}
Expand Down Expand Up @@ -113,7 +112,7 @@ export const cpuPowerupPrice = derived(

// price per kb
export const netPowerupPrice = derived(
[activeBlockchain,sampleUsage, statePowerUp, info],
[activeBlockchain, sampleUsage, statePowerUp, info],
([$activeBlockchain, $sampleUsage, $statePowerUp, $info]) => {
if ($sampleUsage && $statePowerUp) {
return Asset.from(
Expand All @@ -130,7 +129,7 @@ export const cpuStakingPrice = derived(
[activeBlockchain, msToRent, sampleUsage],
([$activeBlockchain, $msToRent, $sampleUsage]) => {
if ($msToRent && $sampleUsage) {
const { account } = $sampleUsage
const {account} = $sampleUsage
const cpu_weight = Number(account.total_resources.cpu_weight.units)
const cpu_limit = Number(account.cpu_limit.max.value)
let price = (cpu_weight / cpu_limit) * $msToRent
Expand All @@ -145,7 +144,7 @@ export const netStakingPrice = derived(
[activeBlockchain, sampleUsage],
([$activeBlockchain, $sampleUsage]) => {
if ($sampleUsage) {
const { account } = $sampleUsage
const {account} = $sampleUsage
const net_weight = Number(account.total_resources.net_weight.units)
const net_limit = Number(account.net_limit.max.value)
let price = net_weight / net_limit
Expand Down Expand Up @@ -206,9 +205,9 @@ export const netRexPrice = derived(
}
)

function compatPriceWithPrecision(price : number, coreTokenSymbol : Asset.Symbol){
function compatPriceWithPrecision(price: number, coreTokenSymbol: Asset.Symbol) {
let precision = coreTokenSymbol.precision;
if (price > 0 && price < 1/Math.pow(10, precision)) {
if (price > 0 && price < 1 / Math.pow(10, precision)) {
precision = Number(price.toExponential().split('-')[1])
}
return Asset.from(price, `${precision},${coreTokenSymbol.name}`)
Expand Down

0 comments on commit ed1b51f

Please sign in to comment.