How to use the web3-utils._ function in web3-utils

To help you get started, we’ve selected a few web3-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vechain / thorify / test / test-utils / fake-provider.ts View on Github external
return callback(new Error("Method not supported!"), {
        id: payload.id || 0,
        jsonrpc: payload.jsonrpc || "2.0",
        result: null,
      });
    }
    let ret = ThorAPIMapping[payload.method].ret;
    // non-objects doesn't need isThorified property since thorify just overwritten 3 formatters
    // which all accept object as input
    if (web3Utils._.isObject(ret)) {
      // tricks for fast deep copy since I defined ThorAPIMapping
       ret = JSON.parse(JSON.stringify(ret));
       Object.defineProperty(ret, "reqBody", { get: () => payload, set: () => null });
       Object.defineProperty(ret, "isThorified", { get: () => true, set: () => null });
    }
    if (web3Utils._.isArray(ret)) {
      ret = ret.map((i) => {
        i = JSON.parse(JSON.stringify(i));
        Object.defineProperty(i, "reqBody", { get: () => payload, set: () => null });
        Object.defineProperty(i, "isThorified", { get: () => true, set: () => null });
        return i;
      });
    }
    callback(null, {
      id: payload.id || 0,
      jsonrpc: payload.jsonrpc || "2.0",
      result: ret,
    });
  }
github MyEtherWallet / MyEtherWallet / src / builds / mewcx / cxHelpers / background.js View on Github external
const eventsListeners = (request, _, callback) => {
  if (request.event === CX_WEB3_DETECTED) {
    clearTimeout(metamaskChecker);
    metamaskChecker = setTimeout(() => {
      chrome.storage.sync.remove('warned');
    }, 180000); // Clear var in 3 minutes
  }

  const payload = utils._.mapObject(
    Object.assign({}, request.payload),
    function(val) {
      return helpers.recursivePayloadStripper(val);
    }
  );

  const obj = {
    event: request.event,
    payload: payload
  };

  const middleware = new MiddleWare();
  middleware.use(mewCxFetchAccounts);
  middleware.use(mewCxSignTx);
  middleware.use(mewCxSignMsg);
  middleware.use(mewCxSendSignedTx);
github vechain / thorify / src / http-provider.ts View on Github external
id: payload.id || 0,
            jsonrpc: payload.jsonrpc || "2.0",
            result: null,
          });
        }

        debug("result: %O", result);
        result = preparation.ResFormatter(result);

        // tricks for compatible with original web3 instance
        // non-objects or non-arrays does't need isThorified property since thorify just overwritten 3 formatters
        // which all accept object as input
        if (web3Utils._.isObject(result) && !web3Utils._.isArray(result)) {
          Object.defineProperty(result, "isThorified", { get: () => true});
        }
        if (web3Utils._.isArray(result)) {
          result = result.map((item: any) => {
            Object.defineProperty(item, "isThorified", { get: () => true});
            return item;
          });
        }
        callback(error, {
          id: payload.id || 0,
          jsonrpc: payload.jsonrpc || "2.0",
          result,
        });
      }
    };
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / InterfaceLayout.vue View on Github external
this.$store.dispatch('switchNetwork', this.Networks[net][0]);
            return true;
          }
        });
      }
    },
    matchWeb3WalletNetwork() {
      this.web3.eth.net.getId().then(id => {
        this.checkAndSetNetwork(id);
      });
      window.ethereum.on('networkChanged', netId => {
        this.setupOnlineEnvironment();
        this.checkAndSetNetwork(netId);
      });
    },
    setupOnlineEnvironment: web3Utils._.debounce(function() {
      this.clearIntervals();
      if (store.get('customTokens') === undefined) {
        store.set('customTokens', {});
        this.setCustomTokenStore();
      } else {
        this.setCustomTokenStore();
      }
      if (this.online) {
        if (this.account.address !== null) {
          if (this.account.identifier === WEB3_TYPE) {
            if (window.ethereum.isMetaMask || window.ethereum.isMew) {
              console.log('or is it here???');
              this.checkWeb3WalletAddrChange();
              this.matchWeb3WalletNetwork();
            } else {
              console.log('or here???');
github MyEtherWallet / MyEtherWallet / src / dapps / ManageENS / containers / ManageENSContainer / ManageENSContainer.vue View on Github external
copySupported() {
      const newObj = utils._.map(this.supportedCoins, utils._.clone);
      const copiedObj = {};
      newObj.forEach(item => {
        copiedObj[item.symbol] = item;
      });

      return copiedObj;
    },
    addInput(item) {
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / containers / SendOfflineContainer / components / GenerateTx / GenerateTx.vue View on Github external
this.localGas = newVal;
    },
    toAmt(newVal) {
      this.createDataHex(newVal, null, null);
    },
    address(newVal) {
      if (this.validAddress) {
        this.createDataHex(null, newVal, null);
      }
    },
    selectedCoinType(newVal) {
      this.createDataHex(null, null, newVal);
    }
  },
  methods: {
    debouncedAmount: utils._.debounce(function(e) {
      const decimals =
        this.selectedCoinType.symbol === this.network.type.name
          ? 18
          : this.selectedCoinType.decimals;
      this.toAmt = new BigNumber(e.target.value)
        .decimalPlaces(decimals)
        .toFixed();
      e.target.value = this.toAmt;
    }, 300),
    async createDataHex(amount, address, currency) {
      const locAmount = amount !== null ? amount : this.toAmt;
      const locAddress = address !== null ? address : this.address;
      const locCurrency = currency !== null ? currency : this.selectedCoinType;
      const abi = [
        {
          constant: false,
github MyEtherWallet / MyEtherWallet / src / dapps / ManageENS / containers / ManageENSContainer / ManageENSContainer.vue View on Github external
copySupported() {
      const newObj = utils._.map(this.supportedCoins, utils._.clone);
      const copiedObj = {};
      newObj.forEach(item => {
        copiedObj[item.symbol] = item;
      });

      return copiedObj;
    },
    addCurrencyInput(item) {
github MyEtherWallet / MyEtherWallet / src / layouts / InterfaceLayout / containers / SendCurrencyContainer / SendCurrencyContainer.vue View on Github external
new Date().getTime() / 1000
      );
    },
    convert() {
      if (this.ethPrice) {
        return new BigNumber(
          new BigNumber(this.txFeeEth).times(new BigNumber(this.ethPrice))
        )
          .toFixed(2)
          .toString();
      }
      return '--';
    }
  },
  watch: {
    multiWatch: utils._.debounce(function() {
      if (this.validInputs) this.estimateGas();
    }, 500),
    network(newVal) {
      if (this.online && newVal.type.name === 'ETH') this.getEthPrice();
    },
    isPrefilled() {
      this.prefillForm();
    }
  },
  mounted() {
    this.checkPrefilled();
    if (this.online && this.network.type.name === 'ETH') this.getEthPrice();
  },
  methods: {
    clear() {
      this.toData = '';
github MyEtherWallet / MyEtherWallet / src / components / DropDownAddressSelector / DropDownAddressSelector.vue View on Github external
},
    addressBook() {
      this.updateAddresses(this.currentAddress);
    },
    hexAddress() {
      this.validateAddress();
    },
    currency() {
      this.validateAddress(this.selectedAddress);
    }
  },
  mounted() {
    this.currentAddress = this.account.address;
  },
  methods: {
    debouncedInput: utils._.debounce(function(e) {
      this.selectedAddress = e.target.value;
    }, 300),
    addAddress() {
      const alreadyExists = Object.keys(this.addressBook).some(key => {
        return this.addressBook[key].address === this.selectedAddress;
      });

      if (!this.selectedAddress) {
        Toast.responseHandler(
          this.$t('interface.address-book.cannot-add'),
          Toast.ERROR
        );
        return;
      } else if (!this.isValidAddress) {
        Toast.responseHandler(
          this.$t('ens.addr-resolver.invalid-eth-addr'),