diff --git a/src/pages/resources/components/forms/powerup.svelte b/src/pages/resources/components/forms/powerup.svelte index f9b77a9c..f0d9953e 100644 --- a/src/pages/resources/components/forms/powerup.svelte +++ b/src/pages/resources/components/forms/powerup.svelte @@ -9,7 +9,7 @@ import {activeBlockchain, activeSession, currentAccount} from '~/store' import {systemToken} from '~/stores/tokens' import {systemTokenBalance} from '~/stores/balances' - import {powerupPrice, sampleUsage, statePowerUp} from '~/pages/resources/resources' + import {cpuPowerupPrice, netPowerupPrice, sampleUsage, statePowerUp} from '~/pages/resources/resources' import type {FormTransaction} from '~/ui-types' import Button from '~/components/elements/button.svelte' @@ -23,6 +23,7 @@ export let resource: string = 'cpu' const unit = resource === 'cpu' ? 'ms' : 'kb' + const powerupPrice = resource === 'cpu' ? cpuPowerupPrice : netPowerupPrice let amount: Writable = writable('') let error: string | undefined @@ -33,7 +34,6 @@ [activeBlockchain, amount, powerupPrice], ([$activeBlockchain, $amount, $powerupPrice]) => { if ($activeBlockchain && $powerupPrice) { - return Asset.from( Number($powerupPrice.value) * Number($amount), $activeBlockchain.coreTokenSymbol diff --git a/src/pages/resources/components/state/prices.svelte b/src/pages/resources/components/state/prices.svelte index fd517a10..8263d7ff 100644 --- a/src/pages/resources/components/state/prices.svelte +++ b/src/pages/resources/components/state/prices.svelte @@ -5,7 +5,7 @@ import {ChainFeatures} from '~/config' import {activeBlockchain} from '~/store' - import {powerupPrice, rexPrice, stakingPrice} from '~/pages/resources/resources' + import {cpuPowerupPrice, netPowerupPrice, rexPrice, cpuStakingPrice, netStakingPrice} from '~/pages/resources/resources' import Button from '~/components/elements/button.svelte' import Segment from '~/components/elements/segment.svelte' @@ -13,6 +13,8 @@ export let resource = 'cpu' const unit = resource === 'cpu' ? 'ms' : 'kb' + const powerupPrice = resource === 'cpu' ? cpuPowerupPrice : netPowerupPrice + const stakingPrice = resource === 'cpu' ? cpuStakingPrice : netStakingPrice const {PowerUp, REX, Staking} = ChainFeatures @@ -156,9 +158,7 @@
Staking
- {(Number($stakingPrice.value) * 1000).toFixed( - $stakingPrice.symbol.precision - )} + {$stakingPrice.value.toFixed($stakingPrice.symbol.precision)}
{$token} per diff --git a/src/pages/resources/resources.ts b/src/pages/resources/resources.ts index 56b8a935..2cc8d7cd 100644 --- a/src/pages/resources/resources.ts +++ b/src/pages/resources/resources.ts @@ -96,7 +96,8 @@ export const msToRent: Readable = derived(activeBlockchain, ($activeBloc return 1 }) -export const powerupPrice = derived( +//price per ms +export const cpuPowerupPrice = derived( [msToRent, sampleUsage, statePowerUp, info], ([$msToRent, $sampleUsage, $statePowerUp, $info]) => { if ($msToRent && $sampleUsage && $statePowerUp) { @@ -109,7 +110,20 @@ export const powerupPrice = derived( } ) -export const stakingPrice = derived( +// price per kb +export const netPowerupPrice = derived( + [msToRent, sampleUsage, statePowerUp, info], + ([$msToRent, $sampleUsage, $statePowerUp, $info]) => { + if ($msToRent && $sampleUsage && $statePowerUp) { + const price = $statePowerUp.net.price_per_kb($sampleUsage, $msToRent, $info) + return Asset.from(price, '4,EOS') + } + return Asset.from(0, '4,EOS') + } +) + +//price per ms +export const cpuStakingPrice = derived( [activeBlockchain, msToRent, sampleUsage], ([$activeBlockchain, $msToRent, $sampleUsage]) => { if ($msToRent && $sampleUsage) { @@ -120,7 +134,22 @@ export const stakingPrice = derived( if ($activeBlockchain.resourceSampleMilliseconds) { price *= $activeBlockchain.resourceSampleMilliseconds } - return Asset.fromUnits(price, $activeBlockchain.coreTokenSymbol) + return Asset.fromUnits(price * 1000, $activeBlockchain.coreTokenSymbol) + } + return Asset.from(0, $activeBlockchain.coreTokenSymbol) + } +) + +// price per kb +export const netStakingPrice = derived( + [activeBlockchain, msToRent, sampleUsage], + ([$activeBlockchain, $msToRent, $sampleUsage]) => { + if ($msToRent && $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 + return Asset.fromUnits(price * 1000, $activeBlockchain.coreTokenSymbol) } return Asset.from(0, $activeBlockchain.coreTokenSymbol) }