0

I have implemented @walletconnect/react-native-dapp in my react-native application to connect external wallet to my app.

Everything is working in my app. I have stuck at one place where I'm calling the approve method of ABI by wallet sendTransaction call. The flow is working if I select Approve option on other external wallet (MetaMask) and transaction been successfully happening.

But when I select Reject on MetaMask then promise not being calling nor catch block calling, or redirection to my app also not happening.

How do I manage the flow if user click on Reject option on request on Metamask. Someone please look it.

Here is my code which I am follow :-

export const transferOnChainWalletPOZBalance = async (
  pozPouchFundWallet: string,
  amountValue: number,
  userWallet: string,
  connector: any,
) => {
  return new Promise<string>(async (resolve, reject) => {
    const POZ_TOKEN = await fetchItemFromStorage('POZ_TOKEN');
    const WEB3_URL = await fetchItemFromStorage('WEB3_URL');
    const Web3js = new Web3(WEB3_URL as string);
    let toAddress = pozPouchFundWallet; // end address to transfer amount
    let decimals = BigNumber(18);
    let amount1 = new BigNumber(amountValue);
    let value = amount1.times(new BigNumber(10).pow(decimals));
    let contract = new Web3js.eth.Contract(POZ_ABI, POZ_TOKEN!);
    try {
      let dataa = await contract.methods
        .approve(toAddress, value.toString())
        .encodeABI();
      let txObj = {
        // gas: Web3js.utils.toHex(100000),
        // value: value,
        data: Web3js.utils.toHex(dataa),
        from: userWallet,
        to: POZ_TOKEN, // Contractor token address
      };
      try {
        const transactionHash = await connector
          .sendTransaction(txObj)
          .catch((_err: any) => {
            Toast.show({
              autoHide: true,
              text1: t('topUpPoz.transactionFailed'),
              type: 'error',
            });
          });
        console.log('approve transactionHash is =', transactionHash);
        resolve(transactionHash);
      } catch (error) {
        console.log('approve the connector error is = ', error);
        reject(error);
      }
    } catch (err) {
      console.log('contact error is = ', err);
      reject(err);
    }
  });
};
Pankaj Sonava
  • 519
  • 4
  • 20

0 Answers0