How to use arc - 10 common examples

To help you get started, we’ve selected a few arc 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 daostack / alchemy / src / components / Scheme / ContributionRewardExtRewarders / Competition / utils.ts View on Github external
return async (dispatch: Redux.Dispatch, _getState: () => IRootState) => {
    try {
      const observer = operationNotifierObserver(dispatch, "Create Solution");
      const competition = new Competition(proposalId, getArc());
      await competition.createSuggestion(options).subscribe(...observer);
    } catch (err) {
      // eslint-disable-next-line no-console
      console.error(err);
      throw err;
    }
  };
};
github daostack / alchemy / src / components / Proposal / Create / SchemeForms / CreateContributionRewardProposal.tsx View on Github external
public async handleSubmit(values: IFormValues, { setSubmitting }: any ): Promise {
    if (!await enableWalletProvider({ showNotification: this.props.showNotification })) { return; }

    if (!values.beneficiary.startsWith("0x")) { values.beneficiary = "0x" + values.beneficiary; }

    const externalTokenDetails = tokenDetails(values.externalTokenAddress);
    let externalTokenReward;

    // If we know the decimals for the token then multiply by that
    if (externalTokenDetails) {
      externalTokenReward = toBaseUnit(values.externalTokenReward.toString(), externalTokenDetails.decimals);
    // Otherwise just convert to Wei and hope for the best
    } else {
      externalTokenReward = toWei(Number(values.externalTokenReward));
    }

    const proposalValues = {...values,
      scheme: this.props.scheme.address,
github daostack / alchemy / src / components / Scheme / ReputationFromToken.tsx View on Github external
public async handleSubmit(values: IFormValues, { _props, setSubmitting, _setErrors }: any): Promise {
    // only connect to wallet if we do not have a private key to sign with
    if (!this.state.privateKey &&
      !await enableWalletProvider({ showNotification: this.props.showNotification })) {
      setSubmitting(false);
      return;
    }

    const schemeState = this.props.schemeState;
    const schemeAddress = schemeState.address;
    const arc = getArc();
    const schemeContract = await arc.getContract(schemeAddress);
    const alreadyRedeemed = await schemeContract.methods.redeems(this.state.redeemerAddress).call();
    if (alreadyRedeemed) {
      this.props.showNotification(NotificationStatus.Failure, `Reputation for the account ${this.state.redeemerAddress} was already redeemed`);
    } else if (values.useTxSenderService === true) {
      // construct the message to sign
      // const signatureType = 1
      const messageToSign = "0x"+ ethABI.soliditySHA3(
        ["address","address"],
github daostack / alchemy / src / layouts / AppContainer.tsx View on Github external
(newAddress: Address) => {
          if (newAddress && checkMetaMask()) {
            console.log(`new address: ${newAddress}`);
            this.props.setCurrentAccount(newAddress);
            this.props.cookies.set("currentAddress", newAddress, { path: "/"});
            // TODO: we reload on setting a new account,
            // but it would be more elegant if we did not need to
            window.location.reload();
          }
        });
      }
github daostack / alchemy / src / layouts / AppContainer.tsx View on Github external
console.log(`using address from web3 connection: ${currentAddress}`);
      this.props.cookies.set("currentAddress", currentAddress, { path: "/"});
      this.props.setCurrentAccount(currentAddress);
    } else {
      const currentAddressFromCookie = this.props.cookies.get("currentAddress");
      if (currentAddressFromCookie) {
        console.log(`using address from cookie: ${currentAddressFromCookie}`);
        this.props.setCurrentAccount(currentAddressFromCookie);
      } else {
        this.props.cookies.set("currentAddress", "", { path: "/"});
        this.props.setCurrentAccount(undefined);
      }
    }

    try {
      metamask = await checkMetaMask();
    } catch (err) {
      console.log("MM not available or not set correctly: using default web3 provider: ", err.message);
    }

    if (metamask) {
      pollForAccountChanges(currentAddress).subscribe(
        (newAddress: Address) => {
          if (newAddress && checkMetaMask()) {
            console.log(`new address: ${newAddress}`);
            this.props.setCurrentAccount(newAddress);
            this.props.cookies.set("currentAddress", newAddress, { path: "/"});
            // TODO: we reload on setting a new account,
            // but it would be more elegant if we did not need to
            window.location.reload();
          }
        });
github daostack / alchemy / src / layouts / AppContainer.tsx View on Github external
(newAddress: Address | null): void => {
        // eslint-disable-next-line no-console
        console.log(`new account: ${newAddress}`);
        this.props.setCurrentAccount(newAddress);
        if (newAddress) {
          cacheWeb3Info(newAddress);
        } else {
          uncacheWeb3Info();
          gotoReadonly(this.props.showNotification);
        }
      });
  }
github daostack / alchemy / src / App.tsx View on Github external
public async componentWillMount() {
    // Do this here because we need to have initialized Arc first
    // we initialize Arc
    initializeArc()
      .then(async () => {
        this.setState({ arcIsInitialized: true });
        persistStore(store);

      })
      .catch ((err) => {
        console.log(err);
      });

    let GOOGLE_ANALYTICS_ID: string;
    switch (process.env.NODE_ENV) {
      case "production": {
        // the "real" id
        GOOGLE_ANALYTICS_ID = "UA-142546205-1";
        break;
      }
github daostack / alchemy / src / App.tsx View on Github external
public async componentWillMount() {
    // Do this here because we need to have initialized Arc first
    // we initialize Arc
    initializeArc()
      .then(async () => {
        this.setState({ arcIsInitialized: true });
        persistStore(store);

      })
      .catch ((err) => {
        console.log(err);
      });

    ReactGA.initialize("UA-142546205-2");
    history.listen((location: any) => {
      ReactGA.pageview(location.pathname + location.search);
    });
  }
github daostack / alchemy / src / layouts / AppContainer.tsx View on Github external
*/
    const currentAddress = getCachedAccount();
    let accountWasCached = false;
    if (currentAddress) {
      accountWasCached = true;
      // eslint-disable-next-line no-console
      console.log(`using account from local storage: ${currentAddress}`);
    }

    this.props.setCurrentAccount(currentAddress);
    /**
     * Only supply currentAddress if it was obtained from a provider.  The poll
     * is only comparing changes with respect to the provider state.  Passing it a cached state
     * will only cause it to get the wrong impression and misbehave.
     */
    pollForAccountChanges(accountWasCached ? null : currentAddress).subscribe(
      (newAddress: Address | null): void => {
        // eslint-disable-next-line no-console
        console.log(`new account: ${newAddress}`);
        this.props.setCurrentAccount(newAddress);
        if (newAddress) {
          cacheWeb3Info(newAddress);
        } else {
          uncacheWeb3Info();
          gotoReadonly(this.props.showNotification);
        }
      });
  }
github daostack / alchemy / src / layouts / AppContainer.tsx View on Github external
console.log(`using address from cookie: ${currentAddressFromCookie}`);
        this.props.setCurrentAccount(currentAddressFromCookie);
      } else {
        this.props.cookies.set("currentAddress", "", { path: "/"});
        this.props.setCurrentAccount(undefined);
      }
    }

    try {
      metamask = await checkMetaMask();
    } catch (err) {
      console.log("MM not available or not set correctly: using default web3 provider: ", err.message);
    }

    if (metamask) {
      pollForAccountChanges(currentAddress).subscribe(
        (newAddress: Address) => {
          if (newAddress && checkMetaMask()) {
            console.log(`new address: ${newAddress}`);
            this.props.setCurrentAccount(newAddress);
            this.props.cookies.set("currentAddress", newAddress, { path: "/"});
            // TODO: we reload on setting a new account,
            // but it would be more elegant if we did not need to
            window.location.reload();
          }
        });
      }
  }