Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes panel actions for uphold limit (uplift to 1.12.x) #6219

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,16 @@ export class RewardsPanel extends React.Component<Props, State> {
actions.push({
name: getMessage('addFunds'),
action: this.openRewardsAddFunds,
icon: <WalletAddIcon />
icon: <WalletAddIcon />,
externalWallet: true
})
}

return actions.concat([{
name: getMessage('rewardsSettings'),
action: this.openRewards,
icon: <BatColorIcon />
icon: <BatColorIcon />,
externalWallet: false
}])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,16 @@ export class Panel extends React.Component<Props, State> {
actions.push({
name: getMessage('addFunds'),
action: this.onAddFunds,
icon: <WalletAddIcon />
icon: <WalletAddIcon />,
externalWallet: true
})
}

return actions.concat([{
name: getMessage('rewardsSettings'),
action: this.openRewardsPage,
icon: <BatColorIcon />
icon: <BatColorIcon />,
externalWallet: false
}])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,15 @@ class PageWallet extends React.Component<Props, State> {
name: getLocale('panelAddFunds'),
action: this.onFundsAction.bind(this, 'add'),
icon: <WalletAddIcon />,
testId: 'panel-add-funds'
testId: 'panel-add-funds',
externalWallet: true
},
{
name: getLocale('panelWithdrawFunds'),
action: this.onFundsAction.bind(this, 'withdraw'),
icon: <WalletWithdrawIcon />,
testId: 'panel-withdraw-funds'
testId: 'panel-withdraw-funds',
externalWallet: true
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface ActionWallet {
name: string
action: () => void
testId?: string
externalWallet: boolean
}

export type NotificationType =
Expand Down Expand Up @@ -175,17 +176,33 @@ export default class WalletWrapper extends React.PureComponent<Props, State> {
}
}

generateActions (actions: { icon: React.ReactNode, name: string, testId?: string, action: () => void }[], id?: string) {
generateActions (actions: ActionWallet[], id?: string) {
return actions && actions.map((action, i: number) => {
let clickAction = action.externalWallet ? this.onActionClick.bind(this, action.action) : action.action
return (
<StyledAction key={`${id}-${i}`} onClick={action.action} data-test-id={action.testId}>
<StyledAction key={`${id}-${i}`} onClick={clickAction} data-test-id={action.testId}>
<StyledActionIcon>{action.icon}</StyledActionIcon>
<StyledActionText>{action.name}</StyledActionText>
</StyledAction>
)
})
}

onActionClick = (action: () => void) => {
if (!action) {
return
}

if (!this.props.showLoginMessage) {
action()
return
}

this.setState({
showLoginMessage: true
})
}

onNotificationClick = () => {
if (this.props.onNotificationClick) {
this.props.onNotificationClick()
Expand Down Expand Up @@ -323,27 +340,12 @@ export default class WalletWrapper extends React.PureComponent<Props, State> {
)
}

walletButtonClicked = () => {
if (!this.props.onVerifyClick) {
return
}

if (!this.props.showLoginMessage) {
this.props.onVerifyClick()
return
}

this.setState({
showLoginMessage: true
})
}

generateWalletButton = (walletState: WalletState) => {
const buttonProps: Partial<ButtonProps> = {
size: 'small',
level: 'primary',
brand: 'rewards',
onClick: this.walletButtonClicked
onClick: this.onActionClick.bind(this, this.props.onVerifyClick)
}

switch (walletState) {
Expand Down Expand Up @@ -774,7 +776,7 @@ export default class WalletWrapper extends React.PureComponent<Props, State> {
onVerifyClick
? <>
{' ('}
<StyledLink onClick={onVerifyClick}>
<StyledLink onClick={this.onActionClick.bind(this, this.props.onVerifyClick)}>
{getLocale('rewardsPanelTextVerify')}
</StyledLink>
{')'}
Expand Down
12 changes: 8 additions & 4 deletions components/brave_rewards/resources/ui/stories/concepts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,14 @@ storiesOf('Rewards/Concepts/Desktop', module)
{
name: 'Add funds',
action: doNothing,
icon: <WalletAddIcon />
icon: <WalletAddIcon />,
externalWallet: true
},
{
name: 'Settings',
action: doNothing,
icon: <BatColorIcon />
icon: <BatColorIcon />,
externalWallet: false
}
]}
showSecActions={false}
Expand Down Expand Up @@ -451,12 +453,14 @@ storiesOf('Rewards/Concepts/Desktop', module)
{
name: 'Add funds',
action: doNothing,
icon: <WalletAddIcon />
icon: <WalletAddIcon />,
externalWallet: true
},
{
name: 'Settings',
action: doNothing,
icon: <BatColorIcon />
icon: <BatColorIcon />,
externalWallet: false
}
]}
showCopy={boolean('Show Uphold', false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,14 @@ class PageWallet extends React.Component<Props, State> {
name: 'Add funds',
action: doNothing,
icon: <WalletAddIcon />,
testId: 'panel-add-funds'
testId: 'panel-add-funds',
externalWallet: true
},
{
name: 'Withdraw Funds',
action: doNothing,
icon: <WalletWithdrawIcon />
icon: <WalletWithdrawIcon />,
externalWallet: true
}
]}
compact={false}
Expand Down
6 changes: 4 additions & 2 deletions components/brave_rewards/resources/ui/stories/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ storiesOf('Rewards/Wallet/Desktop', module)
{
name: 'Add funds',
action: doNothing,
icon: <WalletAddIcon />
icon: <WalletAddIcon />,
externalWallet: true
},
{
name: 'Withdraw Funds',
action: doNothing,
icon: <WalletImportIcon />
icon: <WalletImportIcon />,
externalWallet: true
}
]}
grants={showGrant ? [
Expand Down