diff options
author | Francesco Agosti <francesco.agosti93@gmail.com> | 2018-11-14 09:31:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-14 09:31:38 +0800 |
commit | 4fc457b78b30e761164eac26fe5f1ebcddd11f7d (patch) | |
tree | 05a0d01029815d36370f8548d365289f555e8be4 /packages/instant/src/redux/reducer.ts | |
parent | e02dc13805349a770506350c69e9061f596b48b2 (diff) | |
parent | 2f6b1273aaf621beebcbc70af4bb6c5f4a8217a3 (diff) | |
download | dexon-sol-tools-4fc457b78b30e761164eac26fe5f1ebcddd11f7d.tar dexon-sol-tools-4fc457b78b30e761164eac26fe5f1ebcddd11f7d.tar.gz dexon-sol-tools-4fc457b78b30e761164eac26fe5f1ebcddd11f7d.tar.bz2 dexon-sol-tools-4fc457b78b30e761164eac26fe5f1ebcddd11f7d.tar.lz dexon-sol-tools-4fc457b78b30e761164eac26fe5f1ebcddd11f7d.tar.xz dexon-sol-tools-4fc457b78b30e761164eac26fe5f1ebcddd11f7d.tar.zst dexon-sol-tools-4fc457b78b30e761164eac26fe5f1ebcddd11f7d.zip |
Merge pull request #1242 from 0xProject/feature/instant/metamask-connect-flow
[instant] Install/Unlock MetaMask, connect PaymentDropdown to redux state
Diffstat (limited to 'packages/instant/src/redux/reducer.ts')
-rw-r--r-- | packages/instant/src/redux/reducer.ts | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 77c99627a..dfc2b89f3 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -19,6 +19,8 @@ import { OrderProcessState, OrderState, ProviderState, + StandardSlidingPanelContent, + StandardSlidingPanelSettings, } from '../types'; import { Action, ActionTypes } from './actions'; @@ -30,6 +32,7 @@ export interface DefaultState { buyOrderState: OrderState; latestErrorDisplayStatus: DisplayStatus; quoteRequestState: AsyncProcessState; + standardSlidingPanelSettings: StandardSlidingPanelSettings; } // State that is required but needs to be derived from the props @@ -56,6 +59,10 @@ export const DEFAULT_STATE: DefaultState = { buyOrderState: { processState: OrderProcessState.None }, latestErrorDisplayStatus: DisplayStatus.Hidden, quoteRequestState: AsyncProcessState.None, + standardSlidingPanelSettings: { + animationState: 'none', + content: StandardSlidingPanelContent.None, + }, }; export const createReducer = (initialState: State) => { @@ -66,11 +73,19 @@ export const createReducer = (initialState: State) => { case ActionTypes.SET_ACCOUNT_STATE_LOCKED: return reduceStateWithAccount(state, LOCKED_ACCOUNT); case ActionTypes.SET_ACCOUNT_STATE_READY: { - const account: AccountReady = { + const address = action.data; + let newAccount: AccountReady = { state: AccountState.Ready, - address: action.data, + address, }; - return reduceStateWithAccount(state, account); + const currentAccount = state.providerState.account; + if (currentAccount.state === AccountState.Ready && currentAccount.address === address) { + newAccount = { + ...newAccount, + ethBalanceInWei: currentAccount.ethBalanceInWei, + }; + } + return reduceStateWithAccount(state, newAccount); } case ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE: { const { address, ethBalanceInWei } = action.data; @@ -211,6 +226,22 @@ export const createReducer = (initialState: State) => { ...state, availableAssets: action.data, }; + case ActionTypes.OPEN_STANDARD_SLIDING_PANEL: + return { + ...state, + standardSlidingPanelSettings: { + content: action.data, + animationState: 'slidIn', + }, + }; + case ActionTypes.CLOSE_STANDARD_SLIDING_PANEL: + return { + ...state, + standardSlidingPanelSettings: { + content: state.standardSlidingPanelSettings.content, + animationState: 'slidOut', + }, + }; default: return state; } |