-
Notifications
You must be signed in to change notification settings - Fork 96
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 #3890 from LiskHQ/3889-disable-register-delegate-l…
…ink-in-btc Disable register delegate link in BTC and explorer
- Loading branch information
Showing
5 changed files
with
237 additions
and
90 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/components/screens/wallet/overview/balanceInfo/actionBar.js
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,76 @@ | ||
import React from 'react'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { useSelector } from 'react-redux'; | ||
import { PrimaryButton, SecondaryButton, TertiaryButton } from '@toolbox/buttons'; | ||
import DialogLink from '@toolbox/dialog/link'; | ||
import SignInTooltipWrapper from '@shared/signInTooltipWrapper'; | ||
import { selectAccountBalance, selectLSKAddress } from '@store/selectors'; | ||
import EmptyBalanceTooltipWrapper from './emptyBalanceTooltipWrapper'; | ||
import styles from './balanceInfo.css'; | ||
|
||
const ActionBar = ({ | ||
username, address, t, isWalletRoute, activeToken, | ||
}) => { | ||
const hostBalance = useSelector(selectAccountBalance); | ||
const disableButtons = hostBalance === 0; | ||
const vote = useSelector(state => state.voting[address]); | ||
const lskAddress = useSelector(selectLSKAddress); | ||
const initialValue = isWalletRoute | ||
? {} | ||
: { recipient: address }; | ||
|
||
const voteButtonTitle = vote ? t('Edit vote') : t('Add to votes'); | ||
|
||
const sendTitle = isWalletRoute | ||
? t('Send {{token}}', { token: activeToken }) | ||
: t('Send {{token}} here', { token: activeToken }); | ||
|
||
return ( | ||
<SignInTooltipWrapper position="bottom"> | ||
<EmptyBalanceTooltipWrapper hostBalance={hostBalance}> | ||
<div className={styles.actionRow}> | ||
{ | ||
username && ( | ||
<DialogLink component="editVote" className={`${styles.button} add-vote`}> | ||
<SecondaryButton | ||
className={`${styles.voteButton} open-add-vote-dialog`} | ||
size="m" | ||
disabled={disableButtons} | ||
> | ||
{voteButtonTitle} | ||
</SecondaryButton> | ||
</DialogLink> | ||
) | ||
} | ||
{ | ||
(!username && lskAddress === address) && ( | ||
<DialogLink | ||
className={styles.registerDelegate} | ||
component="registerDelegate" | ||
> | ||
<TertiaryButton | ||
className="register-delegate" | ||
size="m" | ||
disabled={disableButtons} | ||
> | ||
{t('Register delegate')} | ||
</TertiaryButton> | ||
</DialogLink> | ||
) | ||
} | ||
<DialogLink component="send" className={`${styles.button} tx-send-bt`} data={initialValue}> | ||
<PrimaryButton | ||
className={`${styles.sendButton} ${styles[activeToken]} open-send-dialog`} | ||
size="m" | ||
disabled={disableButtons} | ||
> | ||
{sendTitle} | ||
</PrimaryButton> | ||
</DialogLink> | ||
</div> | ||
</EmptyBalanceTooltipWrapper> | ||
</SignInTooltipWrapper> | ||
); | ||
}; | ||
|
||
export default withTranslation()(ActionBar); |
125 changes: 125 additions & 0 deletions
125
src/components/screens/wallet/overview/balanceInfo/actionBar.test.js
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,125 @@ | ||
import { mountWithRouterAndStore } from '@utils/testHelpers'; | ||
import { tokenMap } from '@constants'; | ||
import ActionBar from './actionBar'; | ||
|
||
describe('Reclaim balance screen', () => { | ||
const hostAddress = 'lskmjr8hrnhzc6j653eto5fbh2p3kwdpa9ccdnhk6'; | ||
const explorerAddress = 'lskc7ofju4nvnshg6349otmcssme9q87wrpf8umws'; | ||
let wrapper; | ||
const props = { | ||
username: undefined, | ||
address: hostAddress, | ||
t: t => t, | ||
isWalletRoute: true, | ||
activeToken: tokenMap.LSK.key, | ||
}; | ||
const noBalanceAccount = { | ||
summary: { | ||
address: hostAddress, | ||
balance: 0, | ||
}, | ||
}; | ||
const balanceAccount = { | ||
summary: { | ||
address: hostAddress, | ||
balance: 100000, | ||
}, | ||
}; | ||
const state = { | ||
account: { | ||
passphrase: 'test', | ||
info: { | ||
LSK: { }, | ||
}, | ||
}, | ||
settings: { token: { active: tokenMap.LSK.key } }, | ||
}; | ||
|
||
it('Should display register delegate button and send', () => { | ||
wrapper = mountWithRouterAndStore( | ||
ActionBar, | ||
props, | ||
{}, | ||
{ ...state, account: { info: { LSK: balanceAccount } } }, | ||
); | ||
const html = wrapper.html(); | ||
|
||
expect(html).toContain('open-send-dialog'); | ||
expect(html).toContain('register-delegate'); | ||
expect(html).not.toContain('open-add-vote-dialog'); | ||
}); | ||
|
||
it('Should not display register delegate button', () => { | ||
wrapper = mountWithRouterAndStore( | ||
ActionBar, | ||
{ ...props, activeToken: tokenMap.BTC.key, address: 'mnrutC4CgQhMos4f8HWYRy8rKQ3UisGwYJ' }, | ||
{}, | ||
{ ...state, account: { info: { LSK: balanceAccount } } }, | ||
); | ||
let html = wrapper.html(); | ||
|
||
expect(html).toContain('open-send-dialog'); | ||
expect(html).not.toContain('register-delegate'); | ||
expect(html).not.toContain('open-add-vote-dialog'); | ||
|
||
wrapper = mountWithRouterAndStore( | ||
ActionBar, | ||
{ ...props, address: explorerAddress }, | ||
{}, | ||
{ ...state, account: { info: { LSK: balanceAccount } } }, | ||
); | ||
html = wrapper.html(); | ||
|
||
expect(html).toContain('open-send-dialog'); | ||
expect(html).not.toContain('register-delegate'); | ||
expect(html).not.toContain('open-add-vote-dialog'); | ||
}); | ||
|
||
it('Should display add/edit vote correctly', () => { | ||
wrapper = mountWithRouterAndStore( | ||
ActionBar, | ||
{ ...props, username: 'delegate' }, | ||
{}, | ||
{ ...state, account: { info: { LSK: balanceAccount } } }, | ||
); | ||
let html = wrapper.html(); | ||
|
||
expect(html).toContain('open-send-dialog'); | ||
expect(html).not.toContain('register-delegate'); | ||
expect(html).toContain('open-add-vote-dialog'); | ||
expect(html).toContain('Add to votes'); | ||
expect(html).not.toContain('Edit vote'); | ||
|
||
wrapper = mountWithRouterAndStore( | ||
ActionBar, | ||
{ ...props, username: 'delegate' }, | ||
{}, | ||
{ | ||
...state, | ||
account: { info: { LSK: balanceAccount } }, | ||
voting: { | ||
[balanceAccount.summary.address]: {}, | ||
}, | ||
}, | ||
); | ||
html = wrapper.html(); | ||
|
||
expect(html).toContain('Edit vote'); | ||
expect(html).not.toContain('Add to votes'); | ||
}); | ||
|
||
it('Should disable buttons', () => { | ||
wrapper = mountWithRouterAndStore( | ||
ActionBar, | ||
props, | ||
{}, | ||
{ ...state, account: { info: { LSK: noBalanceAccount } } }, | ||
); | ||
const html = wrapper.html(); | ||
|
||
expect(html).toContain('empty-balance-tooltip-wrapper'); | ||
expect(html).toContain('emptyBalanceTooltipChild disabled'); | ||
expect(wrapper.find('button.open-send-dialog')).toBeDisabled(); | ||
expect(wrapper.find('button.register-delegate')).toBeDisabled(); | ||
}); | ||
}); |
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
118 changes: 31 additions & 87 deletions
118
src/components/screens/wallet/overview/balanceInfo/index.js
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 |
---|---|---|
@@ -1,103 +1,47 @@ | ||
import React from 'react'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { tokenMap } from '@constants'; | ||
import { fromRawLsk } from '@utils/lsk'; | ||
import { PrimaryButton, SecondaryButton, TertiaryButton } from '@toolbox/buttons'; | ||
import Box from '@toolbox/box'; | ||
import BoxContent from '@toolbox/box/content'; | ||
import DialogLink from '@toolbox/dialog/link'; | ||
import LiskAmount from '@shared/liskAmount'; | ||
import DiscreetMode from '@shared/discreetMode'; | ||
import Converter from '@shared/converter'; | ||
import SignInTooltipWrapper from '@shared/signInTooltipWrapper'; | ||
import { selectAccountBalance } from '@store/selectors'; | ||
import LockedBalanceLink from './unlocking'; | ||
import EmptyBalanceTooltipWrapper from './emptyBalanceTooltipWrapper'; | ||
import ActionBar from './actionBar'; | ||
import styles from './balanceInfo.css'; | ||
|
||
const BalanceInfo = ({ | ||
t, activeToken, balance, isWalletRoute, address, username, | ||
}) => { | ||
const hostBalance = useSelector(selectAccountBalance); | ||
const disableButtons = hostBalance === 0; | ||
const vote = useSelector(state => state.voting[address]); | ||
const initialValue = isWalletRoute | ||
? {} | ||
: { recipient: address }; | ||
|
||
const voteButtonTitle = vote ? t('Edit vote') : t('Add to votes'); | ||
|
||
const sendTitle = isWalletRoute | ||
? t('Send {{token}}', { token: activeToken }) | ||
: t('Send {{token}} here', { token: activeToken }); | ||
|
||
return ( | ||
<Box className={`${styles.wrapper}`}> | ||
<BoxContent className={styles.content}> | ||
<h2 className={styles.title}>{t('Balance')}</h2> | ||
<div className={styles.valuesRow}> | ||
<DiscreetMode shouldEvaluateForOtherAccounts> | ||
<div className={`${styles.cryptoValue} balance-value`}> | ||
<LiskAmount val={balance} token={activeToken} /> | ||
<Converter | ||
className={styles.fiatValue} | ||
value={fromRawLsk(balance)} | ||
error="" | ||
/> | ||
|
||
</div> | ||
{ | ||
activeToken === tokenMap.LSK.key && isWalletRoute ? ( | ||
<LockedBalanceLink activeToken={activeToken} isWalletRoute={isWalletRoute} /> | ||
) : null | ||
} | ||
</DiscreetMode> | ||
</div> | ||
<SignInTooltipWrapper position="bottom"> | ||
<EmptyBalanceTooltipWrapper hostBalance={hostBalance}> | ||
<div className={styles.actionRow}> | ||
{ | ||
username ? ( | ||
<DialogLink component="editVote" className={`${styles.button} add-vote`}> | ||
<SecondaryButton | ||
className={`${styles.voteButton} open-add-vote-dialog`} | ||
size="m" | ||
disabled={disableButtons} | ||
> | ||
{voteButtonTitle} | ||
</SecondaryButton> | ||
</DialogLink> | ||
) : ( | ||
<DialogLink | ||
className={`${styles.registerDelegate} register-delegate`} | ||
component="registerDelegate" | ||
> | ||
<TertiaryButton | ||
size="m" | ||
disabled={disableButtons} | ||
> | ||
{t('Register delegate')} | ||
</TertiaryButton> | ||
</DialogLink> | ||
) | ||
} | ||
<DialogLink component="send" className={`${styles.button} tx-send-bt`} data={initialValue}> | ||
<PrimaryButton | ||
className={`${styles.sendButton} ${styles[activeToken]} open-send-dialog`} | ||
size="m" | ||
disabled={disableButtons} | ||
> | ||
{sendTitle} | ||
</PrimaryButton> | ||
</DialogLink> | ||
</div> | ||
</EmptyBalanceTooltipWrapper> | ||
</SignInTooltipWrapper> | ||
</BoxContent> | ||
</Box> | ||
); | ||
}; | ||
}) => ( | ||
<Box className={`${styles.wrapper}`}> | ||
<BoxContent className={styles.content}> | ||
<h2 className={styles.title}>{t('Balance')}</h2> | ||
<div className={styles.valuesRow}> | ||
<DiscreetMode shouldEvaluateForOtherAccounts> | ||
<div className={`${styles.cryptoValue} balance-value`}> | ||
<LiskAmount val={balance} token={activeToken} /> | ||
<Converter | ||
className={styles.fiatValue} | ||
value={fromRawLsk(balance)} | ||
error="" | ||
/> | ||
</div> | ||
{ | ||
activeToken === tokenMap.LSK.key && isWalletRoute ? ( | ||
<LockedBalanceLink activeToken={activeToken} isWalletRoute={isWalletRoute} /> | ||
) : null | ||
} | ||
</DiscreetMode> | ||
</div> | ||
<ActionBar | ||
address={address} | ||
username={username} | ||
isWalletRoute={isWalletRoute} | ||
activeToken={activeToken} | ||
/> | ||
</BoxContent> | ||
</Box> | ||
); | ||
|
||
export default withTranslation()(BalanceInfo); |
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