utils

Source utils

The utils includes several support functions.

One primary function is to check for dapps that should be loaded from the local development file server. This is enabled when opening the dev.html, instead of the index.html.


devMode

devMode

global available array that includes dev mode available dapps, when devMode is enabled, else undefined


setUpDevMode

utils.setUpDevMode();

Checks if we are running in devMode, if true, load dev-dapps from local file server, if false do nothing


isDevAvailable

utils.isDevAvailable(name);

Check if a dev application is available

Parameters

  1. name - string: string of the dapp to check

Returns

boolean: True if DApp is available for development, False otherwise.

Example

utils.isDevAvailable(ensDefinition.name)

sendEvent

utils.sendEvent(name, data);

Sends an event using window.dispatchEvent

Parameters

  1. name - string: event name
  2. data - any (optional): data that should be send

Example

utils.sendEvent('my-cool-event', { anyData: 1234 });

events

Predefined events for frontend usage

loadingSubDApp

events.loadingSubDApp

sends the event, that a sub DApp starts loading

finishLoadingSubDApp

events.loadingSubDApp

Sends the event, that a sub DApp finished loading


showError

utils.showError();

Show Error during the initial loading, when no UI framework is loaded


setProgress

utils.setProgress(percentage);

Sets the current loading progress (animates evan.network logo)

Parameters

  1. percentage - number: current loading percentage

Example

utils.setProgress(70)

raiseProgress

utils.raiseProgress(percentage, returnObj);

Takes the latest progress percentage and raise it with the incoming value.

Parameters

  1. percentage - number: percentage to add
  2. returnObj - any (optional): additional return object for raising loading progress and returning object instantly

Returns

Promise returns any: additional returnObject

Example

Promise
  .all<any, any>([
    System
      .import('bcc')
      .then(CoreBundle => utils.raiseProgress(10, CoreBundle)),
    System
      .import('smart-contracts')
      .then(SmartContracts => utils.raiseProgress(10, SmartContracts))
  ])

devLog

utils.devLog(message, level);

Log a message according to localStorage settings to the log

Parameters

  1. message - string: message to log
  2. level - string (optional): level to log (log / verbose)

Example

utils.devLog(`Loading dapp: ${ dappEns }`, 'trace');

onDeviceReady

utils.devLogonDeviceReady();

Adds an deviceready event handler and wait for the result to resolve the promise. If we are on a desktop device, dont wait for deviceready, it will be never called.

Returns

Promise returns void: resolved when decive is ready

Example

await utils.onDeviceReady();
console.log('device is ready :)');

getDAppName

utils.getDAppName();

Removes the text after the last dot.

Parameters

  1. ensAddress - string: ens address to get the name for

Returns

string: dappname including sub ens paths

Example

const dappName = utils.getDAppName('mydapp.mycompany.evan');
console.log(dappName) // => mydapp.mycompany