Skip to content

Commit

Permalink
Reworked resources
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Feb 23, 2025
1 parent 2af3530 commit e50358c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/elements/resourceCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<p class="*:block">
<span class="font-semibold text-white">
<NumberFormat number={props.value} />
<NumberFormat number={props.value.dividing(1000)} />
{unit}
</span>
<span>{m.common_available()}</span>
Expand Down
1 change: 0 additions & 1 deletion src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Asset, type NameType } from '@wharfkit/antelope';

export * from './strings';
export * from './ricardian';
export * from './resources';
export * from './style';

export function calculateValue(balance: Asset, currency: Asset): Asset {
Expand Down
8 changes: 0 additions & 8 deletions src/lib/utils/resources.ts

This file was deleted.

51 changes: 25 additions & 26 deletions src/routes/[network]/(account)/ram/(forms)/buy/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { getContext } from 'svelte';
import { Checksum256 } from '@wharfkit/antelope';
import { Checksum256, Int64 } from '@wharfkit/antelope';
import type { UnicoveContext } from '$lib/state/client.svelte';
Expand All @@ -20,7 +20,7 @@
import * as m from '$lib/paraglide/messages';
import { BuyRAMState } from './state.svelte';
import { calAvailableSize, preventDefault } from '$lib/utils';
import { preventDefault } from '$lib/utils';
import { DD, DL, DLRow } from '$lib/components/descriptionlist';
let bytesInput: BytesInput | undefined = $state();
Expand All @@ -30,7 +30,7 @@
const { data } = $props();
const buyRamState: BuyRAMState = $state(new BuyRAMState(data.network.chain));
const ramAvailableSize = $derived(calAvailableSize(context.account?.resources.ram));
const ramAvailableSize = $derived(context.account?.resources.ram.available || Int64.from(0));
let transactionId: Checksum256 | undefined = $state();
let errorMessage: string | undefined = $state();
Expand Down Expand Up @@ -199,27 +199,26 @@
</Stack>
</form>
{/if}
{#if context.settings.data.debugMode}
<h3 class="h3">{m.common_debugging()}</h3>
<Code
>{JSON.stringify(
{
payer: buyRamState.payer,
receiver: buyRamState.receiver,
bytes: buyRamState.bytes,
balance: buyRamState.balance,
chain: buyRamState.chain,
pricePerKB: buyRamState.pricePerKB,
pricePerByte: buyRamState.pricePerByte,
bytesValue: buyRamState.bytesValue,
valid: buyRamState.valid,
insufficientBalance: buyRamState.insufficientBalance,
balances: context.account?.balances
},
undefined,
2
)}</Code
>
{/if}
</Stack>

{#if context.settings.data.debugMode}
<h3 class="h3">{m.common_debugging()}</h3>
<Code
>{JSON.stringify(
{
payer: buyRamState.payer,
receiver: buyRamState.receiver,
bytes: buyRamState.bytes,
balance: buyRamState.balance,
chain: buyRamState.chain,
pricePerKB: buyRamState.pricePerKB,
pricePerByte: buyRamState.pricePerByte,
bytesValue: buyRamState.bytesValue,
valid: buyRamState.valid,
insufficientBalance: buyRamState.insufficientBalance,
balances: context.account?.balances
},
undefined,
2
)}</Code
>
{/if}
48 changes: 24 additions & 24 deletions src/routes/[network]/(account)/ram/(forms)/sell/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { getContext } from 'svelte';
import { Checksum256 } from '@wharfkit/antelope';
import { Checksum256, Int64 } from '@wharfkit/antelope';
import type { UnicoveContext } from '$lib/state/client.svelte';
Expand All @@ -19,7 +19,7 @@
import * as m from '$lib/paraglide/messages';
import { SellRAMState } from './state.svelte';
import { calAvailableSize, preventDefault } from '$lib/utils';
import { preventDefault } from '$lib/utils';
import { DD, DL, DLRow } from '$lib/components/descriptionlist';
let bytesInput: BytesInput | undefined = $state();
Expand All @@ -29,7 +29,7 @@
const { data } = $props();
const sellRamState: SellRAMState = $state(new SellRAMState(data.network.chain));
const ramAvailableSize = $derived(calAvailableSize(context.account?.resources.ram));
const ramAvailableSize = $derived(context.account?.resources.ram.available || Int64.from(0));
let transactionId: Checksum256 | undefined = $state();
let errorMessage: string | undefined = $state();
Expand Down Expand Up @@ -182,25 +182,25 @@
</Stack>
</form>
{/if}
</Stack>

{#if context.settings.data.debugMode}
<h3 class="h3">{m.common_debugging()}</h3>
<Code
>{JSON.stringify(
{
account: sellRamState.account,
bytes: sellRamState.bytes,
max: sellRamState.max,
chain: sellRamState.chain,
pricePerKB: sellRamState.pricePerKB,
bytesValue: sellRamState.bytesValue,
insufficientRAM: sellRamState.insufficientRAM,
valid: sellRamState.valid,
balances: context.account?.balances
},
undefined,
2
)}</Code
>
{/if}
{#if context.settings.data.debugMode}
<h3 class="h3">{m.common_debugging()}</h3>
<Code
>{JSON.stringify(
{
account: sellRamState.account,
bytes: sellRamState.bytes,
max: sellRamState.max,
chain: sellRamState.chain,
pricePerKB: sellRamState.pricePerKB,
bytesValue: sellRamState.bytesValue,
insufficientRAM: sellRamState.insufficientRAM,
valid: sellRamState.valid,
balances: context.account?.balances
},
undefined,
2
)}</Code
>
{/if}
</Stack>
26 changes: 11 additions & 15 deletions src/routes/[network]/(account)/resources/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
<script lang="ts">
import Stack from '$lib/components/layout/stack.svelte';
import Button from '$lib/components/button/button.svelte';
import { Int64 } from '@wharfkit/antelope';
import { getContext } from 'svelte';
import { CpuIcon, WifiIcon, HardDrive } from 'lucide-svelte';
import Stack from '$lib/components/layout/stack.svelte';
import Button from '$lib/components/button/button.svelte';
import CpuAndNetResource from '$lib/components/elements/cpunetresource.svelte';
import RamResource from '$lib/components/elements/ramresource.svelte';
import AccountBalance from '$lib/components/card/accountbalance.svelte';
import { calAvailableSize } from '$lib/utils';
import * as m from '$lib/paraglide/messages';
import type { UnicoveContext } from '$lib/state/client.svelte';
import { getContext } from 'svelte';
const { data } = $props();
const context = getContext<UnicoveContext>('state');
const cpuAvailableSize = $derived(calAvailableSize(context.account?.resources.cpu));
const netAvailableSize = $derived(calAvailableSize(context.account?.resources.net));
const ramAvailableSize = $derived(calAvailableSize(context.account?.resources.ram));
const cpuAvailableSize = $derived(context.account?.resources.cpu.available || Int64.from(0));
const netAvailableSize = $derived(context.account?.resources.net.available || Int64.from(0));
const ramAvailableSize = $derived(context.account?.resources.ram.available || Int64.from(0));
const network = String(data.network);
const chainName = data.network.chain.name;
const symbolName = data.network.chain.systemToken?.symbol.name || 'token';
const precision = 2;
const explanations = [
{
Expand Down Expand Up @@ -73,11 +71,9 @@
<div class="flex flex-col gap-9 sm:gap-12 xl:flex-row xl:justify-between xl:gap-8">
<Stack class="max-w-lg flex-1 gap-9">
<Stack>
<CpuAndNetResource
cpuAvailable={cpuAvailableSize}
netAvailable={netAvailableSize}
{precision}
/>
{#if cpuAvailableSize && netAvailableSize}
<CpuAndNetResource cpuAvailable={cpuAvailableSize} netAvailable={netAvailableSize} />
{/if}
{#if data.network.supports('powerup')}
<Button variant="primary" href="/{network}/resources/powerup"
>{m.resources_rent_with_powerup()}</Button
Expand All @@ -95,7 +91,7 @@
{/if}
</Stack>
<Stack>
<RamResource ramAvailable={ramAvailableSize} {precision} />
<RamResource ramAvailable={ramAvailableSize} />
<Button variant="secondary" href="/{network}/ram">{m.common_ram_market()}</Button>
</Stack>
<AccountBalance />
Expand Down
21 changes: 8 additions & 13 deletions src/routes/[network]/(account)/resources/renting.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script lang="ts">
import { Checksum256, Int64 } from '@wharfkit/antelope';
import { type TransactResult } from '@wharfkit/session';
import { getContext } from 'svelte';
import Stack from '$lib/components/layout/stack.svelte';
import NumberInput from '$lib/components/input/number.svelte';
import Label from '$lib/components/input/label.svelte';
Expand All @@ -10,16 +14,12 @@
import TransactError from '$lib/components/transact/error.svelte';
import CpuAndNetResource from '$lib/components/elements/cpunetresource.svelte';
import { Checksum256 } from '@wharfkit/antelope';
import { type TransactResult } from '@wharfkit/session';
import { getContext } from 'svelte';
import type { UnicoveContext } from '$lib/state/client.svelte';
import type { NetworkState } from '$lib/state/network.svelte';
import type { AccountState } from '$lib/state/client/account.svelte';
import * as m from '$lib/paraglide/messages';
import { calAvailableSize, preventDefault } from '$lib/utils';
import { preventDefault } from '$lib/utils';
import { RentState } from './state.svelte';
import { type RentType } from './utils';
Expand All @@ -33,8 +33,8 @@
const { rentType, network, account }: Props = $props();
const cpuAvailableSize = $derived(calAvailableSize(context.account?.resources.cpu));
const netAvailableSize = $derived(calAvailableSize(context.account?.resources.net));
const cpuAvailableSize = $derived(context.account?.resources.cpu.available || Int64.from(0));
const netAvailableSize = $derived(context.account?.resources.net.available || Int64.from(0));
const usableTime = $derived.by(() => {
if (rentType === 'POWERUP') return m.resources_usable_time_24h();
if (rentType === 'REX') return m.resources_usable_time_30days();
Expand Down Expand Up @@ -94,7 +94,6 @@
return details;
});
const precision = 2;
let transactionId: Checksum256 | undefined = $state();
let errorMessage: string | undefined = $state();
Expand Down Expand Up @@ -141,11 +140,7 @@
<Button onclick={resetStateAfterTrasaction}>{m.common_close()}</Button>
{:else}
<div class="mx-auto max-w-md space-y-3">
<CpuAndNetResource
cpuAvailable={cpuAvailableSize}
netAvailable={netAvailableSize}
{precision}
/>
<CpuAndNetResource cpuAvailable={cpuAvailableSize} netAvailable={netAvailableSize} />
<form onsubmit={preventDefault(handleRent)}>
<Stack class="py-4 sm:p-4 ">
<fieldset class="grid gap-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<script lang="ts">
import AssetText from '$lib/components/elements/asset.svelte';
import { API, Asset, PermissionLevel, UInt64 } from '@wharfkit/antelope';
import { PermissionLevel } from '@wharfkit/antelope';
import { getContext } from 'svelte';
import { goto } from '$app/navigation';
import type { UnicoveContext } from '$lib/state/client.svelte';
import { getContext, onMount } from 'svelte';
import * as m from '$lib/paraglide/messages';
import { Card } from '$lib/components/layout/index.js';
import Code from '$lib/components/code.svelte';
import Account from '$lib/components/elements/account.svelte';
import Button from '$lib/components/button/button.svelte';
const { data } = $props();
const zero = UInt64.from(0);
const balances = $derived(data.account.balances.filter((item) => item.asset.units.gt(zero)));
const context = getContext<UnicoveContext>('state');
const isCurrentUser = $derived(
Expand All @@ -23,13 +19,18 @@
data.account.name.equals(context.account.name)
);
function signin(auth: PermissionLevel) {
context.wharf.multisig(auth);
async function signin(auth: PermissionLevel) {
await context.wharf.multisig(auth);
goto(`/${data.account.network}/account/${auth.actor}`);
}
</script>

<p>
The {data.account.name} account has some form of authority assigned to the other accounts listed below.
</p>

{#await data.authorizations then authorizations}
{#each authorizations.accounts as auth, i}
{#each authorizations.accounts as auth}
{@const permission = PermissionLevel.from(`${auth.account_name}@${auth.permission_name}`)}
<Card>
<div class="flex">
Expand All @@ -43,7 +44,12 @@
</div>
<div class="flex-end">
{#if isCurrentUser}
<Button onclick={() => signin(permission)}>Setup Multi-Sig</Button>
<Button onclick={() => signin(permission)}>
Login as {permission}
<div class="text-xs">
↳ multisig using {data.account.name}
</div>
</Button>
{/if}
</div>
</div>
Expand Down

0 comments on commit e50358c

Please sign in to comment.