Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'edge-core-js' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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,
}
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),
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,
}
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
})
}
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)
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
}
}
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)
}
constructor(props) {
super(props)
makeEdgeContext({
apiKey: '3ad0717b3eb31f745aba7bd9d51e7fd1b2926431',
appId: 'com.mydomain.myapp'
}).then(context => this.setState({ context }))
this.state = {
account: null,
closed: false,
context: null
}
}
}
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
}
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({