diff --git a/src/routes/[network]/(account)/ram/buy/+layout.svelte b/src/routes/[network]/(account)/ram/buy/+layout.svelte index dbc697ea9..eba36899f 100644 --- a/src/routes/[network]/(account)/ram/buy/+layout.svelte +++ b/src/routes/[network]/(account)/ram/buy/+layout.svelte @@ -10,7 +10,7 @@ return [ { href: `/${network}/ram/buy/tokens`, - text: String(data.network.chain.systemToken.symbol.code) + text: String(data.network.chain.systemToken?.symbol.code || '') }, { href: `/${network}/ram/buy/bytes`, text: 'Bytes' } ]; diff --git a/src/routes/[network]/(account)/ram/buy/bytes/+page.svelte b/src/routes/[network]/(account)/ram/buy/bytes/+page.svelte index bf0b20994..cbabea856 100644 --- a/src/routes/[network]/(account)/ram/buy/bytes/+page.svelte +++ b/src/routes/[network]/(account)/ram/buy/bytes/+page.svelte @@ -94,7 +94,7 @@ {#if context.account} {context.account.balance?.liquid} {:else} - 0.0000 {data.network.chain.systemToken.symbol.code} + 0.0000 {data.network.chain.systemToken?.symbol.code || ''} {/if}
diff --git a/src/routes/[network]/(account)/ram/buy/state.svelte.ts b/src/routes/[network]/(account)/ram/buy/state.svelte.ts index 09365c0ce..d4d429da2 100644 --- a/src/routes/[network]/(account)/ram/buy/state.svelte.ts +++ b/src/routes/[network]/(account)/ram/buy/state.svelte.ts @@ -21,22 +21,33 @@ export class BuyRAMState { public bytesValue: Asset = $derived( this.format === 'asset' || !this.bytes || !this.pricePerKB.value - ? this.tokens - : Asset.from((this.bytes * this.pricePerKB.value) / 1000, this.chain.systemToken.symbol) + ? 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' + ) ); public bytesToBuy: number = $derived( - this.bytes || !this.bytesValue.value || !this.pricePerKB.value + this.format === 'units' || !this.bytesValue.value || !this.pricePerKB.value ? this.bytes || 0 : Number(((this.bytesValue.value / this.pricePerKB.value) * 1000).toFixed(0)) ); public fee: Asset = $derived( - Asset.from(this.bytesValue.value * 0.005, this.chain.systemToken.symbol) + 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) + this.format === 'asset' + ? this.tokens + : Asset.fromUnits( + this.bytesValue.units.adding(this.fee.units), + this.chain.systemToken?.symbol || '0,UNKNOWN' + ) ); public valid: boolean = $derived( @@ -61,7 +72,7 @@ export class BuyRAMState { reset() { this.bytes = undefined; - this.tokens = Asset.fromUnits(0, this.chain.systemToken.symbol); + this.tokens = Asset.fromUnits(0, this.chain.systemToken?.symbol || '0,UNKNOWN'); } toJSON() { @@ -69,7 +80,7 @@ export class BuyRAMState { return Serializer.objectify({ payer: this.payer, receiver: this.receiver, - quant: this.bytesValue + quant: this.bytesCost }); } else { return Serializer.objectify({ diff --git a/src/routes/[network]/(account)/ram/buy/tokens/+page.svelte b/src/routes/[network]/(account)/ram/buy/tokens/+page.svelte index 052350043..e1394eaa9 100644 --- a/src/routes/[network]/(account)/ram/buy/tokens/+page.svelte +++ b/src/routes/[network]/(account)/ram/buy/tokens/+page.svelte @@ -93,7 +93,7 @@ {#if context.account} {context.account.balance?.liquid} {:else} - 0.0000 {data.network.chain.systemToken.symbol.code} + 0.0000 {data.network.chain.systemToken?.symbol.code || ''} {/if} diff --git a/src/routes/[network]/(account)/ram/sell/tokens/+page.svelte b/src/routes/[network]/(account)/ram/sell/tokens/+page.svelte index c9450a339..667efb0dd 100644 --- a/src/routes/[network]/(account)/ram/sell/tokens/+page.svelte +++ b/src/routes/[network]/(account)/ram/sell/tokens/+page.svelte @@ -105,7 +105,7 @@