How to use edge-core-js - 10 common examples

To help you get started, we’ve selected a few edge-core-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 EdgeApp / edge-login-ui / packages / edge-login-ui-web / src / frame / context-api.js View on Github external
export async function makeUiContext(opts: EdgeUiContextOptions) {
  const {
    apiKey,
    appId,
    hideKeys = false,
    vendorName = '',
    vendorImageUrl = ''
  } = opts

  // Core context:
  const core: EdgeContext = await makeEdgeContext({
    apiKey,
    appId,
    hideKeys,
    plugins: [ethereumCurrencyPluginFactory, shapeshiftPlugin, coincapPlugin]
  })

  // iframe root:
  const root = document.getElementById('app')
  if (root == null) throw new Error('Cannot find document root')

  // State:
  let localUsers: Array = core.localUsers
  let windowVisible = false

  const out: EdgeUiContext = {
    on: onMethod,
github EdgeApp / edge-react-gui / src / connectors / scenes / SendConfirmationConnector.js View on Github external
}

  const transaction = getTransaction(state)
  const pending = getPending(state)
  const nativeAmount = sceneState.nativeAmount
  // const nativeAmount = getNativeAmount(state)
  let error = getError(state)

  let errorMsg = null
  let resetSlider = false
  if (error && error.message === 'broadcastError') {
    error = null
    resetSlider = true
  }
  errorMsg = error ? error.message : ''
  if (error && error.name === errorNames.NoAmountSpecifiedError) errorMsg = ''
  const networkFee = transaction ? transaction.networkFee : null
  const parentNetworkFee = transaction && transaction.parentNetworkFee ? transaction.parentNetworkFee : null

  const uniqueIdentifier = sceneState.parsedUri.uniqueIdentifier
  const transactionMetadata = sceneState.transactionMetadata
  const exchangeRates = state.exchangeRates
  const out = {
    balanceInCrypto,
    balanceInFiat,
    currencyCode,
    transactionMetadata,
    errorMsg,
    exchangeRates,
    fiatCurrencyCode: guiWallet.fiatCurrencyCode,
    fiatPerCrypto,
    forceUpdateGuiCounter: getForceUpdateGuiCounter(state),
github EdgeApp / edge-react-gui / src / connectors / scenes / SendConfirmationConnector.js View on Github external
const transaction = getTransaction(state)
  const pending = getPending(state)
  const nativeAmount = sceneState.nativeAmount
  // const nativeAmount = getNativeAmount(state)
  let error = getError(state)

  let errorMsg = null
  let resetSlider = false
  // consider refactoring this method for resetting slider
  if (error && (error.message === 'broadcastError' || error.message === 'transactionCancelled')) {
    error = null
    resetSlider = true
  }
  errorMsg = error ? error.message : ''
  if (error && error.name === errorNames.NoAmountSpecifiedError) errorMsg = ''
  const networkFee = transaction ? transaction.networkFee : null
  const parentNetworkFee = transaction && transaction.parentNetworkFee ? transaction.parentNetworkFee : null
  const uniqueIdentifier = sceneState.guiMakeSpendInfo.uniqueIdentifier
  const transactionMetadata = sceneState.transactionMetadata
  const exchangeRates = state.exchangeRates
  const { toggleCryptoOnTop } = sceneState

  const { spendingLimits } = state.ui.settings

  const out = {
    balanceInCrypto,
    balanceInFiat,
    currencyCode,
    currencyInfo: currencyInfo || null,
    transactionMetadata,
    errorMsg,
github EdgeApp / edge-react-gui / src / actions / CryptoExchangeActions.js View on Github external
}

        case 'noVerification': {
          if (error.pluginName === 'shapeshift') {
            Airship.show(bridge => )
            return
          }
          break // Not handled
        }
      }
      break // Not handled
    }
  }

  // Some plugins get this error wrong:
  if (error.message === errorNames.InsufficientFundsError) {
    return dispatch({ type: 'RECEIVED_INSUFFICENT_FUNDS_ERROR' })
  }

  // Anything else:
  return dispatch({
    type: 'GENERIC_SHAPE_SHIFT_ERROR',
    data: error.message
  })
}
github EdgeApp / edge-react-gui / src / actions / CryptoExchangeActions.js View on Github external
const processSwapQuoteError = (error: any) => (dispatch: Dispatch, getState: GetState) => {
  const state = getState()
  const { fromCurrencyCode, toCurrencyCode } = state.cryptoExchange

  // Basic sanity checks (should never fail):
  if (error == null) return
  if (fromCurrencyCode == null || toCurrencyCode == null) return

  // Check for known error types:
  switch (error.name) {
    case errorNames.InsufficientFundsError: {
      return dispatch({ type: 'RECEIVED_INSUFFICENT_FUNDS_ERROR' })
    }

    case errorNames.SwapAboveLimitError: {
      const settings = SETTINGS_SELECTORS.getSettings(state)
      const currentCurrencyDenomination = SETTINGS_SELECTORS.getDisplayDenominationFromSettings(settings, fromCurrencyCode)

      const nativeMax: string = error.nativeMax
      const displayDenomination = SETTINGS_SELECTORS.getDisplayDenomination(state, fromCurrencyCode)
      const nativeToDisplayRatio = displayDenomination.multiplier
      const displayMax = UTILS.convertNativeToDisplay(nativeToDisplayRatio)(nativeMax)

      return dispatch({
        type: 'GENERIC_SHAPE_SHIFT_ERROR',
        data: sprintf(s.strings.amount_above_limit, displayMax, currentCurrencyDenomination.name)
      })
    }

    case errorNames.SwapBelowLimitError: {
      const settings = SETTINGS_SELECTORS.getSettings(state)
github EdgeApp / edge-login-ui / packages / edge-login-ui-web / src / frame / frame-state.js View on Github external
async function makeFrameState (opts: ConnectionMessage): Promise {
  const {
    apiKey,
    appId,
    hideKeys,
    vendorName = '',
    vendorImageUrl = '',
    clientDispatch
  } = opts
  const context = await makeEdgeContext({ apiKey, appId })

  return {
    accounts: {},
    context,
    hideKeys,
    nextAccountId: 0,
    page: '',
    pageAccount: null,
    vendorImageUrl,
    vendorName,

    clientDispatch
  }
}
github EdgeApp / edge-react-gui / src / util / makeContext.js View on Github external
export async function makeCoreContext (): Promise {
  const opts: EdgeContextOptions = {
    apiKey: AIRBITZ_API_KEY,
    appId: '',
    shapeshiftKey: SHAPESHIFT_API_KEY,
    changellyInit: CHANGELLY_INIT,
    changeNowKey: CHANGE_NOW_API_KEY,
    faastInit: FAAST_INIT
  }

  return makeEdgeContext(opts)
}
github EdgeApp / edge-login-ui / packages / edge-login-ui-react / src / demo / index.js View on Github external
constructor(props) {
    super(props)
    makeEdgeContext({
      apiKey: '3ad0717b3eb31f745aba7bd9d51e7fd1b2926431',
      appId: 'com.mydomain.myapp'
    }).then(context => this.setState({ context }))

    this.state = {
      account: null,
      closed: false,
      context: null
    }
  }
github EdgeApp / edge-login-ui / packages / edge-login-ui-react / src / abcui.js View on Github external
}

  const getAssetPath = args => {
    if (args.assetPath) {
      return args.assetsPath
    }
    if (args.bundlePath) {
      return args.bundlePath + '/assets'
    }
    if (!args.assetPath && !args.bundlePath) {
      return './assets'
    }
  }

  if (args.apiKey && args.appId) {
    const airbitzCoreJs = makeContext({
      apiKey: args.apiKey,
      appId: args.appId,
      accountType: args.accountType,
      authServer: getApiServer()
    })

    DomWindow.abcui = {
      assetPath: getAssetPath(args),
      abcuiContext: airbitzCoreJs,
      vendorName: args.vendorName,
      vendorImageUrl: args.vendorImageUrl
    }

    const getABCContext = () => {
      return airbitzCoreJs
    }
github EdgeApp / edge-react-gui / src / actions / CryptoExchangeActions.js View on Github external
case errorNames.SwapAboveLimitError: {
      const settings = SETTINGS_SELECTORS.getSettings(state)
      const currentCurrencyDenomination = SETTINGS_SELECTORS.getDisplayDenominationFromSettings(settings, fromCurrencyCode)

      const nativeMax: string = error.nativeMax
      const displayDenomination = SETTINGS_SELECTORS.getDisplayDenomination(state, fromCurrencyCode)
      const nativeToDisplayRatio = displayDenomination.multiplier
      const displayMax = UTILS.convertNativeToDisplay(nativeToDisplayRatio)(nativeMax)

      return dispatch({
        type: 'GENERIC_SHAPE_SHIFT_ERROR',
        data: sprintf(s.strings.amount_above_limit, displayMax, currentCurrencyDenomination.name)
      })
    }

    case errorNames.SwapBelowLimitError: {
      const settings = SETTINGS_SELECTORS.getSettings(state)
      const currentCurrencyDenomination = SETTINGS_SELECTORS.getDisplayDenominationFromSettings(settings, fromCurrencyCode)

      const nativeMin: string = error.nativeMin
      const displayDenomination = SETTINGS_SELECTORS.getDisplayDenomination(state, fromCurrencyCode)
      const nativeToDisplayRatio = displayDenomination.multiplier
      const displayMin = UTILS.convertNativeToDisplay(nativeToDisplayRatio)(nativeMin)

      return dispatch({
        type: 'GENERIC_SHAPE_SHIFT_ERROR',
        data: sprintf(s.strings.amount_below_limit, displayMin, currentCurrencyDenomination.name)
      })
    }

    case errorNames.SwapCurrencyError: {
      return dispatch({