-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8682 from brave/wallet-page
New Wallet page and common state for panel and page
- Loading branch information
Showing
21 changed files
with
384 additions
and
117 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
components/brave_wallet_ui/common/reducers/wallet_reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/* global window */ | ||
|
||
import { createReducer } from 'redux-act' | ||
import { WalletState } from '../../constants/types' | ||
|
||
const defaultState: WalletState = { | ||
} | ||
|
||
const reducer = createReducer<WalletState>({}, defaultState) | ||
|
||
export default reducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
components/brave_wallet_ui/page/actions/wallet_page_actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { createAction } from 'redux-act' | ||
import { InitializedPayloadType } from '../constants/action_types' | ||
|
||
export const initialize = createAction('initialize') | ||
export const initialized = createAction<InitializedPayloadType>('initialized') |
29 changes: 29 additions & 0 deletions
29
components/brave_wallet_ui/page/async/wallet_page_async_handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import { MiddlewareAPI, Dispatch, AnyAction } from 'redux' | ||
import AsyncActionHandler from '../../../common/AsyncActionHandler' | ||
import * as Actions from '../actions/wallet_page_actions' | ||
import { PageState, WalletPageState } from '../../constants/types' | ||
|
||
const handler = new AsyncActionHandler() | ||
|
||
function getPageState (store: MiddlewareAPI<Dispatch<AnyAction>, any>): PageState { | ||
return (store.getState() as WalletPageState).page | ||
} | ||
|
||
handler.on(Actions.initialize.getType(), async (store) => { | ||
const state = getPageState(store) | ||
// Sanity check we only initialize once | ||
if (state.hasInitialized) { | ||
return | ||
} | ||
// TODO: Fetch any data we need for initial display, instead of fake wait. | ||
await new Promise(resolve => setTimeout(resolve, 400)) | ||
store.dispatch(Actions.initialized({ isConnected: true })) | ||
return | ||
}) | ||
|
||
export default handler.middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
export type InitializedPayloadType = { | ||
isConnected: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import * as React from 'react' | ||
import { connect } from 'react-redux' | ||
import { bindActionCreators, Dispatch } from 'redux' | ||
|
||
import * as WalletPageActions from './actions/wallet_page_actions' | ||
import store from './store' | ||
|
||
import 'emptykit.css' | ||
import '../../../ui/webui/resources/fonts/poppins.css' | ||
import '../../../ui/webui/resources/fonts/muli.css' | ||
|
||
import { WalletWidgetStandIn } from '../stories/style' | ||
import { | ||
SideNav, | ||
WalletPageLayout, | ||
WalletSubViewLayout, | ||
CryptoView | ||
} from '../components/desktop' | ||
import { | ||
NavTypes, | ||
NavObjectType, | ||
WalletState, | ||
PageState, | ||
WalletPageState | ||
} from '../constants/types' | ||
import { LinkedAccountsOptions, NavOptions, StaticOptions } from '../options/side-nav-options' | ||
import BuySendSwap from '../components/buy-send-swap' | ||
|
||
type Props = { | ||
wallet: WalletState | ||
page: PageState | ||
actions: typeof WalletPageActions | ||
} | ||
|
||
function Container (props: Props) { | ||
const [view, setView] = React.useState<NavTypes>('crypto') | ||
const [linkedAccounts] = React.useState<NavObjectType[]>(LinkedAccountsOptions) | ||
|
||
// In the future these will be actual paths | ||
// for example wallet/rewards | ||
const navigateTo = (path: NavTypes) => { | ||
setView(path) | ||
} | ||
|
||
return ( | ||
<WalletPageLayout> | ||
<SideNav | ||
navList={NavOptions} | ||
staticList={StaticOptions} | ||
selectedButton={view} | ||
onSubmit={navigateTo} | ||
linkedAccountsList={linkedAccounts} | ||
/> | ||
<WalletSubViewLayout> | ||
{view === 'crypto' ? ( | ||
<CryptoView /> | ||
) : ( | ||
<div style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
<h2>{view} view</h2> | ||
</div> | ||
)} | ||
|
||
</WalletSubViewLayout> | ||
<WalletWidgetStandIn> | ||
<BuySendSwap /> | ||
</WalletWidgetStandIn> | ||
</WalletPageLayout> | ||
) | ||
} | ||
|
||
function mapStateToProps (state: WalletPageState): Partial<Props> { | ||
return { | ||
page: state.page, | ||
wallet: state.wallet | ||
} | ||
} | ||
|
||
function mapDispatchToProps (dispatch: Dispatch): Partial<Props> { | ||
return { | ||
actions: bindActionCreators(WalletPageActions, store.dispatch.bind(store)) | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Container) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { combineReducers } from 'redux' | ||
|
||
import pageReducer from './page_reducer' | ||
import walletReducer from '../../common/reducers/wallet_reducer' | ||
|
||
export default combineReducers({ | ||
page: pageReducer, | ||
wallet: walletReducer | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/* global window */ | ||
|
||
import { createReducer } from 'redux-act' | ||
import * as Actions from '../actions/wallet_page_actions' | ||
import { PageState } from '../../constants/types' | ||
import { InitializedPayloadType } from '../constants/action_types' | ||
|
||
const defaultState: PageState = { | ||
hasInitialized: false | ||
} | ||
|
||
const reducer = createReducer<PageState>({}, defaultState) | ||
|
||
reducer.on(Actions.initialized, (state: PageState, payload: InitializedPayloadType) => { | ||
return { | ||
...state, | ||
hasInitialized: true, | ||
isConnected: payload.isConnected | ||
} | ||
}) | ||
|
||
export default reducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { createStore, applyMiddleware } from 'redux' | ||
|
||
// Utils | ||
import reducers from './reducers' | ||
import walletPageAsyncHandler from './async/wallet_page_async_handler' | ||
|
||
export default createStore( | ||
reducers, | ||
applyMiddleware(walletPageAsyncHandler) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.