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¶
name
-string
: string of the dapp to check
Returns¶
boolean
: True if DApp is available for development, False otherwise.
sendEvent¶
utils.sendEvent(name, data);
Sends an event using window.dispatchEvent
Parameters¶
name
-string
: event namedata
-any
(optional): data that should be send
events¶
Predefined events for frontend usage
setProgress¶
utils.setProgress(percentage);
Sets the current loading progress (animates evan.network logo)
Parameters¶
percentage
-number
: current loading percentage
raiseProgress¶
utils.raiseProgress(percentage, returnObj);
Takes the latest progress percentage and raise it with the incoming value.
Parameters¶
percentage
-number
: percentage to addreturnObj
-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¶
message
-string
: message to loglevel
-string
(optional): level to log (log / verbose)
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
getDAppName¶
utils.getDAppName();
Removes the text after the last dot.
Parameters¶
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