Skip to content

Commit

Permalink
remove some components to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwishing committed Oct 28, 2024
1 parent d250651 commit 0d6d938
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 40 deletions.
3 changes: 0 additions & 3 deletions src/lib/assets/title-icon-back.svg

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="absolute right-3 top-3 text-xl font-bold">CPU</div>
<div class="absolute bottom-2 right-3">
<h5 class="h5 text-right">{cpuAvailable.toFixed(precision)} ms</h5>
<p>Usage Available</p>
<p>Available</p>
</div>
</div>
<div class="relative h-[103px] flex-1 rounded-r-lg bg-[#303338]">
Expand All @@ -29,7 +29,7 @@
<div class="absolute right-4 top-3 text-xl font-bold">NET</div>
<div class="absolute bottom-2 right-4">
<h5 class="h5 text-right">{netAvailable.toFixed(precision)} kb</h5>
<p>Usage Available</p>
<p>Available</p>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<div class="absolute right-3 top-3 text-xl font-bold">RAM</div>
<div class="absolute bottom-2 right-3">
<h5 class="h5 text-right">{ramAvailable.toFixed(precision)} kb</h5>
<p>Usage Available</p>
<p>Available</p>
</div>
</div>
4 changes: 2 additions & 2 deletions src/routes/[network]/(account)/resources/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import BackIcon from '$lib/assets/title-icon-back.svg';
import { ChevronLeft } from 'lucide-svelte';
import Stack from '$lib/components/layout/stack.svelte';
import Pageheader from '$lib/components/pageheader.svelte';
Expand Down Expand Up @@ -28,7 +28,7 @@
href="/{data.network}/resources"
class="flex size-11 items-center justify-center rounded-full bg-[#303338] text-center"
>
<img src={BackIcon} alt="BackIcon" />
<ChevronLeft class="size-7 text-skyBlue-500" />
</a>
{/if}
<Pageheader title="Resources" {subtitle} />
Expand Down
8 changes: 4 additions & 4 deletions src/routes/[network]/(account)/resources/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import CpuIcon from '$lib/assets/resources/cpu.svg';
import NetIcon from '$lib/assets/resources/net.svg';
import RamIcon from '$lib/assets/resources/ram.svg';
import CpuAndNetOverview from './components/cpunet.svelte';
import RamOverview from './components/ram.svelte';
import CpuAndNetResource from '$lib/components/elements/cpunetresource.svelte';
import RamResource from '$lib/components/elements/ramresource.svelte';
import { calAvailableSize } from './utils';
import type { UnicoveContext } from '$lib/state/client.svelte';
Expand Down Expand Up @@ -74,7 +74,7 @@
>
<Stack class="max-w-lg flex-1 gap-9">
<Stack>
<CpuAndNetOverview
<CpuAndNetResource
cpuAvailable={cpuAvailableSize}
netAvailable={netAvailableSize}
{precision}
Expand All @@ -94,7 +94,7 @@
{/if}
</Stack>
<Stack>
<RamOverview ramAvailable={ramAvailableSize} {precision} />
<RamResource ramAvailable={ramAvailableSize} {precision} />
<Button variant="secondary" href="/{network}/ram">RAM Market</Button>
</Stack>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Renting from '../components/renting.svelte';
import Renting from '../renting.svelte';
import type { UnicoveContext } from '$lib/state/client.svelte';
import { getContext } from 'svelte';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Checkbox from '$lib/components/input/checkbox.svelte';
import Button from '$lib/components/button/button.svelte';
import Transaction from '$lib/components/transaction.svelte';
import CpuAndNetOverview from './cpunet.svelte';
import CpuAndNetResource from '$lib/components/elements/cpunetresource.svelte';
import { Checksum256, type TransactResult } from '@wharfkit/session';
Expand All @@ -20,7 +20,7 @@
import { preventDefault } from '$lib/utils';
import { RentState } from './state.svelte';
import { calAvailableSize, getCpuAndNetPrice, getPowerupFrac, type RentType } from '../utils';
import { calAvailableSize, getCpuAndNetPrice, getPowerupFrac, type RentType } from './utils';
const context = getContext<UnicoveContext>('state');
const debugMode = getSetting('debug-mode', true);
Expand Down Expand Up @@ -92,7 +92,6 @@
});
const precision = 2;
//0ebca2f19920514cb7d1f31f04cbfd279788a06671dd1260b7c00a259e2e85ad
let transactionId: Checksum256 | undefined = $state();
function handleRent() {
Expand All @@ -102,7 +101,6 @@
}
try {
rentState.resetBeforeTransction();
const actions = rentState.getActions(context.network.contracts.system);
context.wharf
.transact({
Expand All @@ -113,11 +111,10 @@
resetStateAfterTrasaction();
})
.catch((error) => {
rentState.error = String(error);
console.error(error);
});
} catch (error) {
console.error(error);
alert('rex failed: ' + (error as { message: string }).message);
}
}
Expand All @@ -133,10 +130,10 @@
{/if}

<div class="mx-auto max-w-md">
<CpuAndNetOverview cpuAvailable={cpuAvailableSize} netAvailable={netAvailableSize} {precision} />
<CpuAndNetResource cpuAvailable={cpuAvailableSize} netAvailable={netAvailableSize} {precision} />
<form onsubmit={preventDefault(handleRent)}>
<Stack class="py-4 sm:p-4">
<fieldset class="grid gap-1">
<fieldset class="grid gap-2">
<Label for="cpuNumberInput"
>Amount of CPU {#if rentState.cpuPricePerMs}
(<AssetText variant="full" value={rentState.cpuPricePerMs} />/MS){/if}</Label
Expand All @@ -149,7 +146,7 @@
/>
</fieldset>

<fieldset class="grid gap-1">
<fieldset class="grid gap-2">
<Label for="netNumberInput"
>Amount of NET {#if rentState.netPricePerKb}
(<AssetText variant="full" value={rentState.netPricePerKb} />/KB){/if}</Label
Expand All @@ -168,7 +165,7 @@
</fieldset>

{#if !rentState.rentingForSelf}
<fieldset class="semi-bold grid gap-1">
<fieldset class="semi-bold grid gap-2">
<Label for="thirdReceiver">Receiving Account</Label>
<NameInput
id="thirdReceiver"
Expand Down
2 changes: 1 addition & 1 deletion src/routes/[network]/(account)/resources/rex/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Renting from '../components/renting.svelte';
import Renting from '../renting.svelte';
import type { UnicoveContext } from '$lib/state/client.svelte';
import { getContext } from 'svelte';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Renting from '../components/renting.svelte';
import Renting from '../renting.svelte';
import type { UnicoveContext } from '$lib/state/client.svelte';
import { getContext } from 'svelte';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Action, Asset, Name } from '@wharfkit/antelope';
import { ChainDefinition } from '@wharfkit/common';
import type { Contract } from '@wharfkit/contract';

import type { RentType } from '../utils';
import type { RentType } from './utils';

const defaultName = Name.from('');
const defaultSymbol = Asset.Symbol.from('0,UNKNOWN');
Expand Down Expand Up @@ -60,14 +60,6 @@ export class RentState {
public cpuFrac: number = $state(0);
public netFrac: number = $state(0);

//transaction error
public error: string = $state('');

public min: number | undefined = $derived(
this.balance ? Asset.fromUnits(1, this.balance.symbol).value : undefined
);
public max: number | undefined = $derived(this.balance ? this.balance.value : undefined);

public insufficientBalance: boolean = $derived.by(() => {
if (this.cost && this.balance) return this.cost.value > this.balance.value;
return false;
Expand Down Expand Up @@ -96,17 +88,11 @@ export class RentState {
this.netPricePerKb = undefined;
this.cpuFrac = 0;
this.netFrac = 0;
this.error = '';
}

resetBeforeTransction() {
this.error = '';
}

resetAfterTransction() {
this.cpuAmount = 0;
this.netAmount = 0;
this.error = '';
}

getActions(contract: Contract): Action[] {
Expand Down

0 comments on commit 0d6d938

Please sign in to comment.