Delete uneeded files from old-ui.

feature/default_network_editable
Dan 7 years ago committed by Chi Kei Chan
parent 8defb365b4
commit 800eb2b969
  1. 1128
      old-ui/app/actions.js
  2. 76
      old-ui/app/reducers.js
  3. 599
      old-ui/app/reducers/app.js
  4. 15
      old-ui/app/reducers/identities.js
  5. 166
      old-ui/app/reducers/metamask.js
  6. 23
      old-ui/app/root.js
  7. 21
      old-ui/app/store.js
  8. 20
      old-ui/index.html
  9. 58
      old-ui/index.js

File diff suppressed because it is too large Load Diff

@ -1,76 +0,0 @@
const extend = require('xtend')
const copyToClipboard = require('copy-to-clipboard')
//
// Sub-Reducers take in the complete state and return their sub-state
//
const reduceIdentities = require('./reducers/identities')
const reduceMetamask = require('./reducers/metamask')
const reduceApp = require('./reducers/app')
window.METAMASK_CACHED_LOG_STATE = null
module.exports = rootReducer
function rootReducer (state, action) {
// clone
state = extend(state)
if (action.type === 'GLOBAL_FORCE_UPDATE') {
return action.value
}
//
// Identities
//
state.identities = reduceIdentities(state, action)
//
// MetaMask
//
state.metamask = reduceMetamask(state, action)
//
// AppState
//
state.appState = reduceApp(state, action)
window.METAMASK_CACHED_LOG_STATE = state
return state
}
window.logStateString = function (cb) {
const state = window.METAMASK_CACHED_LOG_STATE
const version = global.platform.getVersion()
const browser = window.navigator.userAgent
return global.platform.getPlatformInfo((err, platform) => {
if (err) {
return cb(err)
}
state.version = version
state.platform = platform
state.browser = browser
const stateString = JSON.stringify(state, removeSeedWords, 2)
return cb(null, stateString)
})
}
window.logState = function (toClipboard) {
return window.logStateString((err, result) => {
if (err) {
console.error(err.message)
} else if (toClipboard) {
copyToClipboard(result)
console.log('State log copied')
} else {
console.log(result)
}
})
}
function removeSeedWords (key, value) {
return key === 'seedWords' ? undefined : value
}

@ -1,599 +0,0 @@
const extend = require('xtend')
const actions = require('../../../ui/app/actions')
const txHelper = require('../../lib/tx-helper')
module.exports = reduceApp
function reduceApp (state, action) {
log.debug('App Reducer got ' + action.type)
// clone and defaults
const selectedAddress = state.metamask.selectedAddress
const hasUnconfActions = checkUnconfActions(state)
let name = 'accounts'
if (selectedAddress) {
name = 'accountDetail'
}
if (hasUnconfActions) {
log.debug('pending txs detected, defaulting to conf-tx view.')
name = 'confTx'
}
var defaultView = {
name,
detailView: null,
context: selectedAddress,
}
// confirm seed words
var seedWords = state.metamask.seedWords
var seedConfView = {
name: 'createVaultComplete',
seedWords,
}
// default state
var appState = extend({
shouldClose: false,
menuOpen: false,
currentView: seedWords ? seedConfView : defaultView,
accountDetail: {
subview: 'transactions',
},
// Used to render transition direction
transForward: true,
// Used to display loading indicator
isLoading: false,
// Used to display error text
warning: null,
}, state.appState)
switch (action.type) {
// transition methods
case actions.TRANSITION_FORWARD:
return extend(appState, {
transForward: true,
})
case actions.TRANSITION_BACKWARD:
return extend(appState, {
transForward: false,
})
// intialize
case actions.SHOW_CREATE_VAULT:
return extend(appState, {
currentView: {
name: 'createVault',
},
transForward: true,
warning: null,
})
case actions.SHOW_RESTORE_VAULT:
return extend(appState, {
currentView: {
name: 'restoreVault',
},
transForward: true,
forgottenPassword: true,
})
case actions.FORGOT_PASSWORD:
return extend(appState, {
currentView: {
name: 'restoreVault',
},
transForward: false,
forgottenPassword: true,
})
case actions.SHOW_INIT_MENU:
return extend(appState, {
currentView: defaultView,
transForward: false,
})
case actions.SHOW_CONFIG_PAGE:
return extend(appState, {
currentView: {
name: 'config',
context: appState.currentView.context,
},
transForward: action.value,
})
case actions.SHOW_ADD_TOKEN_PAGE:
return extend(appState, {
currentView: {
name: 'add-token',
context: appState.currentView.context,
},
transForward: action.value,
})
case actions.SHOW_IMPORT_PAGE:
return extend(appState, {
currentView: {
name: 'import-menu',
},
transForward: true,
warning: null,
})
case actions.SHOW_INFO_PAGE:
return extend(appState, {
currentView: {
name: 'info',
context: appState.currentView.context,
},
transForward: true,
})
case actions.CREATE_NEW_VAULT_IN_PROGRESS:
return extend(appState, {
currentView: {
name: 'createVault',
inProgress: true,
},
transForward: true,
isLoading: true,
})
case actions.SHOW_NEW_VAULT_SEED:
return extend(appState, {
currentView: {
name: 'createVaultComplete',
seedWords: action.value,
},
transForward: true,
isLoading: false,
})
case actions.NEW_ACCOUNT_SCREEN:
return extend(appState, {
currentView: {
name: 'new-account',
context: appState.currentView.context,
},
transForward: true,
})
case actions.SHOW_SEND_PAGE:
return extend(appState, {
currentView: {
name: 'sendTransaction',
context: appState.currentView.context,
},
transForward: true,
warning: null,
})
case actions.SHOW_NEW_KEYCHAIN:
return extend(appState, {
currentView: {
name: 'newKeychain',
context: appState.currentView.context,
},
transForward: true,
})
// unlock
case actions.UNLOCK_METAMASK:
return extend(appState, {
forgottenPassword: appState.forgottenPassword ? !appState.forgottenPassword : null,
detailView: {},
transForward: true,
isLoading: false,
warning: null,
})
case actions.LOCK_METAMASK:
return extend(appState, {
currentView: defaultView,
transForward: false,
warning: null,
})
case actions.BACK_TO_INIT_MENU:
return extend(appState, {
warning: null,
transForward: false,
forgottenPassword: true,
currentView: {
name: 'InitMenu',
},
})
case actions.BACK_TO_UNLOCK_VIEW:
return extend(appState, {
warning: null,
transForward: true,
forgottenPassword: false,
currentView: {
name: 'UnlockScreen',
},
})
// reveal seed words
case actions.REVEAL_SEED_CONFIRMATION:
return extend(appState, {
currentView: {
name: 'reveal-seed-conf',
},
transForward: true,
warning: null,
})
// accounts
case actions.SET_SELECTED_ACCOUNT:
return extend(appState, {
activeAddress: action.value,
})
case actions.GO_HOME:
return extend(appState, {
currentView: extend(appState.currentView, {
name: 'accountDetail',
}),
accountDetail: {
subview: 'transactions',
accountExport: 'none',
privateKey: '',
},
transForward: false,
warning: null,
})
case actions.SHOW_ACCOUNT_DETAIL:
return extend(appState, {
forgottenPassword: appState.forgottenPassword ? !appState.forgottenPassword : null,
currentView: {
name: 'accountDetail',
context: action.value,
},
accountDetail: {
subview: 'transactions',
accountExport: 'none',
privateKey: '',
},
transForward: false,
})
case actions.BACK_TO_ACCOUNT_DETAIL:
return extend(appState, {
currentView: {
name: 'accountDetail',
context: action.value,
},
accountDetail: {
subview: 'transactions',
accountExport: 'none',
privateKey: '',
},
transForward: false,
})
case actions.SHOW_ACCOUNTS_PAGE:
return extend(appState, {
currentView: {
name: seedWords ? 'createVaultComplete' : 'accounts',
seedWords,
},
transForward: true,
isLoading: false,
warning: null,
scrollToBottom: false,
forgottenPassword: false,
})
case actions.SHOW_NOTICE:
return extend(appState, {
transForward: true,
isLoading: false,
})
case actions.REVEAL_ACCOUNT:
return extend(appState, {
scrollToBottom: true,
})
case actions.SHOW_CONF_TX_PAGE:
return extend(appState, {
currentView: {
name: 'confTx',
context: 0,
},
transForward: action.transForward,
warning: null,
isLoading: false,
})
case actions.SHOW_CONF_MSG_PAGE:
return extend(appState, {
currentView: {
name: hasUnconfActions ? 'confTx' : 'account-detail',
context: 0,
},
transForward: true,
warning: null,
isLoading: false,
})
case actions.COMPLETED_TX:
log.debug('reducing COMPLETED_TX for tx ' + action.value)
const otherUnconfActions = getUnconfActionList(state)
.filter(tx => tx.id !== action.value)
const hasOtherUnconfActions = otherUnconfActions.length > 0
if (hasOtherUnconfActions) {
log.debug('reducer detected txs - rendering confTx view')
return extend(appState, {
transForward: false,
currentView: {
name: 'confTx',
context: 0,
},
warning: null,
})
} else {
log.debug('attempting to close popup')
return extend(appState, {
// indicate notification should close
shouldClose: true,
transForward: false,
warning: null,
currentView: {
name: 'accountDetail',
context: state.metamask.selectedAddress,
},
accountDetail: {
subview: 'transactions',
},
})
}
case actions.NEXT_TX:
return extend(appState, {
transForward: true,
currentView: {
name: 'confTx',
context: ++appState.currentView.context,
warning: null,
},
})
case actions.VIEW_PENDING_TX:
const context = indexForPending(state, action.value)
return extend(appState, {
transForward: true,
currentView: {
name: 'confTx',
context,
warning: null,
},
})
case actions.PREVIOUS_TX:
return extend(appState, {
transForward: false,
currentView: {
name: 'confTx',
context: --appState.currentView.context,
warning: null,
},
})
case actions.TRANSACTION_ERROR:
return extend(appState, {
currentView: {
name: 'confTx',
errorMessage: 'There was a problem submitting this transaction.',
},
})
case actions.UNLOCK_FAILED:
return extend(appState, {
warning: action.value || 'Incorrect password. Try again.',
})
case actions.SHOW_LOADING:
return extend(appState, {
isLoading: true,
loadingMessage: action.value,
})
case actions.HIDE_LOADING:
return extend(appState, {
isLoading: false,
})
case actions.SHOW_SUB_LOADING_INDICATION:
return extend(appState, {
isSubLoading: true,
})
case actions.HIDE_SUB_LOADING_INDICATION:
return extend(appState, {
isSubLoading: false,
})
case actions.CLEAR_SEED_WORD_CACHE:
return extend(appState, {
transForward: true,
currentView: {},
isLoading: false,
accountDetail: {
subview: 'transactions',
accountExport: 'none',
privateKey: '',
},
})
case actions.DISPLAY_WARNING:
return extend(appState, {
warning: action.value,
isLoading: false,
})
case actions.HIDE_WARNING:
return extend(appState, {
warning: undefined,
})
case actions.REQUEST_ACCOUNT_EXPORT:
return extend(appState, {
transForward: true,
currentView: {
name: 'accountDetail',
context: appState.currentView.context,
},
accountDetail: {
subview: 'export',
accountExport: 'requested',
},
})
case actions.EXPORT_ACCOUNT:
return extend(appState, {
accountDetail: {
subview: 'export',
accountExport: 'completed',
},
})
case actions.SHOW_PRIVATE_KEY:
return extend(appState, {
accountDetail: {
subview: 'export',
accountExport: 'completed',
privateKey: action.value,
},
})
case actions.BUY_ETH_VIEW:
return extend(appState, {
transForward: true,
currentView: {
name: 'buyEth',
context: appState.currentView.name,
},
identity: state.metamask.identities[action.value],
buyView: {
subview: 'Coinbase',
amount: '15.00',
buyAddress: action.value,
formView: {
coinbase: true,
shapeshift: false,
},
},
})
case actions.ONBOARDING_BUY_ETH_VIEW:
return extend(appState, {
transForward: true,
currentView: {
name: 'onboardingBuyEth',
context: appState.currentView.name,
},
identity: state.metamask.identities[action.value],
})
case actions.COINBASE_SUBVIEW:
return extend(appState, {
buyView: {
subview: 'Coinbase',
formView: {
coinbase: true,
shapeshift: false,
},
buyAddress: appState.buyView.buyAddress,
amount: appState.buyView.amount,
},
})
case actions.SHAPESHIFT_SUBVIEW:
return extend(appState, {
buyView: {
subview: 'ShapeShift',
formView: {
coinbase: false,
shapeshift: true,
marketinfo: action.value.marketinfo,
coinOptions: action.value.coinOptions,
},
buyAddress: appState.buyView.buyAddress,
amount: appState.buyView.amount,
},
})
case actions.PAIR_UPDATE:
return extend(appState, {
buyView: {
subview: 'ShapeShift',
formView: {
coinbase: false,
shapeshift: true,
marketinfo: action.value.marketinfo,
coinOptions: appState.buyView.formView.coinOptions,
},
buyAddress: appState.buyView.buyAddress,
amount: appState.buyView.amount,
warning: null,
},
})
case actions.SHOW_QR:
return extend(appState, {
qrRequested: true,
transForward: true,
Qr: {
message: action.value.message,
data: action.value.data,
},
})
case actions.SHOW_QR_VIEW:
return extend(appState, {
currentView: {
name: 'qr',
context: appState.currentView.context,
},
transForward: true,
Qr: {
message: action.value.message,
data: action.value.data,
},
})
default:
return appState
}
}
function checkUnconfActions (state) {
const unconfActionList = getUnconfActionList(state)
const hasUnconfActions = unconfActionList.length > 0
return hasUnconfActions
}
function getUnconfActionList (state) {
const { unapprovedTxs, unapprovedMsgs,
unapprovedPersonalMsgs, unapprovedTypedMessages, network } = state.metamask
const unconfActionList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, network)
return unconfActionList
}
function indexForPending (state, txId) {
const unconfTxList = getUnconfActionList(state)
const match = unconfTxList.find((tx) => tx.id === txId)
const index = unconfTxList.indexOf(match)
return index
}

@ -1,15 +0,0 @@
const extend = require('xtend')
module.exports = reduceIdentities
function reduceIdentities (state, action) {
// clone + defaults
var idState = extend({
}, state.identities)
switch (action.type) {
default:
return idState
}
}

@ -1,166 +0,0 @@
const extend = require('xtend')
const actions = require('../../../ui/app/actions')
const MetamascaraPlatform = require('../../../app/scripts/platforms/window')
module.exports = reduceMetamask
function reduceMetamask (state, action) {
let newState
// clone + defaults
var metamaskState = extend({
isInitialized: false,
isUnlocked: false,
isMascara: window.platform instanceof MetamascaraPlatform,
rpcTarget: 'https://rawtestrpc.metamask.io/',
identities: {},
unapprovedTxs: {},
noActiveNotices: true,
lastUnreadNotice: undefined,
frequentRpcList: [],
addressBook: [],
tokenExchangeRates: {},
coinOptions: {},
featureFlags: {},
}, state.metamask)
switch (action.type) {
case actions.SHOW_ACCOUNTS_PAGE:
newState = extend(metamaskState)
delete newState.seedWords
return newState
case actions.SHOW_NOTICE:
return extend(metamaskState, {
noActiveNotices: false,
lastUnreadNotice: action.value,
})
case actions.CLEAR_NOTICES:
return extend(metamaskState, {
noActiveNotices: true,
})
case actions.UPDATE_METAMASK_STATE:
return extend(metamaskState, action.value)
case actions.UNLOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
})
case actions.LOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: false,
})
case actions.SET_RPC_LIST:
return extend(metamaskState, {
frequentRpcList: action.value,
})
case actions.SET_RPC_TARGET:
return extend(metamaskState, {
provider: {
type: 'rpc',
rpcTarget: action.value,
},
})
case actions.SET_PROVIDER_TYPE:
return extend(metamaskState, {
provider: {
type: action.value,
},
})
case actions.COMPLETED_TX:
var stringId = String(action.id)
newState = extend(metamaskState, {
unapprovedTxs: {},
unapprovedMsgs: {},
})
for (const id in metamaskState.unapprovedTxs) {
if (id !== stringId) {
newState.unapprovedTxs[id] = metamaskState.unapprovedTxs[id]
}
}
for (const id in metamaskState.unapprovedMsgs) {
if (id !== stringId) {
newState.unapprovedMsgs[id] = metamaskState.unapprovedMsgs[id]
}
}
return newState
case actions.SHOW_NEW_VAULT_SEED:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: false,
seedWords: action.value,
})
case actions.CLEAR_SEED_WORD_CACHE:
newState = extend(metamaskState, {
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
})
delete newState.seedWords
return newState
case actions.SHOW_ACCOUNT_DETAIL:
newState = extend(metamaskState, {
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
})
delete newState.seedWords
return newState
case actions.SAVE_ACCOUNT_LABEL:
const account = action.value.account
const name = action.value.label
var id = {}
id[account] = extend(metamaskState.identities[account], { name })
var identities = extend(metamaskState.identities, id)
return extend(metamaskState, { identities })
case actions.SET_CURRENT_FIAT:
return extend(metamaskState, {
currentCurrency: action.value.currentCurrency,
conversionRate: action.value.conversionRate,
conversionDate: action.value.conversionDate,
})
case actions.PAIR_UPDATE:
const { value: { marketinfo: pairMarketInfo } } = action
return extend(metamaskState, {
tokenExchangeRates: {
...metamaskState.tokenExchangeRates,
[pairMarketInfo.pair]: pairMarketInfo,
},
})
case actions.SHAPESHIFT_SUBVIEW:
const { value: { marketinfo, coinOptions } } = action
return extend(metamaskState, {
tokenExchangeRates: {
...metamaskState.tokenExchangeRates,
[marketinfo.pair]: marketinfo,
},
coinOptions,
})
case actions.UPDATE_FEATURE_FLAGS:
return extend(metamaskState, {
featureFlags: action.value,
})
default:
return metamaskState
}
}

@ -1,23 +0,0 @@
const inherits = require('util').inherits
const Component = require('react').Component
const Provider = require('react-redux').Provider
const h = require('react-hyperscript')
const App = require('./app')
module.exports = Root
inherits(Root, Component)
function Root () { Component.call(this) }
Root.prototype.render = function () {
console.log(123454)
return (
h(Provider, {
store: this.props.store,
}, [
h(App),
])
)
}

@ -1,21 +0,0 @@
const createStore = require('redux').createStore
const applyMiddleware = require('redux').applyMiddleware
const thunkMiddleware = require('redux-thunk').default
const rootReducer = require('./reducers')
const createLogger = require('redux-logger').createLogger
global.METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
module.exports = configureStore
const loggerMiddleware = createLogger({
predicate: () => global.METAMASK_DEBUG,
})
const middlewares = [thunkMiddleware, loggerMiddleware]
const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore)
function configureStore (initialState) {
return createStoreWithMiddleware(rootReducer, initialState)
}

@ -1,20 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>MetaMask</title>
</head>
<body>
<!-- app content -->
<div id="app-content"></div>
<script src="./bundle.js" type="text/javascript" charset="utf-8"></script>
<!-- design reference -->
<link rel="stylesheet" type="text/css" href="./app/css/debug.css">
<div id="design-container">
<img id="design-img" src="./design/metamask_wfs_jan_13.png">
</div>
</body>
</html>

@ -1,58 +0,0 @@
const render = require('react-dom').render
const h = require('react-hyperscript')
const Root = require('./app/root')
const actions = require('./app/actions')
const configureStore = require('./app/store')
const txHelper = require('./lib/tx-helper')
global.log = require('loglevel')
module.exports = launchMetamaskUi
log.setLevel(global.METAMASK_DEBUG ? 'debug' : 'warn')
function launchMetamaskUi (opts, cb) {
var accountManager = opts.accountManager
actions._setBackgroundConnection(accountManager)
// check if we are unlocked first
accountManager.getState(function (err, metamaskState) {
if (err) return cb(err)
const store = startApp(metamaskState, accountManager, opts)
cb(null, store)
})
}
function startApp (metamaskState, accountManager, opts) {
// parse opts
const store = configureStore({
// metamaskState represents the cross-tab state
metamask: metamaskState,
// appState represents the current tab's popup state
appState: {},
// Which blockchain we are using:
networkVersion: opts.networkVersion,
})
// if unconfirmed txs, start on txConf page
const unapprovedTxsAll = txHelper(metamaskState.unapprovedTxs, metamaskState.unapprovedMsgs, metamaskState.unapprovedPersonalMsgs, metamaskState.unapprovedTypedMessages, metamaskState.network)
if (unapprovedTxsAll.length > 0) {
store.dispatch(actions.showConfTxPage())
}
accountManager.on('update', function (metamaskState) {
store.dispatch(actions.updateMetamaskState(metamaskState))
})
// start app
render(
h(Root, {
// inject initial state
store: store,
}
), opts.container)
return store
}
Loading…
Cancel
Save