diff options
author | Hsuan Lee <boczeratul@gmail.com> | 2018-10-13 13:27:14 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2018-12-10 18:16:38 +0800 |
commit | 764cd4533c55620e35a2ff57ef447f7b9955620b (patch) | |
tree | 62deb7a73afb46b62fecdce7c17ab7c949a71d9f /app/scripts | |
parent | 7896e5f5c25add295ce4d9f7d97adc3ee69df48c (diff) | |
download | dexon-wallet-764cd4533c55620e35a2ff57ef447f7b9955620b.tar.gz dexon-wallet-764cd4533c55620e35a2ff57ef447f7b9955620b.tar.zst dexon-wallet-764cd4533c55620e35a2ff57ef447f7b9955620b.zip |
Complete onboarding flow
Diffstat (limited to 'app/scripts')
44 files changed, 214 insertions, 103 deletions
diff --git a/app/scripts/README.md b/app/scripts/README.md index f5a90724..60ba14ba 100644 --- a/app/scripts/README.md +++ b/app/scripts/README.md @@ -1,4 +1,4 @@ -# Main MetaMask Code +# Main DekuSan Code This folder contains the core-code. diff --git a/app/scripts/background.js b/app/scripts/background.js index 6056962d..b47c5bac 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -97,8 +97,8 @@ setupMetamaskMeshMetrics() */ /** - * The data emitted from the MetaMaskController.store EventEmitter, also used to initialize the MetaMaskController. Available in UI on React state as state.metamask. - * @typedef MetaMaskState + * The data emitted from the DekuSanController.store EventEmitter, also used to initialize the DekuSanController. Available in UI on React state as state.metamask. + * @typedef DekuSanState * @property {boolean} isInitialized - Whether the first vault has been created. * @property {boolean} isUnlocked - Whether the vault is currently decrypted and accounts are available for selection. * @property {boolean} isAccountMenuOpen - Represents whether the main account selection UI is currently displayed. @@ -123,7 +123,7 @@ setupMetamaskMeshMetrics() * @property {string} currentLocale - A locale string matching the user's preferred display language. * @property {Object} provider - The current selected network provider. * @property {string} provider.rpcTarget - The address for the RPC API, if using an RPC API. - * @property {string} provider.type - An identifier for the type of network selected, allows MetaMask to use custom provider strategies for known networks. + * @property {string} provider.type - An identifier for the type of network selected, allows DekuSan to use custom provider strategies for known networks. * @property {string} network - A stringified number of the current network ID. * @property {Object} accounts - An object mapping lower-case hex addresses to objects with "balance" and "address" keys, both storing hex string values. * @property {hex} currentBlockGasLimit - The most recently seen block gas limit, in a lower case hex prefixed string. @@ -151,19 +151,20 @@ setupMetamaskMeshMetrics() /** * @typedef VersionedData - * @property {MetaMaskState} data - The data emitted from MetaMask controller, or used to initialize it. + * @property {DekuSanState} data - The data emitted from DekuSan controller, or used to initialize it. * @property {Number} version - The latest migration version that has been run. */ /** - * Initializes the MetaMask controller, and sets up all platform configuration. + * Initializes the DekuSan controller, and sets up all platform configuration. * @returns {Promise} Setup complete. */ async function initialize () { const initState = await loadStateFromPersistence() + console.log(initState) const initLangCode = await getFirstPreferredLangCode() await setupController(initState, initLangCode) - log.debug('MetaMask initialization complete.') + log.debug('DekuSan initialization complete.') } // @@ -173,7 +174,7 @@ async function initialize () { /** * Loads any stored data, prioritizing the latest storage strategy. * Migrates that data schema in case it was last loaded on an older version. - * @returns {Promise<MetaMaskState>} Last data emitted from previous instance of MetaMask. + * @returns {Promise<DekuSanState>} Last data emitted from previous instance of DekuSan. */ async function loadStateFromPersistence () { // migrations @@ -196,14 +197,22 @@ async function loadStateFromPersistence () { // we were able to recover (though it might be old) versionedData = diskStoreState const vaultStructure = getObjStructure(versionedData) +<<<<<<< HEAD sentry.captureMessage('MetaMask - Empty vault found - recovered from diskStore', { +======= + raven.captureMessage('DekuSan - Empty vault found - recovered from diskStore', { +>>>>>>> Complete onboarding flow // "extra" key is required by Sentry extra: { vaultStructure }, }) } else { // unable to recover, clear state versionedData = migrator.generateInitialState(firstTimeState) +<<<<<<< HEAD sentry.captureMessage('MetaMask - Empty vault found - unable to recover') +======= + raven.captureMessage('DekuSan - Empty vault found - unable to recover') +>>>>>>> Complete onboarding flow } } @@ -220,7 +229,7 @@ async function loadStateFromPersistence () { // migrate data versionedData = await migrator.migrateData(versionedData) if (!versionedData) { - throw new Error('MetaMask - migrator returned undefined') + throw new Error('DekuSan - migrator returned undefined') } // write to disk @@ -229,7 +238,7 @@ async function loadStateFromPersistence () { } else { // throw in setTimeout so as to not block boot setTimeout(() => { - throw new Error('MetaMask - Localstore not supported') + throw new Error('DekuSan - Localstore not supported') }) } @@ -238,7 +247,7 @@ async function loadStateFromPersistence () { } /** - * Initializes the MetaMask Controller with any initial state and default language. + * Initializes the DekuSan Controller with any initial state and default language. * Configures platform-specific error reporting strategy. * Streams emitted state updates to platform-specific storage strategy. * Creates platform listeners for new Dapps/Contexts, and sets up their data connections to the controller. @@ -249,7 +258,7 @@ async function loadStateFromPersistence () { */ function setupController (initState, initLangCode) { // - // MetaMask Controller + // DekuSan Controller // const controller = new MetamaskController({ @@ -289,13 +298,13 @@ function setupController (initState, initLangCode) { storeTransform(versionifyData), createStreamSink(persistData), (error) => { - log.error('MetaMask - Persistence pipeline failed', error) + log.error('DekuSan - Persistence pipeline failed', error) } ) /** * Assigns the given state to the versioned object (with metadata), and returns that. - * @param {Object} state - The state object as emitted by the MetaMaskController. + * @param {Object} state - The state object as emitted by the DekuSanController. * @returns {VersionedData} The state object wrapped in an object that includes a metadata key. */ function versionifyData (state) { @@ -305,10 +314,10 @@ function setupController (initState, initLangCode) { async function persistData (state) { if (!state) { - throw new Error('MetaMask - updated state is missing', state) + throw new Error('DekuSan - updated state is missing', state) } if (!state.data) { - throw new Error('MetaMask - updated state does not have data', state) + throw new Error('DekuSan - updated state does not have data', state) } if (localStore.isSupported) { try { @@ -348,23 +357,27 @@ function setupController (initState, initLangCode) { */ /** - * Connects a Port to the MetaMask controller via a multiplexed duplex stream. - * This method identifies trusted (MetaMask) interfaces, and connects them differently from untrusted (web pages). + * Connects a Port to the DekuSan controller via a multiplexed duplex stream. + * This method identifies trusted (DekuSan) interfaces, and connects them differently from untrusted (web pages). * @param {Port} remotePort - The port provided by a new context. */ function connectRemote (remotePort) { const processName = remotePort.name - const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName] + const isDekuSanInternalProcess = metamaskInternalProcessHash[processName] +<<<<<<< HEAD if (metamaskBlacklistedPorts.includes(remotePort.name)) { return false } if (isMetaMaskInternalProcess) { +======= + if (isDekuSanInternalProcess) { +>>>>>>> Complete onboarding flow const portStream = new PortStream(remotePort) // communication with popup controller.isClientOpen = true - controller.setupTrustedCommunication(portStream, 'MetaMask') + controller.setupTrustedCommunication(portStream, 'DekuSan') if (processName === ENVIRONMENT_TYPE_POPUP) { popupIsOpen = true diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 92e382ea..195c32b4 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -19,7 +19,7 @@ let isEnabled = false // // But for now that is only Firefox // If we create a FireFox-only code path using that API, -// MetaMask will be much faster loading and performant on Firefox. +// DekuSan will be much faster loading and performant on Firefox. if (shouldInjectWeb3()) { injectScript(inpageBundle) @@ -76,7 +76,7 @@ function setupStreams () { pluginStream, approvalTransform, pageStream, - (err) => logStreamDisconnectWarning('MetaMask Contentscript Forwarding', err) + (err) => logStreamDisconnectWarning('DekuSan Contentscript Forwarding', err) ) // setup local multistream channels @@ -87,13 +87,13 @@ function setupStreams () { mux, pageStream, mux, - (err) => logStreamDisconnectWarning('MetaMask Inpage', err) + (err) => logStreamDisconnectWarning('DekuSan Inpage', err) ) pump( mux, pluginStream, mux, - (err) => logStreamDisconnectWarning('MetaMask Background', err) + (err) => logStreamDisconnectWarning('DekuSan Background', err) ) // connect ping stream @@ -102,7 +102,7 @@ function setupStreams () { mux, pongStream, mux, - (err) => logStreamDisconnectWarning('MetaMask PingPongStream', err) + (err) => logStreamDisconnectWarning('DekuSan PingPongStream', err) ) // connect phishing warning stream @@ -287,7 +287,7 @@ function blacklistedDomainCheck () { * Redirects the current page to a phishing information page */ function redirectToPhishingWarning () { - console.log('MetaMask - routing to Phishing Warning component') + console.log('DekuSan - routing to Phishing Warning component') const extensionURL = extension.runtime.getURL('phishing.html') window.location.href = `${extensionURL}#${querystring.stringify({ hostname: window.location.hostname, diff --git a/app/scripts/controllers/blacklist.js b/app/scripts/controllers/blacklist.js index e55b09d0..f52adebb 100644 --- a/app/scripts/controllers/blacklist.js +++ b/app/scripts/controllers/blacklist.js @@ -20,7 +20,7 @@ class BlacklistController { * @param {object} opts Overrides the defaults for the initial state of this.store * @property {object} store The the store of the current phishing config * @property {object} store.phishing Contains fuzzylist, whitelist and blacklist arrays. @see - * {@link https://github.com/MetaMask/eth-phishing-detect/blob/master/src/config.json} + * {@link https://github.com/DekuSan/eth-phishing-detect/blob/master/src/config.json} * @property {object} _phishingDetector The PhishingDetector instantiated by passing store.phishing to * PhishingDetector. * @property {object} _phishingUpdateIntervalRef Id of the interval created to periodically update the blacklist @@ -122,10 +122,10 @@ class BlacklistController { /** * Sets this._phishingDetector to a new PhishingDetector instance. - * @see {@link https://github.com/MetaMask/eth-phishing-detect} + * @see {@link https://github.com/DekuSan/eth-phishing-detect} * * @private - * @param {object} config A config object like that found at {@link https://github.com/MetaMask/eth-phishing-detect/blob/master/src/config.json} + * @param {object} config A config object like that found at {@link https://github.com/DekuSan/eth-phishing-detect/blob/master/src/config.json} * */ _setupPhishingDetector (config) { diff --git a/app/scripts/controllers/currency.js b/app/scripts/controllers/currency.js index fce65fd9..295046af 100644 --- a/app/scripts/controllers/currency.js +++ b/app/scripts/controllers/currency.js @@ -176,8 +176,12 @@ class CurrencyController { } } } catch (err) { +<<<<<<< HEAD // reset current conversion rate log.warn(`MetaMask - Failed to query currency conversion:`, nativeCurrency, currentCurrency, err) +======= + log.warn(`DekuSan - Failed to query currency conversion:`, currentCurrency, err) +>>>>>>> Complete onboarding flow this.setConversionRate(0) this.setConversionDate('N/A') // throw error diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js index 62e63979..fcf07bd5 100644 --- a/app/scripts/controllers/detect-tokens.js +++ b/app/scripts/controllers/detect-tokens.js @@ -53,7 +53,7 @@ class DetectTokensController { this._preferences.addToken(contractAddress, contracts[contractAddress].symbol, contracts[contractAddress].decimals) } } else { - warn(`MetaMask - DetectTokensController balance fetch failed for ${contractAddress}.`, error) + warn(`DekuSan - DetectTokensController balance fetch failed for ${contractAddress}.`, error) } }) } diff --git a/app/scripts/controllers/network/createMetamaskMiddleware.js b/app/scripts/controllers/network/createMetamaskMiddleware.js index 319c5bf3..7afeb07f 100644 --- a/app/scripts/controllers/network/createMetamaskMiddleware.js +++ b/app/scripts/controllers/network/createMetamaskMiddleware.js @@ -19,7 +19,7 @@ function createMetamaskMiddleware ({ createScaffoldMiddleware({ // staticSubprovider eth_syncing: false, - web3_clientVersion: `MetaMask/v${version}`, + web3_clientVersion: `DekuSan/v${version}`, }), createWalletSubprovider({ getAccounts, diff --git a/app/scripts/controllers/network/enums.js b/app/scripts/controllers/network/enums.js index 5a419105..586c0119 100644 --- a/app/scripts/controllers/network/enums.js +++ b/app/scripts/controllers/network/enums.js @@ -2,7 +2,7 @@ const ROPSTEN = 'ropsten' const RINKEBY = 'rinkeby' const KOVAN = 'kovan' const MAINNET = 'mainnet' -const TESTNET = 'testnet' +const TESTNET = 'rinkeby' const LOCALHOST = 'localhost' const MAINNET_CODE = 1 @@ -12,7 +12,7 @@ const RINKEYBY_CODE = 4 const KOVAN_CODE = 42 const ROPSTEN_DISPLAY_NAME = 'Ropsten' -const RINKEBY_DISPLAY_NAME = 'Rinkeby' +const RINKEBY_DISPLAY_NAME = 'DEXON' const KOVAN_DISPLAY_NAME = 'Kovan' const MAINNET_DISPLAY_NAME = 'Main DEXON Network' const TESTNET_DISPLAY_NAME = 'DEXON Test Network' diff --git a/app/scripts/controllers/network/network.js b/app/scripts/controllers/network/network.js index 3c893201..a9defca9 100644 --- a/app/scripts/controllers/network/network.js +++ b/app/scripts/controllers/network/network.js @@ -24,12 +24,13 @@ const { } = require('./enums') const INFURA_PROVIDER_TYPES = [MAINNET, TESTNET] -const env = process.env.METAMASK_ENV -const METAMASK_DEBUG = process.env.METAMASK_DEBUG -const testMode = (METAMASK_DEBUG || env === 'test') +// const env = process.env.METAMASK_ENV +// const METAMASK_DEBUG = process.env.METAMASK_DEBUG +// const testMode = (METAMASK_DEBUG || env === 'test') const defaultProviderConfig = { - type: testMode ? TESTNET : MAINNET, + // type: testMode ? TESTNET : MAINNET, + type: MAINNET, } const defaultNetworkConfig = { diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js index 3f948285..f9fb2aa4 100644 --- a/app/scripts/controllers/token-rates.js +++ b/app/scripts/controllers/token-rates.js @@ -47,6 +47,25 @@ class TokenRatesController { } /** +<<<<<<< HEAD +======= + * Fetches a token exchange rate by address + * + * @param {String} address - Token contract address + */ + async fetchExchangeRate (address) { + try { + const response = await fetch(`https://metamask.balanc3.net/prices?from=${address}&to=ETH&autoConversion=false&summaryOnly=true`) + const json = await response.json() + return json && json.length ? json[0].averagePrice : 0 + } catch (error) { + warn(`DekuSan - TokenRatesController exchange rate fetch failed for ${address}.`, error) + return 0 + } + } + + /** +>>>>>>> Complete onboarding flow * @type {Number} */ set interval (interval) { diff --git a/app/scripts/controllers/transactions/README.md b/app/scripts/controllers/transactions/README.md index b414762d..75e3749a 100644 --- a/app/scripts/controllers/transactions/README.md +++ b/app/scripts/controllers/transactions/README.md @@ -1,7 +1,7 @@ # Transaction Controller Transaction Controller is an aggregate of sub-controllers and trackers -exposed to the MetaMask controller. +exposed to the DekuSan controller. - txStateManager responsible for the state of a transaction and @@ -62,7 +62,7 @@ txMeta = { "gasPriceSpecified": false, //whether or not the user/dapp has specified gasPrice "gasLimitSpecified": false, //whether or not the user/dapp has specified gas "estimatedGas": "5208", - "origin": "MetaMask", //debug + "origin": "DekuSan", //debug "nonceDetails": { "params": { "highestLocallyConfirmed": 0, diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 2ce736be..8fbc3cbc 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -143,7 +143,7 @@ class TransactionController extends EventEmitter { */ async newUnapprovedTransaction (txParams, opts = {}) { - log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`) + log.debug(`DekuSanController newUnapprovedTransaction ${JSON.stringify(txParams)}`) const initialTxMeta = await this.addUnapprovedTransaction(txParams) initialTxMeta.origin = opts.origin this.txStateManager.updateTx(initialTxMeta, '#newUnapprovedTransaction - adding the origin') @@ -154,11 +154,11 @@ class TransactionController extends EventEmitter { case 'submitted': return resolve(finishedTxMeta.hash) case 'rejected': - return reject(cleanErrorStack(new Error('MetaMask Tx Signature: User denied transaction signature.'))) + return reject(cleanErrorStack(new Error('DekuSan Tx Signature: User denied transaction signature.'))) case 'failed': return reject(cleanErrorStack(new Error(finishedTxMeta.err.message))) default: - return reject(cleanErrorStack(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))) + return reject(cleanErrorStack(new Error(`DekuSan Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))) } }) }) diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index b2556a27..bde7d9e6 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -178,7 +178,7 @@ function cleanContextForImports () { try { global.define = undefined } catch (_) { - console.warn('MetaMask - global.define could not be deleted.') + console.warn('DekuSan - global.define could not be deleted.') } } @@ -189,6 +189,6 @@ function restoreContextAfterImports () { try { global.define = __define } catch (_) { - console.warn('MetaMask - global.define could not be overwritten.') + console.warn('DekuSan - global.define could not be overwritten.') } } diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 170d508c..55f3fb6f 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -27,7 +27,7 @@ async function getFirstPreferredLangCode () { } // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages - // https://github.com/MetaMask/metamask-extension/issues/4270 + // https://github.com/DekuSan/metamask-extension/issues/4270 if (!userPreferredLocaleCodes) { userPreferredLocaleCodes = [] } diff --git a/app/scripts/lib/message-manager.js b/app/scripts/lib/message-manager.js index e8662959..de028849 100644 --- a/app/scripts/lib/message-manager.js +++ b/app/scripts/lib/message-manager.js @@ -12,7 +12,7 @@ const createId = require('./random-id') * @typedef {Object} Message * @property {number} id An id to track and identify the message object * @property {Object} msgParams The parameters to pass to the eth_sign method once the signature request is approved. - * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within DekuSan. * @property {string} msgParams.data A hex string conversion of the raw buffer data of the signature request * @property {number} time The epoch time at which the this message was created * @property {string} status Indicates whether the signature request is 'unapproved', 'approved', 'signed' or 'rejected' @@ -82,9 +82,9 @@ module.exports = class MessageManager extends EventEmitter { case 'signed': return resolve(data.rawSig) case 'rejected': - return reject(new Error('MetaMask Message Signature: User denied message signature.')) + return reject(new Error('DekuSan Message Signature: User denied message signature.')) default: - return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) + return reject(new Error(`DekuSan Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) } }) }) @@ -147,8 +147,8 @@ module.exports = class MessageManager extends EventEmitter { * Approves a Message. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise with * any the message params modified for proper signing. * - * @param {Object} msgParams The msgParams to be used when eth_sign is called, plus data added by MetaMask. - * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @param {Object} msgParams The msgParams to be used when eth_sign is called, plus data added by DekuSan. + * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within DekuSan. * @returns {Promise<object>} Promises the msgParams object with metamaskId removed. * */ diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index 345ca800..94c21318 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -47,7 +47,7 @@ class Migrator extends EventEmitter { } catch (err) { // rewrite error message to add context without clobbering stack const originalErrorMessage = err.message - err.message = `MetaMask Migration Error #${migration.version}: ${originalErrorMessage}` + err.message = `DekuSan Migration Error #${migration.version}: ${originalErrorMessage}` console.warn(err.stack) // emit error instead of throw so as to not break the run (gracefully fail) this.emit('error', err) diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js index 969a9459..830b72b9 100644 --- a/app/scripts/lib/notification-manager.js +++ b/app/scripts/lib/notification-manager.js @@ -13,7 +13,7 @@ class NotificationManager { */ /** - * Either brings an existing MetaMask notification window into focus, or creates a new notification window. New + * Either brings an existing DekuSan notification window into focus, or creates a new notification window. New * notification windows are given a 'popup' type. * */ @@ -40,7 +40,7 @@ class NotificationManager { } /** - * Closes a MetaMask notification if it window exists. + * Closes a DekuSan notification if it window exists. * */ closePopup () { @@ -53,7 +53,7 @@ class NotificationManager { } /** - * Checks all open MetaMask windows, and returns the first one it finds that is a notification window (i.e. has the + * Checks all open DekuSan windows, and returns the first one it finds that is a notification window (i.e. has the * type 'popup') * * @private @@ -68,7 +68,7 @@ class NotificationManager { } /** - * Returns all open MetaMask windows. + * Returns all open DekuSan windows. * * @private * @param {Function} cb A node style callback that to which the windows will be passed. @@ -86,10 +86,10 @@ class NotificationManager { } /** - * Given an array of windows, returns the 'popup' that has been opened by MetaMask, or null if no such window exists. + * Given an array of windows, returns the 'popup' that has been opened by DekuSan, or null if no such window exists. * * @private - * @param {array} windows An array of objects containing data about the open MetaMask extension windows. + * @param {array} windows An array of objects containing data about the open DekuSan extension windows. * */ _getPopupIn (windows) { diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js index fdb94f5e..333f4f93 100644 --- a/app/scripts/lib/personal-message-manager.js +++ b/app/scripts/lib/personal-message-manager.js @@ -15,7 +15,7 @@ const log = require('loglevel') * @property {number} id An id to track and identify the message object * @property {Object} msgParams The parameters to pass to the personal_sign method once the signature request is * approved. - * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within DekuSan. * @property {string} msgParams.data A hex string conversion of the raw buffer data of the signature request * @property {number} time The epoch time at which the this message was created * @property {string} status Indicates whether the signature request is 'unapproved', 'approved', 'signed' or 'rejected' @@ -80,7 +80,7 @@ module.exports = class PersonalMessageManager extends EventEmitter { addUnapprovedMessageAsync (msgParams, req) { return new Promise((resolve, reject) => { if (!msgParams.from) { - reject(new Error('MetaMask Message Signature: from field is required.')) + reject(new Error('DekuSan Message Signature: from field is required.')) } const msgId = this.addUnapprovedMessage(msgParams, req) this.once(`${msgId}:finished`, (data) => { @@ -88,9 +88,9 @@ module.exports = class PersonalMessageManager extends EventEmitter { case 'signed': return resolve(data.rawSig) case 'rejected': - return reject(new Error('MetaMask Message Signature: User denied message signature.')) + return reject(new Error('DekuSan Message Signature: User denied message signature.')) default: - return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) + return reject(new Error(`DekuSan Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) } }) }) @@ -156,8 +156,8 @@ module.exports = class PersonalMessageManager extends EventEmitter { * Approves a PersonalMessage. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise * with any the message params modified for proper signing. * - * @param {Object} msgParams The msgParams to be used when eth_sign is called, plus data added by MetaMask. - * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @param {Object} msgParams The msgParams to be used when eth_sign is called, plus data added by DekuSan. + * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within DekuSan. * @returns {Promise<object>} Promises the msgParams object with metamaskId removed. * */ diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js new file mode 100644 index 00000000..6719a6fc --- /dev/null +++ b/app/scripts/lib/resolver.js @@ -0,0 +1,71 @@ +const namehash = require('eth-ens-namehash') +const multihash = require('multihashes') +const HttpProvider = require('ethjs-provider-http') +const Eth = require('ethjs-query') +const EthContract = require('ethjs-contract') +const registrarAbi = require('./contracts/registrar') +const resolverAbi = require('./contracts/resolver') + +function ens (name, provider) { + const eth = new Eth(new HttpProvider(getProvider(provider.type))) + const hash = namehash.hash(name) + const contract = new EthContract(eth) + const Registrar = contract(registrarAbi).at(getRegistrar(provider.type)) + return new Promise((resolve, reject) => { + if (provider.type === 'mainnet' || provider.type === 'ropsten') { + Registrar.resolver(hash).then((address) => { + if (address === '0x0000000000000000000000000000000000000000') { + reject(null) + } else { + const Resolver = contract(resolverAbi).at(address['0']) + return Resolver.content(hash) + } + }).then((contentHash) => { + if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null) + if (contentHash.ret !== '0x') { + const hex = contentHash['0'].substring(2) + const buf = multihash.fromHexString(hex) + resolve(multihash.toB58String(multihash.encode(buf, 'sha2-256'))) + } else { + reject(null) + } + }) + } else { + return reject('unsupport') + } + }) +} + +function getProvider (type) { + switch (type) { + case 'mainnet': + return 'https://mainnet.infura.io/' + case 'testnet': + return 'http://testnet.dexon.org:8545/' + default: + return 'http://localhost:8545/' + } +} + +function getRegistrar (type) { + switch (type) { + case 'mainnet': + return '0x314159265dd8dbb310642f98f50c066173c1259b' + case 'testnet': + return '0x314159265dd8dbb310642f98f50c066173c1259b' + default: + return '0x0000000000000000000000000000000000000000' + } +} + +module.exports.resolve = function (name, provider) { + const path = name.split('.') + const topLevelDomain = path[path.length - 1] + if (topLevelDomain === 'eth' || topLevelDomain === 'test') { + return ens(name, provider) + } else { + return new Promise((resolve, reject) => { + reject(null) + }) + } +} diff --git a/app/scripts/lib/setupMetamaskMeshMetrics.js b/app/scripts/lib/setupMetamaskMeshMetrics.js index fd3b93fc..b7c2e519 100644 --- a/app/scripts/lib/setupMetamaskMeshMetrics.js +++ b/app/scripts/lib/setupMetamaskMeshMetrics.js @@ -7,6 +7,6 @@ module.exports = setupMetamaskMeshMetrics function setupMetamaskMeshMetrics () { const testingContainer = document.createElement('iframe') testingContainer.src = 'https://metamask.github.io/mesh-testing/' - console.log('Injecting MetaMask Mesh testing client') + console.log('Injecting DekuSan Mesh testing client') document.head.appendChild(testingContainer) } diff --git a/app/scripts/lib/typed-message-manager.js b/app/scripts/lib/typed-message-manager.js index b10145f3..ef1e8820 100644 --- a/app/scripts/lib/typed-message-manager.js +++ b/app/scripts/lib/typed-message-manager.js @@ -14,7 +14,7 @@ const jsonschema = require('jsonschema') * @property {number} id An id to track and identify the message object * @property {Object} msgParams The parameters to pass to the eth_signTypedData method once the signature request is * approved. - * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @property {Object} msgParams.metamaskId Added to msgParams for tracking and identification within DekuSan. * @property {Object} msgParams.from The address that is making the signature request. * @property {string} msgParams.data A hex string conversion of the raw buffer data of the signature request * @property {number} time The epoch time at which the this message was created @@ -78,11 +78,11 @@ module.exports = class TypedMessageManager extends EventEmitter { case 'signed': return resolve(data.rawSig) case 'rejected': - return reject(new Error('MetaMask Message Signature: User denied message signature.')) + return reject(new Error('DekuSan Message Signature: User denied message signature.')) case 'errored': - return reject(new Error(`MetaMask Message Signature: ${data.error}`)) + return reject(new Error(`DekuSan Message Signature: ${data.error}`)) default: - return reject(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) + return reject(new Error(`DekuSan Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) } }) }) @@ -186,8 +186,8 @@ module.exports = class TypedMessageManager extends EventEmitter { * Approves a TypedMessage. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise * with any the message params modified for proper signing. * - * @param {Object} msgParams The msgParams to be used when eth_sign is called, plus data added by MetaMask. - * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. + * @param {Object} msgParams The msgParams to be used when eth_sign is called, plus data added by DekuSan. + * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within DekuSan. * @returns {Promise<object>} Promises the msgParams object with metamaskId removed. * */ diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index c7e9cfcc..e81b8ea4 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1,6 +1,6 @@ /** * @file The central metamask controller. Aggregates other controllers and exports an api. - * @copyright Copyright (c) 2018 MetaMask + * @copyright Copyright (c) 2018 DekuSan * @license MIT */ @@ -281,7 +281,7 @@ module.exports = class MetamaskController extends EventEmitter { const providerOpts = { static: { eth_syncing: false, - web3_clientVersion: `MetaMask/v${version}`, + web3_clientVersion: `DekuSan/v${version}`, }, version, // account mgmt @@ -917,7 +917,7 @@ module.exports = class MetamaskController extends EventEmitter { * @returns {Promise<Object>} Full state update. */ signMessage (msgParams) { - log.info('MetaMaskController - signMessage') + log.info('DekuSanController - signMessage') const msgId = msgParams.metamaskId // sets the status op the message to 'approved' @@ -976,7 +976,7 @@ module.exports = class MetamaskController extends EventEmitter { * @returns {Promise<Object>} - A full state update. */ signPersonalMessage (msgParams) { - log.info('MetaMaskController - signPersonalMessage') + log.info('DekuSanController - signPersonalMessage') const msgId = msgParams.metamaskId // sets the status op the message to 'approved' // and removes the metamaskId for signing @@ -1029,7 +1029,7 @@ module.exports = class MetamaskController extends EventEmitter { * @returns {Object} Full state update. */ async signTypedMessage (msgParams) { - log.info('MetaMaskController - eth_signTypedData') + log.info('DekuSanController - eth_signTypedData') const msgId = msgParams.metamaskId const version = msgParams.version try { @@ -1056,7 +1056,7 @@ module.exports = class MetamaskController extends EventEmitter { this.typedMessageManager.setMsgStatusSigned(msgId, signature) return this.getState() } catch (error) { - log.info('MetaMaskController - eth_signTypedData failed.', error) + log.info('DekuSanController - eth_signTypedData failed.', error) this.typedMessageManager.errorMessage(msgId, error) } } @@ -1075,7 +1075,7 @@ module.exports = class MetamaskController extends EventEmitter { } // --------------------------------------------------------------------------- - // MetaMask Version 3 Migration Account Restauration Methods + // DekuSan Version 3 Migration Account Restauration Methods /** * A legacy method (probably dead code) that was used when we swapped out our @@ -1155,7 +1155,7 @@ module.exports = class MetamaskController extends EventEmitter { * transaction. * @param {number} originalTxId - the id of the txMeta that you want to attempt to cancel * @param {string=} customGasPrice - the hex value to use for the cancel transaction - * @returns {object} MetaMask state + * @returns {object} DekuSan state */ async createCancelTransaction (originalTxId, customGasPrice, cb) { try { @@ -1223,7 +1223,7 @@ module.exports = class MetamaskController extends EventEmitter { setupUntrustedCommunication (connectionStream, originDomain) { // Check if new connection is blacklisted if (this.blacklistController.checkForPhishing(originDomain)) { - log.debug('MetaMask - sending phishing warning for', originDomain) + log.debug('DekuSan - sending phishing warning for', originDomain) this.sendPhishingWarning(connectionStream, originDomain) return } @@ -1394,7 +1394,7 @@ module.exports = class MetamaskController extends EventEmitter { } /** - * A method for emitting the full MetaMask state to all registered listeners. + * A method for emitting the full DekuSan state to all registered listeners. * @private */ privateSendUpdate () { @@ -1568,7 +1568,7 @@ module.exports = class MetamaskController extends EventEmitter { // TODO: Replace isClientOpen methods with `controllerConnectionChanged` events. /** - * A method for recording whether the MetaMask user interface is open or not. + * A method for recording whether the DekuSan user interface is open or not. * @private * @param {boolean} open */ diff --git a/app/scripts/migrations/005.js b/app/scripts/migrations/005.js index f7b68dfe..6c9e1b08 100644 --- a/app/scripts/migrations/005.js +++ b/app/scripts/migrations/005.js @@ -21,7 +21,7 @@ module.exports = { const newState = selectSubstateForKeyringController(state) versionedData.data = newState } catch (err) { - console.warn('MetaMask Migration #5' + err.stack) + console.warn('DekuSan Migration #5' + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/006.js b/app/scripts/migrations/006.js index 51ea6e3e..f27dc804 100644 --- a/app/scripts/migrations/006.js +++ b/app/scripts/migrations/006.js @@ -20,7 +20,7 @@ module.exports = { const newState = migrateState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/007.js b/app/scripts/migrations/007.js index d9887b9c..f48d9606 100644 --- a/app/scripts/migrations/007.js +++ b/app/scripts/migrations/007.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/008.js b/app/scripts/migrations/008.js index da7cb2e6..1d20cb72 100644 --- a/app/scripts/migrations/008.js +++ b/app/scripts/migrations/008.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/009.js b/app/scripts/migrations/009.js index f47db55a..833fcc9d 100644 --- a/app/scripts/migrations/009.js +++ b/app/scripts/migrations/009.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/010.js b/app/scripts/migrations/010.js index e4b9ac07..c1d45984 100644 --- a/app/scripts/migrations/010.js +++ b/app/scripts/migrations/010.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/011.js b/app/scripts/migrations/011.js index 782ec809..1fe5531a 100644 --- a/app/scripts/migrations/011.js +++ b/app/scripts/migrations/011.js @@ -19,7 +19,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/012.js b/app/scripts/migrations/012.js index f69ccbb0..87818a1a 100644 --- a/app/scripts/migrations/012.js +++ b/app/scripts/migrations/012.js @@ -19,7 +19,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/013.js b/app/scripts/migrations/013.js index fb7131f8..ec756ccd 100644 --- a/app/scripts/migrations/013.js +++ b/app/scripts/migrations/013.js @@ -19,7 +19,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/014.js b/app/scripts/migrations/014.js index 0fe92125..b5cc1d2e 100644 --- a/app/scripts/migrations/014.js +++ b/app/scripts/migrations/014.js @@ -19,7 +19,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/015.js b/app/scripts/migrations/015.js index 5e2f9e63..549200f5 100644 --- a/app/scripts/migrations/015.js +++ b/app/scripts/migrations/015.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/016.js b/app/scripts/migrations/016.js index 048c7a40..a7c53666 100644 --- a/app/scripts/migrations/016.js +++ b/app/scripts/migrations/016.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/017.js b/app/scripts/migrations/017.js index 5f6d906d..fc92b4c4 100644 --- a/app/scripts/migrations/017.js +++ b/app/scripts/migrations/017.js @@ -19,7 +19,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/018.js b/app/scripts/migrations/018.js index ffbf24a4..003f9ebb 100644 --- a/app/scripts/migrations/018.js +++ b/app/scripts/migrations/018.js @@ -21,7 +21,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/019.js b/app/scripts/migrations/019.js index ce5da685..46a56d90 100644 --- a/app/scripts/migrations/019.js +++ b/app/scripts/migrations/019.js @@ -21,7 +21,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/020.js b/app/scripts/migrations/020.js index 8159b3e7..f0937753 100644 --- a/app/scripts/migrations/020.js +++ b/app/scripts/migrations/020.js @@ -21,7 +21,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/021.js b/app/scripts/migrations/021.js index d84e77b5..b9ff4776 100644 --- a/app/scripts/migrations/021.js +++ b/app/scripts/migrations/021.js @@ -19,7 +19,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/022.js b/app/scripts/migrations/022.js index 1fbe241e..ed341e88 100644 --- a/app/scripts/migrations/022.js +++ b/app/scripts/migrations/022.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/023.js b/app/scripts/migrations/023.js index 18493a78..cdd92515 100644 --- a/app/scripts/migrations/023.js +++ b/app/scripts/migrations/023.js @@ -20,7 +20,7 @@ module.exports = { const newState = transformState(state) versionedData.data = newState } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) } return Promise.resolve(versionedData) }, diff --git a/app/scripts/migrations/026.js b/app/scripts/migrations/026.js index 4e907e09..4f7593e9 100644 --- a/app/scripts/migrations/026.js +++ b/app/scripts/migrations/026.js @@ -18,7 +18,7 @@ module.exports = { const state = versionedData.data versionedData.data = transformState(state) } catch (err) { - console.warn(`MetaMask Migration #${version}` + err.stack) + console.warn(`DekuSan Migration #${version}` + err.stack) return Promise.reject(err) } return Promise.resolve(versionedData) diff --git a/app/scripts/popup-core.js b/app/scripts/popup-core.js index db885ec9..f455ec53 100644 --- a/app/scripts/popup-core.js +++ b/app/scripts/popup-core.js @@ -10,7 +10,7 @@ const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex module.exports = initializePopup /** - * Asynchronously initializes the MetaMask popup UI + * Asynchronously initializes the DekuSan popup UI * * @param {{ container: Element, connectionStream: * }} config Popup configuration object * @param {Function} cb Called when initialization is complete diff --git a/app/scripts/ui.js b/app/scripts/ui.js index 682a4aaa..3d8c0b9a 100644 --- a/app/scripts/ui.js +++ b/app/scripts/ui.js @@ -1,5 +1,4 @@ const injectCss = require('inject-css') -const OldMetaMaskUiCss = require('../../old-ui/css') const NewMetaMaskUiCss = require('../../ui/css') const {getShouldUseNewUi} = require('../../ui/app/selectors') const startPopup = require('./popup-core') @@ -47,6 +46,7 @@ async function start () { const container = document.getElementById('app-content') startPopup({ container, connectionStream }, (err, store) => { if (err) return displayCriticalError(err) +<<<<<<< HEAD const state = store.getState() let betaUIState = Boolean(state.featureFlags && state.featureFlags.betaUI) @@ -66,6 +66,9 @@ async function start () { deleteInjectedCss = injectCss(css) } }) +======= + injectCss(NewMetaMaskUiCss()) +>>>>>>> Complete onboarding flow }) |