From 0587bfd7b196d1db4df63b3df8244dd2d3ed480b Mon Sep 17 00:00:00 2001 From: Nejc Zdovc Date: Thu, 18 Oct 2018 05:24:53 -0700 Subject: [PATCH] Merge pull request #689 from brave/wallet-failed Adds wallet creation failed flow --- browser/ui/webui/brave_webui_source.cc | 3 ++ .../brave_rewards/components/panel.tsx | 1 - .../brave_rewards/ui/components/app.tsx | 49 +++++++++++++++---- .../ui/reducers/wallet_reducer.ts | 3 ++ .../resources/brave_components_resources.grd | 3 ++ 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index be5b1d99f2ef..fc06aa2cf3bf 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -385,6 +385,9 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource* { "walletActivity", IDS_BRAVE_UI_WALLET_ACTIVITY }, { "walletAddress", IDS_BRAVE_UI_WALLET_ADDRESS }, { "walletBalance", IDS_BRAVE_UI_WALLET_BALANCE }, + { "walletFailedButton", IDS_BRAVE_UI_WALLET_FAILED_BUTTON }, + { "walletFailedTitle", IDS_BRAVE_UI_WALLET_FAILED_TITLE }, + { "walletFailedText", IDS_BRAVE_UI_WALLET_FAILED_TEXT }, { "welcome", IDS_BRAVE_UI_WELCOME }, { "welcomeButtonTextOne", IDS_BRAVE_UI_WELCOME_BUTTON_TEXT_ONE}, { "welcomeButtonTextTwo", IDS_BRAVE_UI_WELCOME_BUTTON_TEXT_TWO}, diff --git a/components/brave_rewards/extension/brave_rewards/components/panel.tsx b/components/brave_rewards/extension/brave_rewards/components/panel.tsx index 049ea6e43b50..4316973ec12c 100644 --- a/components/brave_rewards/extension/brave_rewards/components/panel.tsx +++ b/components/brave_rewards/extension/brave_rewards/components/panel.tsx @@ -246,7 +246,6 @@ export class Panel extends React.Component { tipsEnabled={true} includeInAuto={!publisher.excluded} attentionScore={(publisher.percentage || 0).toString()} - donationAmounts={[]} onToggleTips={this.doNothing} donationAction={this.showDonateToSiteDetail} onAmountChange={this.doNothing} diff --git a/components/brave_rewards/ui/components/app.tsx b/components/brave_rewards/ui/components/app.tsx index 90b6a9fe2520..a26a93f234f8 100644 --- a/components/brave_rewards/ui/components/app.tsx +++ b/components/brave_rewards/ui/components/app.tsx @@ -16,15 +16,41 @@ import { WelcomePage } from 'brave-ui/features/rewards' interface Props extends Rewards.ComponentProps { } -export class App extends React.Component { +interface State { + creating: boolean +} + +export class App extends React.Component { + constructor (props: Props) { + super(props) + this.state = { + creating: false + } + } + componentDidMount () { if (!this.props.rewardsData.walletCreated) { this.actions.checkWalletExistence() } } + componentDidUpdate (prevProps: Props, prevState: State) { + if ( + this.state.creating && + !prevProps.rewardsData.walletCreateFailed && + this.props.rewardsData.walletCreateFailed + ) { + this.setState({ + creating: false + }) + } + } + onCreateWalletClicked = () => { this.actions.createWallet() + this.setState({ + creating: true + }) } get actions () { @@ -32,27 +58,32 @@ export class App extends React.Component { } render () { - const { rewardsData } = this.props + const { walletCreated, walletCreateFailed } = this.props.rewardsData + + let props: {onReTry?: () => void} = {} + + if (walletCreateFailed) { + props = { + onReTry: this.onCreateWalletClicked + } + } return (
{ - !rewardsData.walletCreated && !rewardsData.walletCreateFailed + !walletCreated ? : null } { - rewardsData.walletCreated + walletCreated ? : null } - { - rewardsData.walletCreateFailed - ?
Wallet Create Failed!
- : null - }
) } diff --git a/components/brave_rewards/ui/reducers/wallet_reducer.ts b/components/brave_rewards/ui/reducers/wallet_reducer.ts index 3b9491951a75..ea379f8e74a8 100644 --- a/components/brave_rewards/ui/reducers/wallet_reducer.ts +++ b/components/brave_rewards/ui/reducers/wallet_reducer.ts @@ -26,6 +26,9 @@ const createWallet = (state: Rewards.State) => { const walletReducer: Reducer = (state: Rewards.State, action) => { switch (action.type) { case types.CREATE_WALLET: + state = { ...state } + state.walletCreateFailed = false + state.walletCreated = false chrome.send('brave_rewards.createWalletRequested', []) break case types.WALLET_CREATED: diff --git a/components/resources/brave_components_resources.grd b/components/resources/brave_components_resources.grd index 4647fd525871..34b18594e19f 100644 --- a/components/resources/brave_components_resources.grd +++ b/components/resources/brave_components_resources.grd @@ -415,6 +415,9 @@ Wallet Activity Wallet Address wallet balance + Try again + Wallet creation failed + Please check your internet connection. Welcome! Start Earning Now! Join Rewards