Exemplo n.º 1
0
function parseRoundScore(g: LbDataGolfer): number {
  const str = g.round;
  if (isNullStr(str)) return 0;
  if (str === 'E') return 0;
  if (str.startsWith('+')) return parseInt(str.substr(1));
  if (str.startsWith('-')) return parseInt(str);
  throw new Error(`Unexpected round score: ${str}`);
}
    public async signPersonalMessageAsync(msgParams: SignPersonalMessageParams,
                                          callback: (err: Error, result?: string) => void) {
        if (!_.isUndefined(this.ledgerEthConnection)) {
            callback(new Error('Another request is in progress.'));
            return;
        }
        this.ledgerEthConnection = await this.createLedgerConnectionAsync();

        try {
            const derivationPath = this.getDerivationPath();
            const result = await this.ledgerEthConnection.signPersonalMessage_async(
                derivationPath, ethUtil.stripHexPrefix(msgParams.data),
            );
            const v = _.parseInt(result.v) - 27;
            let vHex = v.toString(16);
            if (vHex.length < 2) {
                vHex = `0${v}`;
            }
            const signature = `0x${result.r}${result.s}${vHex}`;
            await this.closeLedgerConnectionAsync();
            callback(null, signature);
        } catch (err) {
            await this.closeLedgerConnectionAsync();
            callback(err, null);
        }
    }
Exemplo n.º 3
0
    private async onPageLoadInitFireAndForgetAsync() {
        await this.onPageLoadAsync(); // wait for page to load

        // Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in
        // order to properly instantiate the web3Wrapper. Since we must use the async call, we cannot
        // retrieve it from within the web3Wrapper constructor. This is and should remain the only
        // call to a web3 instance outside of web3Wrapper in the entire dapp.
        // In addition, if the user has an injectedWeb3 instance that is disconnected from a backing
        // Ethereum node, this call will throw. We need to handle this case gracefully
        const injectedWeb3 = (window as any).web3;
        let networkId: number;
        if (!_.isUndefined(injectedWeb3)) {
            try {
                networkId = _.parseInt(await promisify(injectedWeb3.version.getNetwork)());
            } catch (err) {
                // Ignore error and proceed with networkId undefined
            }
        }

        const provider = await this.getProviderAsync(injectedWeb3, networkId);
        this.zeroEx = new ZeroEx(provider);
        await this.updateProviderName(injectedWeb3);
        const shouldPollUserAddress = true;
        this.web3Wrapper = new Web3Wrapper(this.dispatcher, provider, networkId, shouldPollUserAddress);
        await this.postInstantiationOrUpdatingProviderZeroExAsync();
    }
function parseDayScore(td: Element, par: number): number | 'MC' {
  const text = td.textContent.trim();
  if (isEmpty(text)) {
    // TODO: Turn this into typescript compatible
    return constants.MISSED_CUT as 'MC';
  }
  return parseInt(text) - par;
}
Exemplo n.º 5
0
 trs.forEach(tr => {
   const tds = tr.querySelectorAll('td');
   const wgr = _.parseInt(tds.item(0).textContent);
   const name = tr.querySelector('td.name')
     .textContent
     .trim()
     .replace(AMATEUR_REGEX, '');
   wgrs.push({ wgr, name } as WGR);
 });
Exemplo n.º 6
0
  configComponents.forEach(component => {
    const [ key, value ] = component.split('=');

    const lKey = key.toLowerCase();

    switch (lKey[ 0 ]) {
      case 'c': {
        if (primordialCharacter.className === 'None') {
          const chosenCharacterClass = _.find(Character.CHARACTER_CLASS_NAMES, (name) => {
            return Helpers.isApproximateString(value, name);
          });

          if (chosenCharacterClass) {
            primordialCharacter.className = chosenCharacterClass;
          } else {
            log.push(`Unrecognized character class: ${value}`);
          }
        }

        break;
      }
      case 'a': {
        if (primordialCharacter.allegiance === 'None') {
          const chosenAllegiance = _.find(Character.ALLEGIANCES, (allegiance) => {
            return Helpers.isApproximateString(value, allegiance);
          });

          if (chosenAllegiance) {
            primordialCharacter.allegiance = chosenAllegiance;
          } else {
            log.push(`Unrecognized allegiance: ${value}`);
          }
        }

        break;
      }
      case 'm': {
        updatedNumModifiers = true;
        if (primordialCharacter.numModifiers === 0) {
          const chosenNumModifiers = _.parseInt(value, 10);

          if (_.isFinite(chosenNumModifiers) && chosenNumModifiers >= 0) {
            primordialCharacter.numModifiers = chosenNumModifiers;
          } else {
            log.push(`Bad number of modifiers: ${value}`);
          }

          break;
        }
      }
      default: {
        log.push(`Unrecognized key: ${key}`);
        break;
      }
    }
  });
 _.each(T.Koulutustyypit(), kt => {
     const ktkoodi = _.parseInt(kt.split("_")[1]);
     $httpBackend
         .when("GET", "/eperusteet-service/api/perusteprojektit/" + ktkoodi)
         .respond(createPerusteprojekti(ktkoodi));
     $httpBackend.when("GET", "/eperusteet-service/api/perusteet/" + ktkoodi).respond(
         createPeruste(("koulutustyyppi_" + ktkoodi) as T.Koulutustyyppi, {
             id: ktkoodi
         })
     );
 });
Exemplo n.º 8
0
function parseNetworkId(networkIdStrIfExists?: string): number {
    if (_.isUndefined(networkIdStrIfExists)) {
        return NETWORK_ID;
    } else {
        const networkId = _.parseInt(networkIdStrIfExists);
        if (networkId !== NETWORK_ID) {
            const validationErrorItem = {
                field: 'networkId',
                code: 1004,
                reason: `Incorrect Network ID: ${networkIdStrIfExists}`,
            };
            throw new ValidationError([validationErrorItem]);
        }
        return networkId;
    }
}
Exemplo n.º 9
0
    private async _onPageLoadInitFireAndForgetAsync() {
        await utils.onPageLoadAsync(); // wait for page to load

        // Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in
        // order to properly instantiate the web3Wrapper. Since we must use the async call, we cannot
        // retrieve it from within the web3Wrapper constructor. This is and should remain the only
        // call to a web3 instance outside of web3Wrapper in the entire dapp.
        // In addition, if the user has an injectedWeb3 instance that is disconnected from a backing
        // Ethereum node, this call will throw. We need to handle this case gracefully
        const injectedWeb3 = (window as any).web3;
        let networkIdIfExists: number;
        if (!_.isUndefined(injectedWeb3)) {
            try {
                networkIdIfExists = _.parseInt(await promisify<string>(injectedWeb3.version.getNetwork)());
            } catch (err) {
                // Ignore error and proceed with networkId undefined
            }
        }

        const provider = await Blockchain._getProviderAsync(injectedWeb3, networkIdIfExists);
        this.networkId = !_.isUndefined(networkIdIfExists)
            ? networkIdIfExists
            : configs.IS_MAINNET_ENABLED ? constants.NETWORK_ID_MAINNET : constants.NETWORK_ID_KOVAN;
        this._dispatcher.updateNetworkId(this.networkId);
        const zeroExConfigs = {
            networkId: this.networkId,
        };
        this._zeroEx = new ZeroEx(provider, zeroExConfigs);
        this._updateProviderName(injectedWeb3);
        const shouldPollUserAddress = true;
        this._web3Wrapper = new Web3Wrapper(provider);
        this._blockchainWatcher = new BlockchainWatcher(
            this._dispatcher,
            this._web3Wrapper,
            this.networkId,
            shouldPollUserAddress,
        );

        const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
        this._userAddressIfExists = userAddresses[0];
        this._dispatcher.updateUserAddress(this._userAddressIfExists);
        await this.fetchTokenInformationAsync();
        this._blockchainWatcher.startEmittingNetworkConnectionAndUserBalanceState();
        await this._rehydrateStoreWithContractEvents();
    }
 generateNewTitle(oldTitle, aes, titleName){
     let newTitle;
     if (_.endsWith(oldTitle, '_CLONE')){
         newTitle = oldTitle + '(1)';
     }else{
         if (_.endsWith(oldTitle, ')')){
             let split = _.split(oldTitle,  '(');
             let index = _.last(split);
             split.pop();
             index = _.replace(index, ')', '');
             let indexInt = _.parseInt(index);
             newTitle = split + '(' + _.add(indexInt, 1) + ')';
         }else{
             newTitle = oldTitle + '_CLONE';
         }
     }
     if(aes && _.findIndex(aes, function(o) { return (_.hasIn(o,titleName) && o[titleName] == newTitle); }) > -1){
         return this.generateNewTitle(newTitle, aes, titleName);
     }else{
         return newTitle;
     }
 }