Adding Wallet Functionalities

Wallet Functions
const getBalanceClick = async () => {
    //Call getBalance method
    const balanceObj = await getBalance(clientId);
    console.log("balanceObj", balanceObj);
    console.log("balance", balanceObj?.balance);
    setBalance(balanceObj?.balance || 0);
  };

  const getBalanceWasmClick = async () => {
    //Call getBalance method on Wasm
    const balanceObj = await getBalanceWasm(clientId);
    console.log("balanceObj", balanceObj);
    console.log("balance", balanceObj?.zcn);
    setBalance(balanceObj?.zcn || 0);
  };

  const createWalletClick = async () => {
    console.log("calling createWallet");
    const wallet = await createWallet();
    console.log("Wallet", wallet);
    setClientId(wallet.keys.walletId);
    setPublicKey(wallet.keys.publicKey);
    setPrivateKey(wallet.keys.privateKey);
  };

  const recoverWalletClick = async () => {
    console.log("calling recoverWallet");
    const wallet = await recoverWallet(mnemonic);
    console.log("Wallet", wallet);
    setClientId(wallet.keys.walletId);
    setPublicKey(wallet.keys.publicKey);
    setPrivateKey(wallet.keys.privateKey);
  };

  const getFaucetTokenClick = async () => {
    console.log("calling getFaucetToken");
    await getFaucetToken();
  };

  const sendTransactionClick = async () => {
    console.log("calling sendTransaction");
    const fromWallet = {
      id: clientId,
      public_key: publicKey,
      secretKey: privateKey,
    };
    await sendTransaction(fromWallet, sendTo, parseInt(sendAmount), "");
  };

  const setWalletClick = async () => {
    console.log("calling set wallet");
    //Call setWallet method
    await setWallet(clientId, privateKey, publicKey, mnemonic);
  };

const getUSDRateClick = async () => {
    console.log("getUSDRate");
    const rate = await getUSDRate("zcn");
    console.log("getUSDRate completed", rate);
    setOutput(rate);
  };

  const isWalletIDClick = async () => {
    console.log("isWalletID");
    const output = await isWalletID(clientId);
    //const output = await isWalletID("abc");
    console.log("isWalletID completed", output);
    setOutput("" + output);
  };

  const getPublicEncryptionKeyClick = async () => {
    console.log("getPublicEncryptionKey");
    const key = await getPublicEncryptionKey(mnemonic);
    console.log("getPublicEncryptionKey completed", key);
    setEncryptKey(key);
  };

const initBridgeClick = async () => {
    const ethereumAddress = "0x5B9eb7E72247c45F6c4B8424FB2002151c57c54d",
      bridgeAddress = "0x2405e40161ea6da91AE0e95061e7A8462b4D5eEa",
      authorizersAddress = "0xB132C20A02AD7C38d88805F0e3fFDdfb54224C58",
      wzcnAddress = "0x10140fbca3a468A1c35F132D75659eF0EB5d95DB",
      ethereumNodeURL =
        "https://goerli.infura.io/v3/6141be73a15d47748af0dc14f53d57d7",
      gasLimit = 300000,
      value = 0,
      consensusThreshold = 75.0;
    console.log(
      "initBridgeClick",
      ethereumAddress,
      bridgeAddress,
      authorizersAddress,
      wzcnAddress,
      ethereumNodeURL,
      gasLimit,
      value,
      consensusThreshold
    );
    //Call initBridge method
    await initBridge(
      ethereumAddress,
      bridgeAddress,
      authorizersAddress,
      wzcnAddress,
      ethereumNodeURL,
      gasLimit,
      value,
      consensusThreshold
    );
  };

  const burnZCNClick = async () => {
    const amount = 1000;
    console.log("burnZCNClick", amount);
    const hash = await burnZCN(amount);
    setTxHash(hash);
    return hash;
  };

  const mintZCNClick = async () => {
    const burnTrxHash = txHash,
      timeout = 100;
    console.log("mintZCNClick", burnTrxHash, timeout);
    const hash = await mintZCN(burnTrxHash, timeout);
    return hash;
  };

  const getMintWZCNPayloadClick = async () => {
    const burnTrxHash = txHash;
    console.log("getMintWZCNPayloadClick", burnTrxHash);
    const result = await getMintWZCNPayload(burnTrxHash);
    return result;
  };

Describing Code :

Line 1 to 133 defines the following allocation functionalities for the web app :

  • getBalanceClick : Get Wallet Balance on click .Calls js-sdk getBalance method .

  • getBalanceWasmClick : Get Wallet Balance on Wasm . Calls js-sdk getBalanceWasm by passing wallet ClientID.

  • createWalletClick: Create Wallet on click .Calls js-sdk createWallet method

  • recoverWalletClick: Recover wallet on click.Calls js-sdk recoverWallet method by passing wallet mnemonic phrase provided as input by user.

  • getFaucetTokenClick: Get Test Tokens into wallet via faucet.Calls js-sdk getFaucetToken method.

  • sendTransactionClick: Send ZCN token from one wallet to another. Calls js-sdk sendTransaction method.

  • setWalletClick: Set wallet on click.Calls js-sdk setWallet method.

  • getUSDRateClick : Get USD equivalent of ZCN tokens. Calls js-sdk getUSD method.

  • isWalletIDClick : Verifies WalletID. Calls js-sdk isWalletID method.

  • getPublicEncryptionKeyClick : Get Wallet PublicEncryptionKey . Calls js-sdk getPublicEncryptionKey method

  • initBridgeClick : Initialize bridge configuration for burning and minting of tokens. Calls js-sdk initBridge method.

  • burnZCNClick : A function for burning ZCN tokens.Calls js-sdk burnZCN method

  • mintZCNClick : A function ffor minting ZCN tokens .Calls js-sdk mintZCN method.

  • getMintZCNPayloadClick : A function for getting MintZCNPayload. Calls js-sdk mintZCNpayload method.

Last updated