From e2bc4ed2ed9f3026e71e7c31c5db9556c63031ff Mon Sep 17 00:00:00 2001 From: kurt Date: Fri, 25 Oct 2024 11:59:19 +0800 Subject: [PATCH] add transaction section --- .../resources/components/renting.svelte | 113 ++++++++++++++---- .../(account)/resources/powerup/+page.svelte | 2 +- .../(account)/resources/rex/+page.svelte | 2 +- .../(account)/resources/stake/+page.svelte | 4 +- 4 files changed, 92 insertions(+), 29 deletions(-) diff --git a/src/routes/[network]/(account)/resources/components/renting.svelte b/src/routes/[network]/(account)/resources/components/renting.svelte index 2412647e1..8c056a85e 100644 --- a/src/routes/[network]/(account)/resources/components/renting.svelte +++ b/src/routes/[network]/(account)/resources/components/renting.svelte @@ -20,6 +20,8 @@ import { getContext } from 'svelte'; import type { UnicoveContext } from '$lib/state/client.svelte'; + import { Checksum256, type TransactResult } from '@wharfkit/session'; + import Transaction from '$lib/components/transaction.svelte'; const context = getContext('state'); @@ -78,8 +80,10 @@ let receiverInput: NameInput | undefined = $state(); - const rentState: RentState = $state(new RentState(network.chain, RentType.STAKE)); + const rentState: RentState = $state(new RentState(network.chain, rentType)); const precision = 2; + //0ebca2f19920514cb7d1f31f04cbfd279788a06671dd1260b7c00a259e2e85ad + let transactionId: Checksum256 | undefined = $state(); function handleRent() { if (!context.wharf || !context.wharf.session || !context.network) { @@ -90,13 +94,32 @@ try { rentState.resetBeforeTransction(); const actions = rentState.getActions(context.network.contracts.system); + context.wharf + .transact({ + actions: actions + }) + .then((result: TransactResult) => { + transactionId = result.response?.transaction_id; + resetStateAfterTrasaction(); + }) + .catch((error) => { + rentState.error = String(error); + }); } catch (error) { console.error(error); alert('rex failed: ' + (error as { message: string }).message); } } + + function resetStateAfterTrasaction() { + rentState.resetAfterTransction(); + } +{#if transactionId} +
+{/if} +
- - {#if debugMode} -
-

Test Info:

-

receiver: {rentState.receiver}

-

rentingForSelf: {rentState.rentingForSelf}

-

thirdReceiver: {rentState.thirdReceiver}

-

cpuPricePerMs: {rentState.cpuPricePerMs}, netPricePerKb: {rentState.netPricePerKb}

-

liquid: {rentState.balance}

- -

valid:

-

Valid: {rentState.valid}

-

ReceiverInputValid: {rentState.thirdReceiverValid}

- -

Cost

-

cpuAmount: {rentState.cpuAmount}, netAmount: {rentState.netAmount}

-

cpu: {rentState.cpuQuantity} net: {rentState.netQuantity}

-

cost: {rentState.cost}

- {#if rentType === RentType.POWERUP} -

cpuFrac: {rentState.cpuFrac}, netFrac: {rentState.netFrac}

- {/if} -
- {/if}
+{#if debugMode} +
+

Test Info

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {#if rentType === RentType.POWERUP} + + + + + + + + + {/if} + +
RentType{rentType}
Balance{rentState.balance}
Receiver{rentState.receiver}
RentingForSelf{rentState.rentingForSelf}
ThirdReceiver{rentState.thirdReceiver}
ThirdReceiver-Valid{rentState.thirdReceiverValid}
Valid{rentState.valid}
CpuAmount{rentState.cpuAmount}
NetAmount{rentState.netAmount}
CpuQuantity{rentState.cpuQuantity}
NetQuantity{rentState.netQuantity}
CpuFrac{rentState.cpuFrac}
NetFrac{rentState.netFrac}
+
+{/if} diff --git a/src/routes/[network]/(account)/resources/powerup/+page.svelte b/src/routes/[network]/(account)/resources/powerup/+page.svelte index a8cccfc82..7c7f24de5 100644 --- a/src/routes/[network]/(account)/resources/powerup/+page.svelte +++ b/src/routes/[network]/(account)/resources/powerup/+page.svelte @@ -16,6 +16,6 @@ function handleRent() {} -
+
diff --git a/src/routes/[network]/(account)/resources/rex/+page.svelte b/src/routes/[network]/(account)/resources/rex/+page.svelte index 3e8e54d06..46e8a435a 100644 --- a/src/routes/[network]/(account)/resources/rex/+page.svelte +++ b/src/routes/[network]/(account)/resources/rex/+page.svelte @@ -16,6 +16,6 @@ function handleRent() {} -
+
diff --git a/src/routes/[network]/(account)/resources/stake/+page.svelte b/src/routes/[network]/(account)/resources/stake/+page.svelte index f641f812e..b51d7e4b6 100644 --- a/src/routes/[network]/(account)/resources/stake/+page.svelte +++ b/src/routes/[network]/(account)/resources/stake/+page.svelte @@ -12,10 +12,8 @@ const network = data.network; const account = $derived(context.account); - - function handleRent() {} -
+