Skip to content

Commit

Permalink
fix: fixing type errors related to chain.systemToken being undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Sep 18, 2024
1 parent 900c414 commit 518aa6b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/routes/[network]/(account)/ram/buy/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
];
Expand Down
2 changes: 1 addition & 1 deletion src/routes/[network]/(account)/ram/buy/bytes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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}
</p>
</Stack>
Expand Down
14 changes: 10 additions & 4 deletions src/routes/[network]/(account)/ram/buy/state.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || defaultSymbol
)
);

public bytesToBuy: number = $derived(
Expand All @@ -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 || defaultSymbol)
);

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 || defaultSymbol
)
);

public valid: boolean = $derived(
Expand All @@ -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 || defaultSymbol);
}

toJSON() {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/[network]/(account)/ram/sell/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return [
{
href: `/${network}/ram/sell/tokens`,
text: String(data.network.chain.systemToken.symbol.code)
text: String(data.network.chain.systemToken?.symbol.code)
},
{ href: `/${network}/ram/sell/bytes`, text: 'Bytes' }
];
Expand Down
11 changes: 7 additions & 4 deletions src/routes/[network]/(account)/ram/sell/state.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ export class SellRAMState {

public bytesValue: Asset = $derived(
this.format === 'units' && this.bytes !== undefined
? Asset.from((this.bytes * this.pricePerKB.value) / 1000, this.chain.systemToken.symbol)
? Asset.from(
(this.bytes * this.pricePerKB.value) / 1000,
this.chain.systemToken?.symbol || defaultSymbol
)
: this.tokens
);

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 || defaultSymbol)
);

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

Expand Down Expand Up @@ -70,7 +73,7 @@ export class SellRAMState {

reset() {
this.bytes = undefined;
this.tokens = Asset.fromUnits(0, this.chain.systemToken.symbol);
this.tokens = Asset.fromUnits(0, this.chain.systemToken?.symbol || defaultSymbol);
}

toJSON() {
Expand Down

0 comments on commit 518aa6b

Please sign in to comment.