How to use the await-to-js.to function in await-to-js

To help you get started, we’ve selected a few await-to-js 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 LiskHQ / lisk-desktop / src / components / screens / splashscreen / splashscreen.js View on Github external
async checkNodeStatus() {
    const { errorToastDisplayed, history, liskAPIClient } = this.props;
    // istanbul ignore else
    if (liskAPIClient) {
      const [error, response] = await to(liskAPIClient.node.getConstants());
      if (response) history.push(routes.dashboard.path);
      if (error) errorToastDisplayed({ label: `Unable to connect to the node, Error: ${error.message}` });
    }
  }
github carbon-native / carbon-native / scripts / package-json.js View on Github external
(async function() {
  const [error1, data] = await to(fs.readJson('./package.json'));
  if (error1) return console.error(error1);

  data.dependencies = _.omit(data.dependencies, [
    'expo',
    'react',
    'react-native',
  ]);

  data.private = false;

  const [error2] = await to(
    fs.writeJson('./dist/package.json', data, { spaces: 2 })
  );
  if (error2) return console.error(error2);
})();
github carbon-native / carbon-native / scripts / package-json.js View on Github external
(async function() {
  const [error1, data] = await to(fs.readJson('./package.json'));
  if (error1) return console.error(error1);

  data.dependencies = _.omit(data.dependencies, [
    'expo',
    'react',
    'react-native',
  ]);

  data.private = false;

  const [error2] = await to(
    fs.writeJson('./dist/package.json', data, { spaces: 2 })
  );
  if (error2) return console.error(error2);
})();
github LiskHQ / lisk-desktop / src / actions / account.js View on Github external
export const login = ({ passphrase, publicKey, hwInfo }) => async (dispatch, getState) => {
  const { network: networkConfig, settings } = getState();
  dispatch(accountLoading());
  const expireTime = (passphrase && settings.autoLog)
    ? Date.now() + accountConfig.lockDuration
    : 0;

  const activeTokens = Object.keys(settings.token.list)
    .filter(key => settings.token.list[key]);
  const [error, info] = await to(getAccounts(activeTokens, {
    networkConfig, publicKey, passphrase,
  }));

  if (error) {
    dispatch(errorToastDisplayed({ label: getConnectionErrorMessage(error) }));
    dispatch(accountLoggedOut());
  } else {
    dispatch(accountLoggedIn({
      passphrase,
      loginType: hwInfo ? loginType[hwInfo.deviceModel.replace(/\s.+$/, '').toLowerCase()] : loginType.normal,
      hwInfo: hwInfo || {},
      expireTime,
      info,
    }));
  }
};
github LiskHQ / lisk-desktop / src / components / shared / header / signInHeader / signInHeader.js View on Github external
async checkNodeStatus(showErrorToaster = true) {
    const {
      liskAPIClient, errorToastDisplayed, network,
    } = this.props;

    if (liskAPIClient) {
      this.setState({
        network: network.networks.LSK.code,
        activeNetwork: network.networks.LSK.code,
      });
      const [error] = await to(liskAPIClient.node.getConstants());

      if (error) {
        if (network.name === networks.customNode.name) {
          this.setValidationError();
        } else {
          this.setState(({ validationError: '' }));
        }
        if (showErrorToaster) {
          errorToastDisplayed({ label: `Unable to connect to the node, Error: ${error.message}` });
        }
      }
    }
  }
github GrouperBot / GrouperBot / src / util / LoadTags.js View on Github external
export default async function LoadTags(client) {
    let database, err;

    [ err , database ] = await to(getDB());

    if (err) {
        setTimeout(LoadTags, 5 * 1000);

        return;
    }

    database.query("SELECT `name`, `created_at` FROM `tags`", (err, results) => {
        if (err) {
            throw err;
        }

        for (const result of results) {
            let tag = new Tag(result.name);

            tag.setCreatedAt(result.created_at);
github GrouperBot / GrouperBot / src / tasks / Sweep.js View on Github external
async run() {
        const stmt = format(
            "DELETE FROM advertisements WHERE `expiration` < ?",
            Math.floor(Date.now() / 1000),
        );

        let database, err;

        [ err , database ] = await to(getDB());

        if (err) {
            return;
        }

        database.query(stmt, (err, results) => {
            if (err) {
                return;
            }

            /**
             * Emitted when sweeping is complete
             * 
             * @event GrouperClient#sweeped
             * @param {number} results.affectedRows Number of rows affected or deleted
             */
github LiskHQ / lisk-desktop / src / actions / account.js View on Github external
export const updateEnabledTokenAccount = token => async (dispatch, getState) => {
  const { network: networkConfig, account } = getState();
  if (token !== tokenMap.LSK.key) {
    const [error, result] = await to(getAccount({
      token,
      networkConfig,
      passphrase: account.passphrase,
    }));
    if (error) {
      dispatch(errorToastDisplayed({ label: getConnectionErrorMessage(error) }));
    } else {
      dispatch(accountUpdated(result));
    }
  }
};
github LiskHQ / lisk-desktop / src / components / screens / hwWalletLogin / requestPin.js View on Github external
async onSubmitPin(e) {
    e.preventDefault();
    const { pin } = this.state;
    const { deviceId, t, nextStep } = this.props;
    this.setState({ isLoading: true });
    const [error] = await to(validatePin({ deviceId, pin }));
    if (error) {
      this.setState({
        isLoading: false, error: true, feedback: t('Invalid PIN'), pin: '',
      });
    } else {
      nextStep({ deviceId });
    }
  }
github LiskHQ / lisk-desktop / src / components / screens / hwWalletLogin / selectAccount / selectAccount.js View on Github external
async getAccountsFromDevice() {
    const { device, networkConfig, errorToastDisplayed } = this.props;
    const [error, accounts] = await to(getAccountsFromDevice({ device, networkConfig }));
    if (error) {
      errorToastDisplayed({ label: `Error retrieving accounts from device: ${error}` });
    } else {
      const hwAccounts = accounts.map((account, index) => ({
        ...account,
        name: this.getNameFromAccount(account.address),
        shouldShow: !!account.balance || index === 0,
      }));
      this.setState({ hwAccounts });
    }
  }

await-to-js

Async/await wrapper for easy error handling in js

MIT
Latest version published 4 years ago

Package Health Score

55 / 100
Full package analysis

Popular await-to-js functions