From eb5991cb01b87b5e6c49f30ac6a4189e7b1bd2a6 Mon Sep 17 00:00:00 2001
From: dafuga
Date: Tue, 1 Oct 2024 15:43:08 -0700
Subject: [PATCH 1/5] cleanup: fixed type errors
enhancement: better wording on ram sell page
---
.../[network]/(account)/ram/buy/+layout.svelte | 2 +-
.../[network]/(account)/ram/buy/bytes/+page.svelte | 2 +-
.../[network]/(account)/ram/buy/state.svelte.ts | 14 ++++++++++----
.../(account)/ram/sell/tokens/+page.svelte | 2 +-
4 files changed, 13 insertions(+), 7 deletions(-)
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..d5812c232 100644
--- a/src/routes/[network]/(account)/ram/buy/state.svelte.ts
+++ b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
@@ -22,7 +22,10 @@ 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.bytes * this.pricePerKB.value) / 1000,
+ this.chain.systemToken?.symbol || '0,UNKNOWN'
+ )
);
public bytesToBuy: number = $derived(
@@ -32,11 +35,14 @@ export class BuyRAMState {
);
public fee: Asset = $derived(
- Asset.from(this.bytesValue.value * 0.005, this.chain.systemToken.symbol)
+ Asset.from(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)
+ Asset.fromUnits(
+ this.bytesValue.units.adding(this.fee.units),
+ this.chain.systemToken?.symbol || '0,UNKNOWN'
+ )
);
public valid: boolean = $derived(
@@ -61,7 +67,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() {
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 @@
Price for 1000 bytes:
{sellRamState.pricePerKB} / KB
- Estimated RAM to be sold:
+ RAM to be sold:
{sellRamState.bytesToSell} Bytes
RAM Value:
{sellRamState.tokens}
From 43ff72664c0d84458ecde7c1fe274e08fc4d6e3b Mon Sep 17 00:00:00 2001
From: dafuga
Date: Tue, 1 Oct 2024 16:03:52 -0700
Subject: [PATCH 2/5] fix: fixed the fee calculation on ram buy page
---
src/routes/[network]/(account)/ram/buy/state.svelte.ts | 2 +-
src/routes/[network]/(account)/ram/buy/tokens/+page.svelte | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/routes/[network]/(account)/ram/buy/state.svelte.ts b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
index d5812c232..8d222546a 100644
--- a/src/routes/[network]/(account)/ram/buy/state.svelte.ts
+++ b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
@@ -75,7 +75,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}
From 07938d99f545b211ebaa0e1cf2d6d9f16ea6a43b Mon Sep 17 00:00:00 2001
From: dafuga
Date: Tue, 1 Oct 2024 16:26:48 -0700
Subject: [PATCH 3/5] fix: using input amount for total ram purchase cost
---
.../(account)/ram/buy/state.svelte.ts | 24 ++++++++++++++-----
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/routes/[network]/(account)/ram/buy/state.svelte.ts b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
index 8d222546a..7457ebe92 100644
--- a/src/routes/[network]/(account)/ram/buy/state.svelte.ts
+++ b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
@@ -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'
@@ -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(
@@ -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;
From 9fd463cde160dd001d87413c250a351007016e0a Mon Sep 17 00:00:00 2001
From: dafuga
Date: Tue, 1 Oct 2024 16:30:18 -0700
Subject: [PATCH 4/5] cleanup: removed expectedToReceive getter
---
src/routes/[network]/(account)/ram/buy/state.svelte.ts | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/routes/[network]/(account)/ram/buy/state.svelte.ts b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
index 7457ebe92..632c3e0aa 100644
--- a/src/routes/[network]/(account)/ram/buy/state.svelte.ts
+++ b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
@@ -64,13 +64,6 @@ 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;
From 4dcc4fa36da0b12bcfc72d4bb9ced7f76b950ea0 Mon Sep 17 00:00:00 2001
From: dafuga
Date: Tue, 1 Oct 2024 16:51:43 -0700
Subject: [PATCH 5/5] fix: buying proper bytes amount
---
src/routes/[network]/(account)/ram/buy/state.svelte.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/routes/[network]/(account)/ram/buy/state.svelte.ts b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
index 632c3e0aa..d4d429da2 100644
--- a/src/routes/[network]/(account)/ram/buy/state.svelte.ts
+++ b/src/routes/[network]/(account)/ram/buy/state.svelte.ts
@@ -29,7 +29,7 @@ export class BuyRAMState {
);
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))
);