From 1ab5fbb1df70fde3a1efeb617219d6c76b778acf Mon Sep 17 00:00:00 2001 From: Alexander Diemand Date: Mon, 21 Oct 2024 21:05:43 +0200 Subject: [PATCH] wallet component Signed-off-by: Alexander Diemand --- .../src/lib/components/wallet.svelte | 39 +++++++++++++++ bca-token-market/src/lib/wallet.ts | 1 + .../[cid]/service/[sid]/instance/+page.svelte | 47 +++++++++++-------- 3 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 bca-token-market/src/lib/components/wallet.svelte diff --git a/bca-token-market/src/lib/components/wallet.svelte b/bca-token-market/src/lib/components/wallet.svelte new file mode 100644 index 0000000..b22fbfa --- /dev/null +++ b/bca-token-market/src/lib/components/wallet.svelte @@ -0,0 +1,39 @@ + + +
+ {#if wallet.walletaddr} +
+ + +
+ + {:else} + + {/if} +
+ + \ No newline at end of file diff --git a/bca-token-market/src/lib/wallet.ts b/bca-token-market/src/lib/wallet.ts index 4ba4f2a..b21be54 100644 --- a/bca-token-market/src/lib/wallet.ts +++ b/bca-token-market/src/lib/wallet.ts @@ -14,6 +14,7 @@ export async function get_wallet_chainid(wallet: WalletInformation): Promise = new window.web3.eth.Contract(serviceContractABI, contractAddresses[contractAddress]) - const user_addr = await contract.methods.userAddress().call() - const day_price = await contract.methods.dayPrice().call() - const deposit = await contract.methods.deposit().call() - const start_time = await contract.methods.startTime().call() - const end_time = await contract.methods.endTime().call() - const balance = 0n //await contract.methods.balanceUser().send({from: wallet.walletaddr}).then(console.log); - return { user_addr, day_price, deposit, start_time, end_time, balance, subscriber: (user_addr == wallet.walletaddr ? 'you' : 'anybody') } + const user_addr: string = await contract.methods.userAddress().call() + const day_price: bigint = await contract.methods.dayPrice().call() + const deposit: bigint = await contract.methods.deposit().call() + const start_time: bigint = await contract.methods.startTime().call() + const end_time: bigint = await contract.methods.endTime().call() + const balance: bigint = 0n //await contract.methods.balanceUser().send({from: wallet.walletaddr}).then(console.log); + return { user_addr, day_price, deposit, start_time, end_time, balance, subscriber: (user_addr.toLocaleLowerCase() == wallet.walletaddr?.toLocaleLowerCase() ? 'you' : 'anybody') } } return {} } async function deposit_tokens(tokens: number, ev: any) { console.log(`got ${tokens}`) - if (window.web3 && instance.contract_addr) { - if (! wallet.walletaddr) { wallet = await get_wallet_addr(wallet, {}); } + if (window.web3 && instance.contract_addr && wallet.walletaddr) { let token: Contract = new window.web3.eth.Contract(tokenContractABI, tokenContractAddress) const decimals: bigint = await token.methods.decimals().call() @@ -97,9 +98,11 @@ {#if $page.data.session}
-

controllers - - services

- +

Instances

@@ -109,8 +112,9 @@ {#if is_provider } {:else} - + {/if} @@ -140,7 +144,7 @@

Subscribe to service

-

Indicate the number of tokens you want to provide for the service:

+

Indicate the number of tokens you want to allocate for the service:

{JSON.stringify(instance,null,2)}

@@ -170,11 +174,14 @@

+ {#if contractdetails.end_time == 0n} + + {/if}
{instance.id} - {instance.id} + + {date_formatter.format(instance.created)} {date_formatter.format(instance.updated)}
Start time:{date_formatter.format(Number(contractdetails.start_time * 1000n))}
End time:{contractdetails.end_time > 0n ? date_formatter.format(Number(contractdetails.end_time * 1000n)) : ''}
Calc. end time:{date_formatter.format(Number(contractdetails.start_time * 1000n + (contractdetails.deposit * 1000n * 24n * 3600n / contractdetails.day_price)))}
Price / 24h:{contractdetails.day_price}
Deposit:{contractdetails.deposit}
Balance:{contractdetails.balance}
- {#if contractdetails.subscriber == 'you'}

{/if} + {#if contractdetails.subscriber == 'you'}

{/if} {/if}