diff options
Diffstat (limited to 'packages/instant/src/containers')
-rw-r--r-- | packages/instant/src/containers/connected_account_payment_method.ts | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/packages/instant/src/containers/connected_account_payment_method.ts b/packages/instant/src/containers/connected_account_payment_method.ts index ee57d1829..c20af67cc 100644 --- a/packages/instant/src/containers/connected_account_payment_method.ts +++ b/packages/instant/src/containers/connected_account_payment_method.ts @@ -4,34 +4,61 @@ import { Dispatch } from 'redux'; import { PaymentMethod } from '../components/payment_method'; import { Action, actions } from '../redux/actions'; +import { asyncData } from '../redux/async_data'; import { State } from '../redux/reducer'; -import { Account, Network, StandardSlidingPanelContent } from '../types'; +import { Account, Network, ProviderState, StandardSlidingPanelContent } from '../types'; export interface ConnectedAccountPaymentMethodProps {} interface ConnectedState { - account: Account; network: Network; + providerState: ProviderState; } interface ConnectedDispatch { - openStandardSlidingPanel: (content: StandardSlidingPanelContent) => void; + onInstallWalletClick: () => void; + unlockWalletAndDispatchToStore: (providerState: ProviderState) => void; +} + +interface ConnectedProps { + onInstallWalletClick: () => void; + onUnlockWalletClick: () => void; + account: Account; + network: Network; } +type FinalProps = ConnectedProps & ConnectedAccountPaymentMethodProps; + const mapStateToProps = (state: State, _ownProps: ConnectedAccountPaymentMethodProps): ConnectedState => ({ - account: state.providerState.account, network: state.network, + providerState: state.providerState, }); const mapDispatchToProps = ( dispatch: Dispatch<Action>, ownProps: ConnectedAccountPaymentMethodProps, ): ConnectedDispatch => ({ - openStandardSlidingPanel: (content: StandardSlidingPanelContent) => - dispatch(actions.openStandardSlidingPanel(content)), + onInstallWalletClick: () => dispatch(actions.openStandardSlidingPanel(StandardSlidingPanelContent.InstallWallet)), + unlockWalletAndDispatchToStore: async (providerState: ProviderState) => + asyncData.fetchAccountInfoAndDispatchToStore(providerState, dispatch, true), +}); + +const mergeProps = ( + connectedState: ConnectedState, + connectedDispatch: ConnectedDispatch, + ownProps: ConnectedAccountPaymentMethodProps, +): FinalProps => ({ + ...ownProps, + network: connectedState.network, + account: connectedState.providerState.account, + onInstallWalletClick: connectedDispatch.onInstallWalletClick, + onUnlockWalletClick: () => { + connectedDispatch.unlockWalletAndDispatchToStore(connectedState.providerState); + }, }); export const ConnectedAccountPaymentMethod: React.ComponentClass<ConnectedAccountPaymentMethodProps> = connect( mapStateToProps, mapDispatchToProps, + mergeProps, )(PaymentMethod); |