Skip to content

Commit

Permalink
fix: using input amount for total ram purchase cost
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Oct 1, 2024
1 parent 43ff726 commit 07938d9
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/routes/[network]/(account)/ram/buy/state.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BuyRAMState {

public bytesValue: Asset = $derived(
this.format === 'asset' || !this.bytes || !this.pricePerKB.value
? this.tokens
? Asset.from(this.tokens.value * 0.995, this.chain.systemToken?.symbol || '0,UNKNOWN')
: Asset.from(
(this.bytes * this.pricePerKB.value) / 1000,
this.chain.systemToken?.symbol || '0,UNKNOWN'
Expand All @@ -35,14 +35,19 @@ export class BuyRAMState {
);

public fee: Asset = $derived(
Asset.from(this.bytesValue.value * 0.005, this.chain.systemToken?.symbol || '0,UNKNOWN')
Asset.from(
(this.format === 'asset' ? this.tokens.value : this.bytesValue.value) * 0.005,
this.chain.systemToken?.symbol || '0,UNKNOWN'
)
);

public bytesCost: Asset = $derived(
Asset.fromUnits(
this.bytesValue.units.adding(this.fee.units),
this.chain.systemToken?.symbol || '0,UNKNOWN'
)
this.format === 'asset'
? this.tokens
: Asset.fromUnits(
this.bytesValue.units.adding(this.fee.units),
this.chain.systemToken?.symbol || '0,UNKNOWN'
)
);

public valid: boolean = $derived(
Expand All @@ -59,6 +64,13 @@ export class BuyRAMState {
!!this.balance.value && this.bytesValue.value > this.balance.value
);

public expectedToReceive: Asset = $derived(
Asset.fromUnits(
this.bytesValue.units.subtracting(this.fee.units),
this.chain.systemToken?.symbol || '0,UNKNOWN'
)
);

constructor(chain: ChainDefinition) {
this.chain = chain;

Expand Down

0 comments on commit 07938d9

Please sign in to comment.