diff options
author | Chi Kei Chan <chikeichan@gmail.com> | 2017-10-19 13:58:46 +0800 |
---|---|---|
committer | Chi Kei Chan <chikeichan@gmail.com> | 2017-10-19 13:58:46 +0800 |
commit | c8c773d6416f92c520a509a9811d73f68aa00fc0 (patch) | |
tree | 495a798eeb4a5272c80d93725f5146a6fbcf85c8 /ui/app/reducers | |
parent | 5bdee96e73f65a0b369277e9c56b0afe5159e65b (diff) | |
parent | de1da7d1b215ade650fc644adf63384a401dc240 (diff) | |
download | tangerine-wallet-browser-c8c773d6416f92c520a509a9811d73f68aa00fc0.tar tangerine-wallet-browser-c8c773d6416f92c520a509a9811d73f68aa00fc0.tar.gz tangerine-wallet-browser-c8c773d6416f92c520a509a9811d73f68aa00fc0.tar.bz2 tangerine-wallet-browser-c8c773d6416f92c520a509a9811d73f68aa00fc0.tar.lz tangerine-wallet-browser-c8c773d6416f92c520a509a9811d73f68aa00fc0.tar.xz tangerine-wallet-browser-c8c773d6416f92c520a509a9811d73f68aa00fc0.tar.zst tangerine-wallet-browser-c8c773d6416f92c520a509a9811d73f68aa00fc0.zip |
Merge branch 'NewUI-flat' into merge
Diffstat (limited to 'ui/app/reducers')
-rw-r--r-- | ui/app/reducers/app.js | 133 | ||||
-rw-r--r-- | ui/app/reducers/metamask.js | 110 |
2 files changed, 210 insertions, 33 deletions
diff --git a/ui/app/reducers/app.js b/ui/app/reducers/app.js index 349c25b96..f10bf9fb7 100644 --- a/ui/app/reducers/app.js +++ b/ui/app/reducers/app.js @@ -14,6 +14,7 @@ function reduceApp (state, action) { if (selectedAddress) { name = 'accountDetail' } + if (hasUnconfActions) { log.debug('pending txs detected, defaulting to conf-tx view.') name = 'confTx' @@ -36,6 +37,17 @@ function reduceApp (state, action) { var appState = extend({ shouldClose: false, menuOpen: false, + modal: { + open: false, + modalState: { + name: null, + }, + previousModalState: { + name: null, + } + }, + sidebarOpen: false, + networkDropdownOpen: false, currentView: seedWords ? seedConfView : defaultView, accountDetail: { subview: 'transactions', @@ -49,9 +61,50 @@ function reduceApp (state, action) { }, state.appState) switch (action.type) { + // dropdown methods + case actions.NETWORK_DROPDOWN_OPEN: + return extend(appState, { + networkDropdownOpen: true, + }) - // transition methods + case actions.NETWORK_DROPDOWN_CLOSE: + return extend(appState, { + networkDropdownOpen: false, + }) + + // sidebar methods + case actions.SIDEBAR_OPEN: + return extend(appState, { + sidebarOpen: true, + }) + + case actions.SIDEBAR_CLOSE: + return extend(appState, { + sidebarOpen: false, + }) + + // modal methods: + case actions.MODAL_OPEN: + return extend(appState, { + modal: Object.assign( + state.appState.modal, + { open: true }, + { modalState: action.payload }, + { previousModalState: appState.modal.modalState}, + ), + }) + + case actions.MODAL_CLOSE: + return extend(appState, { + modal: Object.assign( + state.appState.modal, + { open: false }, + { modalState: { name: null } }, + { previousModalState: appState.modal.modalState}, + ), + }) + // transition methods case actions.TRANSITION_FORWARD: return extend(appState, { transForward: true, @@ -133,7 +186,7 @@ function reduceApp (state, action) { transForward: true, }) - case actions.CREATE_NEW_VAULT_IN_PROGRESS: + case actions.CREATE_NEW_VAULT_IN_PROGRESS: return extend(appState, { currentView: { name: 'createVault', @@ -172,6 +225,16 @@ function reduceApp (state, action) { warning: null, }) + case actions.SHOW_SEND_TOKEN_PAGE: + return extend(appState, { + currentView: { + name: 'sendToken', + context: appState.currentView.context, + }, + transForward: true, + warning: null, + }) + case actions.SHOW_NEW_KEYCHAIN: return extend(appState, { currentView: { @@ -307,7 +370,7 @@ function reduceApp (state, action) { return extend(appState, { currentView: { name: 'confTx', - context: 0, + context: action.id ? indexForPending(state, action.id) : indexForLastPending(state), }, transForward: action.transForward, warning: null, @@ -327,36 +390,36 @@ function reduceApp (state, action) { 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', - }, - }) - } + // 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, { @@ -586,3 +649,7 @@ function indexForPending (state, txId) { const index = unconfTxList.indexOf(match) return index } + +function indexForLastPending (state) { + return getUnconfActionList(state).length +} diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js index e0c416c2d..fb2b2e674 100644 --- a/ui/app/reducers/metamask.js +++ b/ui/app/reducers/metamask.js @@ -10,6 +10,7 @@ function reduceMetamask (state, action) { var metamaskState = extend({ isInitialized: false, isUnlocked: false, + isAccountMenuOpen: false, rpcTarget: 'https://rawtestrpc.metamask.io/', identities: {}, unapprovedTxs: {}, @@ -17,6 +18,19 @@ function reduceMetamask (state, action) { lastUnreadNotice: undefined, frequentRpcList: [], addressBook: [], + selectedTokenAddress: null, + tokenExchangeRates: {}, + tokens: [], + send: { + gasLimit: null, + gasPrice: null, + gasTotal: null, + from: '', + to: '', + amount: '0x0', + memo: '', + errors: {}, + }, }, state.metamask) switch (action.type) { @@ -115,6 +129,11 @@ function reduceMetamask (state, action) { delete newState.seedWords return newState + case actions.SET_SELECTED_TOKEN: + return extend(metamaskState, { + selectedTokenAddress: action.value, + }) + case actions.SAVE_ACCOUNT_LABEL: const account = action.value.account const name = action.value.label @@ -130,6 +149,97 @@ function reduceMetamask (state, action) { conversionDate: action.value.conversionDate, }) + case actions.UPDATE_TOKEN_EXCHANGE_RATE: + const { payload: { pair, marketinfo } } = action + return extend(metamaskState, { + tokenExchangeRates: { + ...metamaskState.tokenExchangeRates, + [pair]: marketinfo, + }, + }) + + case actions.UPDATE_TOKENS: + return extend(metamaskState, { + tokens: action.newTokens, + }) + + // metamask.send + case actions.UPDATE_GAS_LIMIT: + return extend(metamaskState, { + send: { + ...metamaskState.send, + gasLimit: action.value, + }, + }) + + case actions.UPDATE_GAS_PRICE: + return extend(metamaskState, { + send: { + ...metamaskState.send, + gasPrice: action.value, + }, + }) + + case actions.TOGGLE_ACCOUNT_MENU: + return extend(metamaskState, { + isAccountMenuOpen: !metamaskState.isAccountMenuOpen, + }) + + case actions.UPDATE_GAS_TOTAL: + return extend(metamaskState, { + send: { + ...metamaskState.send, + gasTotal: action.value, + }, + }) + + case actions.UPDATE_SEND_FROM: + return extend(metamaskState, { + send: { + ...metamaskState.send, + from: action.value, + }, + }) + + case actions.UPDATE_SEND_TO: + return extend(metamaskState, { + send: { + ...metamaskState.send, + to: action.value, + }, + }) + + case actions.UPDATE_SEND_AMOUNT: + return extend(metamaskState, { + send: { + ...metamaskState.send, + amount: action.value, + }, + }) + + case actions.UPDATE_SEND_MEMO: + return extend(metamaskState, { + send: { + ...metamaskState.send, + memo: action.value, + }, + }) + + case actions.UPDATE_SEND_ERRORS: + console.log(123, { + ...metamaskState.send.errors, + ...action.value, + }) + return extend(metamaskState, { + send: { + ...metamaskState.send, + errors: { + ...metamaskState.send.errors, + ...action.value, + } + }, + }) + default: return metamaskState |