diff --git a/backend/lib/b3_helper_lib/src/identifier.rs b/backend/lib/b3_helper_lib/src/identifier.rs index 70e4b832..a619b5b3 100644 --- a/backend/lib/b3_helper_lib/src/identifier.rs +++ b/backend/lib/b3_helper_lib/src/identifier.rs @@ -24,7 +24,7 @@ impl AccountIdentifier { data.push(0x0A); data.extend_from_slice("account-id".as_bytes()); data.extend_from_slice(owner.as_slice()); - data.extend_from_slice(subaccount.0.as_ref()); + data.extend_from_slice(subaccount.as_slice()); let account_hash = easy_hasher::raw_sha224(data); @@ -72,11 +72,7 @@ impl FromStr for AccountIdentifier { impl fmt::Display for AccountIdentifier { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut result = String::new(); - for byte in self.0.iter() { - result.push_str(&format!("{:02x}", byte)); - } - write!(f, "{}", result) + write!(f, "{}", hex::encode(&self.0)) } } diff --git a/backend/lib/b3_helper_lib/src/subaccount.rs b/backend/lib/b3_helper_lib/src/subaccount.rs index 34c1dfe5..3e9d2821 100644 --- a/backend/lib/b3_helper_lib/src/subaccount.rs +++ b/backend/lib/b3_helper_lib/src/subaccount.rs @@ -122,6 +122,10 @@ impl Subaccount { self.0 == [0u8; 32] } + pub fn as_ref(&self) -> &[u8; 32] { + &self.0 + } + pub fn as_slice(&self) -> &[u8] { &self.0 } diff --git a/backend/lib/b3_helper_lib/src/time.rs b/backend/lib/b3_helper_lib/src/time.rs index 247532cc..6a2ed6de 100644 --- a/backend/lib/b3_helper_lib/src/time.rs +++ b/backend/lib/b3_helper_lib/src/time.rs @@ -30,7 +30,7 @@ impl NanoTimeStamp { /// Converts the timestamp to seconds pub fn to_secs(&self) -> u64 { - self.0 / 1_000_000_000 + self.0 / Self::NS_PER_SECOND } /// Converts the timestamp to milliseconds @@ -107,6 +107,21 @@ impl NanoTimeStamp { NanoTimeStamp(self.0 + ns_to_add) } + /// Get the number of whole seconds represented by the timestamp + pub fn get_secs(&self) -> u64 { + self.0 / Self::NS_PER_SECOND + } + + /// Get the number of whole minutes represented by the timestamp + pub fn get_mins(&self) -> u64 { + self.0 / Self::NS_PER_MINUTE + } + + /// Get the number of whole hours represented by the timestamp + pub fn get_hours(&self) -> u64 { + self.0 / Self::NS_PER_HOUR + } + /// Get the number of whole days represented by the timestamp pub fn get_days(&self) -> u64 { self.0 / Self::NS_PER_DAY @@ -136,14 +151,18 @@ mod tests { let ts = ts.add_secs(1); assert_eq!(ts.to_secs(), 1); + assert_eq!(ts.get_secs(), 1); let ts = ts.add_mins(1); assert_eq!(ts.to_secs(), 61); + assert_eq!(ts.get_mins(), 1); let ts = ts.add_hours(1); assert_eq!(ts.to_secs(), 3661); + assert_eq!(ts.get_hours(), 1); let ts = ts.add_days(1); + assert_eq!(ts.to_secs(), 90061); assert_eq!(ts.get_days(), 1); } diff --git a/backend/lib/b3_wallet_lib/src/state.rs b/backend/lib/b3_wallet_lib/src/state.rs index 01741bc0..38dcd333 100644 --- a/backend/lib/b3_wallet_lib/src/state.rs +++ b/backend/lib/b3_wallet_lib/src/state.rs @@ -13,9 +13,9 @@ use ic_cdk::export::{candid::CandidType, serde::Deserialize}; #[derive(CandidType, Deserialize, Clone)] pub struct WalletState { - pub accounts: WalletAccountMap, pub nonces: AccountsNonce, pub settings: WalletSettings, + pub accounts: WalletAccountMap, } impl Default for WalletState { @@ -58,7 +58,7 @@ impl WalletState { account.rename("Main Account".to_owned()); - self.accounts.insert("default".to_owned(), account); + self.accounts.insert("-default".to_owned(), account); self.nonces.increment(Environment::Production); } @@ -140,7 +140,7 @@ impl WalletState { } pub fn remove_account(&mut self, id: &String) -> Result<(), WalletError> { - if id == "default" { + if id == "-default" { return Err(WalletError::CannotRemoveDefaultAccount); } diff --git a/frontend/src/components/Wallet/Account/ChainCards/EthCard.tsx b/frontend/src/components/Wallet/Account/ChainCards/EthCard.tsx index fb4dc723..ef6eb53b 100644 --- a/frontend/src/components/Wallet/Account/ChainCards/EthCard.tsx +++ b/frontend/src/components/Wallet/Account/ChainCards/EthCard.tsx @@ -11,16 +11,10 @@ import { import Address from "components/Wallet/Address" import Balance from "components/Wallet/Balance" import { ChainEnum } from "declarations/b3_wallet/b3_wallet.did" -import { ethers, providers } from "ethers" import useToastMessage from "hooks/useToastMessage" -import { useCallback, useEffect, useState } from "react" +import { useEffect, useState } from "react" import { B3BasicWallet, B3Wallet } from "service" import { AddressesWithChain } from "." -import TransferForm from "../TransferForm" - -const provider = new providers.JsonRpcProvider( - "https://data-seed-prebsc-2-s1.binance.org:8545" -) interface EthCardProps extends AddressesWithChain { actor: B3Wallet | B3BasicWallet @@ -47,7 +41,6 @@ const EthCard: React.FC = ({ network, accountId, balanceLoading, - networkDetail, handleBalance, handleTransfer, @@ -60,57 +53,6 @@ const EthCard: React.FC = ({ handleBalance(id, chain) }, [actor, accountId]) - const handleEthTransfer = useCallback( - async (from: string, to: string, amount: bigint) => { - console.log(`Transfering ${amount} ETH from ${from} to ${to}`) - setLoading(true) - - const nonce = await provider.getTransactionCount(from) - const gasPrice = await provider.getGasPrice().then(s => s.toHexString()) - const value = ethers.utils.parseEther(amount.toString()).toHexString() - const data = "0x00" - const gasLimit = ethers.BigNumber.from("24000").toHexString() - const transaction = { - nonce, - gasPrice, - gasLimit, - to, - value, - data - } - - try { - const serializeTx = Buffer.from( - ethers.utils.serializeTransaction(transaction).slice(2) + "808080", - "hex" - ) - - console.log(serializeTx) - - setLoading(false) - - console.log({ title: "Signing transaction...", variant: "subtle" }) - - // const res = await actor.request_sign_transaction( - // id, - // [...serializeTx], - // 97n - // ) - } catch (error: any) { - errorToast({ - title: "Error", - description: error.message, - status: "error", - duration: 5000, - isClosable: true - }) - - setLoading(false) - } - }, - [actor] - ) - return ( = ({ loading={balanceLoading} /> - + Not available right now, please don't send any tokens to this + address + + {/* + handleTransfer={handleEthTransfer} + /> */}