async function updateContractInfo(req, res, next) {
  const { nftCommitmentShield, ftCommitmentShield } = req.body;

  try {
    const user = await db.fetchUser(req.user);

    // if update ftCommitmentShield data
    if (ftCommitmentShield) {
      const { contractName, contractAddress, isSelected } = ftCommitmentShield;

      const isFTShieldPreviousSelected =
        user.selected_coin_shield_contract === ftCommitmentShield.contractAddress;

      await db.updateFTShieldContractInfoByContractAddress(req.user, contractAddress, {
        contractName,
        isSelected,
        isFTShieldPreviousSelected,
      });

      if (isSelected)
        await zkp.setFTCommitmentShield(req.user, { ftCommitmentShield: contractAddress });
      else if (isFTShieldPreviousSelected) await zkp.unSetFTCommitmentShield(req.user);
    }

    // if update nftCommitmentShield data
    if (nftCommitmentShield) {
      const { contractName, contractAddress, isSelected } = nftCommitmentShield;

      const isNFTShieldPreviousSelected =
        user.selected_token_shield_contract === nftCommitmentShield.contractAddress;

      await db.updateNFTShieldContractInfoByContractAddress(req.user, contractAddress, {
        contractName,
        isSelected,
        isNFTShieldPreviousSelected,
      });

      if (isSelected) await zkp.setTokenShield(req.user, { nftCommitmentShield: contractAddress });
      else if (isNFTShieldPreviousSelected) await zkp.unSetTokenShield(req.user);
    }

    res.data = { message: 'Contract Address updated' };
    next();
  } catch (err) {
    next(err);
  }
}
/**
 * This function will update sheild contract information
   will change primary selected contract for user of both
   ERC-20 and ERC-721.
 * in body "nftCommitmentShield" and "ftCommitmentShield" object are optional.
 * req.body {
    "nftCommitmentShield": {
      "contractAddress": "0x88B8d386BA803423482f325Be664607AE1Db6E1F",
      "contractName": "tokenShield1",
      "isSelected": true
    },
    "ftCommitmentShield": {
      "contractAddress": "0x3BBa2cdBb2376F07017421878540c424aAB61294",
      "contractName": "coinShield0",
      "isSelected": false
    }
  }
 * @param {*} req
 * @param {*} res
*/
This function will update sheild contract information
will change primary selected contract for user of both
ERC-20 and ERC-721.
in body "nftCommitmentShield" and "ftCommitmentShield" object are optional.
This function will update sheild contract information will change primary selected contract for user of both ERC - 20 and ERC - 721 . in body " nftCommitmentShield " and " ftCommitmentShield " object are optional .
async function updateContractInfo(req, res, next) {
  const { nftCommitmentShield, ftCommitmentShield } = req.body;
  try {
    const user = await db.fetchUser(req.user);
    if (ftCommitmentShield) {
      const { contractName, contractAddress, isSelected } = ftCommitmentShield;
      const isFTShieldPreviousSelected =
        user.selected_coin_shield_contract === ftCommitmentShield.contractAddress;
      await db.updateFTShieldContractInfoByContractAddress(req.user, contractAddress, {
        contractName,
        isSelected,
        isFTShieldPreviousSelected,
      });
      if (isSelected)
        await zkp.setFTCommitmentShield(req.user, { ftCommitmentShield: contractAddress });
      else if (isFTShieldPreviousSelected) await zkp.unSetFTCommitmentShield(req.user);
    }
    if (nftCommitmentShield) {
      const { contractName, contractAddress, isSelected } = nftCommitmentShield;
      const isNFTShieldPreviousSelected =
        user.selected_token_shield_contract === nftCommitmentShield.contractAddress;
      await db.updateNFTShieldContractInfoByContractAddress(req.user, contractAddress, {
        contractName,
        isSelected,
        isNFTShieldPreviousSelected,
      });
      if (isSelected) await zkp.setTokenShield(req.user, { nftCommitmentShield: contractAddress });
      else if (isNFTShieldPreviousSelected) await zkp.unSetTokenShield(req.user);
    }
    res.data = { message: 'Contract Address updated' };
    next();
  } catch (err) {
    next(err);
  }
}
async function updateContractInfo ( req , res , next ) { const { nftCommitmentShield , ftCommitmentShield } = req . body ; try { const user = await db . fetchUser ( req . user ) ; if ( ftCommitmentShield ) { const { contractName , contractAddress , isSelected } = ftCommitmentShield ; const isFTShieldPreviousSelected = user . selected_coin_shield_contract === ftCommitmentShield . contractAddress ; await db . updateFTShieldContractInfoByContractAddress ( req . user , contractAddress , { contractName , isSelected , isFTShieldPreviousSelected , } ) ; if ( isSelected ) await zkp . setFTCommitmentShield ( req . user , { ftCommitmentShield : contractAddress } ) ; else if ( isFTShieldPreviousSelected ) await zkp . unSetFTCommitmentShield ( req . user ) ; } if ( nftCommitmentShield ) { const { contractName , contractAddress , isSelected } = nftCommitmentShield ; const isNFTShieldPreviousSelected = user . selected_token_shield_contract === nftCommitmentShield . contractAddress ; await db . updateNFTShieldContractInfoByContractAddress ( req . user , contractAddress , { contractName , isSelected , isNFTShieldPreviousSelected , } ) ; if ( isSelected ) await zkp . setTokenShield ( req . user , { nftCommitmentShield : contractAddress } ) ; else if ( isNFTShieldPreviousSelected ) await zkp . unSetTokenShield ( req . user ) ; } res . data = { message : 'Contract Address updated' } ; next ( ) ; } catch ( err ) { next ( err ) ; } }
This function will update sheild contract information
will change primary selected contract for user of both
ERC-20 and ERC-721.
This function will update sheild contract information will change primary selected contract for user of both ERC - 20 and ERC - 721 .
// if update ftCommitmentShield data // if update nftCommitmentShield data