How to use @aragon/api - 10 common examples

To help you get started, we’ve selected a few @aragon/api 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 1Hive / conviction-voting-app / app / src / script.js View on Github external
import 'core-js/stable'
import 'regenerator-runtime/runtime'
import Aragon, { events } from '@aragon/api'
import { addressesEqual, toUtf8 } from './lib/web3-utils'
import { hasLoadedTokenSettings, loadTokenSettings } from './token-settings'
import tokenAbi from './abi/minimeToken.json'
import {
  vaultAbi,
  getVaultInitializationBlock,
  updateBalances,
} from './vault-balance'

const app = new Aragon()

/*
 * Calls `callback` exponentially, everytime `retry()` is called.
 * Returns a promise that resolves with the callback's result if it (eventually) succeeds.
 *
 * Usage:
 *
 * retryEvery(retry => {
 *  // do something
 *
 *  if (condition) {
 *    // retry in 1, 2, 4, 8 seconds… as long as the condition passes.
 *    retry()
 *  }
 * }, 1000, 2)
 *
github 1Hive / time-lock-app / app / src / script.js View on Github external
(state, { event, returnValues, blockNumber }) => {
      // dont want to listen for past events for now
      // (our app state can be obtained from smart contract vars)
      if (blockNumber && blockNumber <= currentBlock) return state

      let nextState = {
        ...state,
      }

      switch (event) {
        case events.ACCOUNTS_TRIGGER:
          return updateConnectedAccount(nextState, returnValues)
        case events.SYNC_STATUS_SYNCING:
          return { ...nextState, isSyncing: true }
        case events.SYNC_STATUS_SYNCED:
          return { ...nextState, isSyncing: false }
        case 'ChangeLockDuration':
          return updateLockDuration(nextState, returnValues)
        case 'ChangeLockAmount':
          return updateLockAmount(nextState, returnValues)
        case 'ChangeSpamPenaltyFactor':
          return updateSpamPenaltyFactor(nextState, returnValues)
        case 'NewLock':
          return newLock(nextState, returnValues)
        case 'Withdrawal':
          return newWithdrawal(nextState, returnValues)
        default:
          return state
      }
    },
    {
github 1Hive / time-lock-app / app / src / script.js View on Github external
(state, { event, returnValues, blockNumber }) => {
      // dont want to listen for past events for now
      // (our app state can be obtained from smart contract vars)
      if (blockNumber && blockNumber <= currentBlock) return state

      let nextState = {
        ...state,
      }

      switch (event) {
        case events.ACCOUNTS_TRIGGER:
          return updateConnectedAccount(nextState, returnValues)
        case events.SYNC_STATUS_SYNCING:
          return { ...nextState, isSyncing: true }
        case events.SYNC_STATUS_SYNCED:
          return { ...nextState, isSyncing: false }
        case 'ChangeLockDuration':
          return updateLockDuration(nextState, returnValues)
        case 'ChangeLockAmount':
          return updateLockAmount(nextState, returnValues)
        case 'ChangeSpamPenaltyFactor':
          return updateSpamPenaltyFactor(nextState, returnValues)
        case 'NewLock':
          return newLock(nextState, returnValues)
        case 'Withdrawal':
          return newWithdrawal(nextState, returnValues)
        default:
          return state
      }
github AutarkLabs / open-enterprise / apps / rewards / app / index.js View on Github external
import React from 'react'
import ReactDOM from 'react-dom'
import Aragon, { providers } from '@aragon/api'
import App from './components/App/App'

class ConnectedApp extends React.Component {
  state = {
    app: new Aragon(new providers.WindowMessage(window.parent)),
    observable: null,
    userAccount: '',
    network: {},
    // ...allocationsMockData
  }
  componentDidMount() {
    window.addEventListener('message', this.handleWrapperMessage)
  }
  componentWillUnmount() {
    window.removeEventListener('message', this.handleWrapperMessage)
  }
  // handshake between Aragon Core and the iframe,
  // since iframes can lose messages that were sent before they were ready
  handleWrapperMessage = ({ data }) => {
    if (data.from !== 'wrapper') {
      return
github 1Hive / time-lock-app / app / src / script.js View on Github external
(state, { event, returnValues, blockNumber }) => {
      // dont want to listen for past events for now
      // (our app state can be obtained from smart contract vars)
      if (blockNumber && blockNumber <= currentBlock) return state

      let nextState = {
        ...state,
      }

      switch (event) {
        case events.ACCOUNTS_TRIGGER:
          return updateConnectedAccount(nextState, returnValues)
        case events.SYNC_STATUS_SYNCING:
          return { ...nextState, isSyncing: true }
        case events.SYNC_STATUS_SYNCED:
          return { ...nextState, isSyncing: false }
        case 'ChangeLockDuration':
          return updateLockDuration(nextState, returnValues)
        case 'ChangeLockAmount':
          return updateLockAmount(nextState, returnValues)
        case 'ChangeSpamPenaltyFactor':
          return updateSpamPenaltyFactor(nextState, returnValues)
        case 'NewLock':
          return newLock(nextState, returnValues)
        case 'Withdrawal':
          return newWithdrawal(nextState, returnValues)
        default:
github 1Hive / token-request-app / app / src / script.js View on Github external
import 'core-js/stable'
import 'regenerator-runtime/runtime'
import Aragon, { events } from '@aragon/api'
import { first } from 'rxjs/operators'
import tmAbi from './abi/tokenManager.json'
import { requestStatus } from './lib/constants'
import {
  tokenDataFallback,
  getTokenSymbol,
  getTokenName,
  getTokenDecimals,
  ETHER_TOKEN_FAKE_ADDRESS,
} from './lib/token-utils'

const app = new Aragon()

const ETHER_DATA = {
  decimals: 18,
  name: 'Ether',
  symbol: 'ETH',
}

app
  .call('tokenManager')
  .subscribe(initialize, err =>
    console.error(`Could not start background script execution due to the contract not loading token: ${err}`)
  )

async function initialize(tokenManagerAddress) {
  let tokens = []
  const network = await app
github pandonetwork / pando / packages / pando-repository / app / src / script.js View on Github external
import Aragon from '@aragon/api'
import CID from 'cids'
import IPFS from 'ipfs-http-client'
import IPLD from 'ipld'
import IPLDGit from 'ipld-git'
import { cidToSha } from 'ipld-git/src/util/util.js'
import orderBy from 'lodash.orderby'
import uniqWith from 'lodash.uniqwith'

const PR_STATE = ['PENDING', 'MERGED', 'REJECTED'].reduce((state, key, index) => {
  state[key] = index
  return state
}, {})
const app = new Aragon()
const ipfs = IPFS({ host: 'ipfs.infura.io', port: '5001', protocol: 'https' })
const ipld = new IPLD({
  blockService: ipfs.block,
  formats: [IPLDGit],
})

app
  .call('name')
  .toPromise()
  .then(name => {
    app.identify(name)
  })
  .catch(err => {
    console.error('Failed to load information to identify repository app due to:', err)
  })
github 1Hive / time-lock-app / app / src / script.js View on Github external
import 'core-js/stable'
import 'regenerator-runtime/runtime'
import Aragon, { events } from '@aragon/api'
import { addressesEqual } from './lib/web3-utils'
import tokenAbi from './abi/token.json'
import retryEvery from './lib/retry-every'
import lockSettings from './lib/lock-settings'

const app = new Aragon()

retryEvery(() =>
  app
    .call('token')
    .subscribe(initialize, err =>
      console.error(
        `Could not start background script execution due to the contract not loading token: ${err}`
      )
    )
)

async function initialize(tokenAddress) {
  const tokenContract = app.external(tokenAddress, tokenAbi)
  return createStore(tokenContract)
}
github 1Hive / conviction-voting-app / app / src / script.js View on Github external
const { id } = returnValues
        nextState = {
          ...nextState,
          proposals: nextState.proposals.map(proposal => {
            if (proposal.id === parseInt(id)) {
              return { ...proposal, executed: true }
            }
            return proposal
          }),
        }
        break
      }
      case events.SYNC_STATUS_SYNCING:
        nextState = { ...nextState, isSyncing: true }
        break
      case events.SYNC_STATUS_SYNCED:
        nextState = { ...nextState, isSyncing: false }
        break
    }

    console.log(nextState)
    return nextState
  }
github 1Hive / conviction-voting-app / app / src / script.js View on Github external
break
      }
      case 'ProposalExecuted': {
        const { id } = returnValues
        nextState = {
          ...nextState,
          proposals: nextState.proposals.map(proposal => {
            if (proposal.id === parseInt(id)) {
              return { ...proposal, executed: true }
            }
            return proposal
          }),
        }
        break
      }
      case events.SYNC_STATUS_SYNCING:
        nextState = { ...nextState, isSyncing: true }
        break
      case events.SYNC_STATUS_SYNCED:
        nextState = { ...nextState, isSyncing: false }
        break
    }

    console.log(nextState)
    return nextState
  }