Skip to content

Commit

Permalink
Rename selectedAccountIndex to active
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Jan 14, 2021
1 parent b31f8ec commit 087764b
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 56 deletions.
12 changes: 6 additions & 6 deletions app/frontend/actions.ts
Expand Up @@ -1015,13 +1015,13 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF

const resetAccountIndexes = (state: State) => {
setState({
targetAccountIndex: state.selectedAccountIndex,
sourceAccountIndex: state.selectedAccountIndex,
targetAccountIndex: state.activeAccountIndex,
sourceAccountIndex: state.activeAccountIndex,
})
}
const setSelectedAccount = (state: State, accountIndex: number) => {
const setActiveAccount = (state: State, accountIndex: number) => {
setState({
selectedAccountIndex: accountIndex,
activeAccountIndex: accountIndex,
targetAccountIndex: accountIndex,
sourceAccountIndex: accountIndex,
txSuccessTab: '',
Expand All @@ -1038,7 +1038,7 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
accountsInfo,
...wallet.getWalletInfo(accountsInfo),
})
setSelectedAccount(state, newAccount.accountIndex)
setActiveAccount(state, newAccount.accountIndex)
} catch (e) {
setErrorState('walletLoadingError', e)
setState({
Expand Down Expand Up @@ -1374,7 +1374,7 @@ export default ({setState, getState}: {setState: SetStateFn; getState: GetStateF
closeSendTransactionModal,
showDelegationModal,
closeDelegationModal,
setSelectedAccount,
setActiveAccount,
setTargetAccount,
setSourceAccount,
exploreNewAccount,
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/components/common/balance.tsx
@@ -1,7 +1,7 @@
import {h} from 'preact'
import printAda from '../../helpers/printAda'
import Conversions from './conversions'
import {Lovelace, State, selectedAccountState} from '../../state'
import {Lovelace, State, activeAccountState} from '../../state'
import {AdaIcon} from './svg'
import actions from '../../actions'
import {connect} from '../../libs/unistore/preact'
Expand Down Expand Up @@ -47,7 +47,7 @@ const Balance = ({balance, reloadWalletInfo, conversionRates}: Props) => (
export default connect(
(state: State) => ({
conversionRates: state.conversionRates && state.conversionRates.data,
balance: selectedAccountState(state).balance,
balance: activeAccountState(state).balance,
}),
actions
)(Balance)
2 changes: 1 addition & 1 deletion app/frontend/components/pages/accounts/accountDropdown.tsx
Expand Up @@ -40,7 +40,7 @@ const AccountDropdown = ({accountIndex, setAccountFunc, accountsInfo}) => {
export default connect(
(state: State) => ({
accountsInfo: state.accountsInfo,
selectedAccountIndex: state.selectedAccountIndex,
activeAccountIndex: state.activeAccountIndex,
}),
actions
)(AccountDropdown)
40 changes: 20 additions & 20 deletions app/frontend/components/pages/accounts/accountsDashboard.tsx
Expand Up @@ -17,9 +17,9 @@ type TileProps = {
ticker: string | null
availableBalance: Lovelace | null
rewardsBalance: Lovelace | null
setSelectedAccount: any
setActiveAccount: any
exploreNewAccount: any
selectedAccountIndex: number
activeAccountIndex: number
showDelegationModal: any
showSendTransactionModal: any
shouldShowAccountInfo?: boolean
Expand All @@ -30,14 +30,14 @@ const AccountTile = ({
ticker,
availableBalance,
rewardsBalance,
setSelectedAccount,
setActiveAccount,
exploreNewAccount,
selectedAccountIndex,
activeAccountIndex,
showDelegationModal,
showSendTransactionModal,
shouldShowAccountInfo,
}: TileProps) => {
const isSelected = selectedAccountIndex === accountIndex
const isActive = activeAccountIndex === accountIndex

const Balance = ({value}: {value: Lovelace}) =>
value !== null ? (
Expand All @@ -52,8 +52,8 @@ const AccountTile = ({
const TransferButton = () => (
<button
className="button primary nowrap account-button"
onClick={() => showSendTransactionModal(selectedAccountIndex, accountIndex)}
disabled={isSelected}
onClick={() => showSendTransactionModal(activeAccountIndex, accountIndex)}
disabled={isActive}
>
Transfer
</button>
Expand All @@ -73,12 +73,12 @@ const AccountTile = ({
const ActivationButton = () => (
<button
className="button primary nowrap"
disabled={isSelected}
disabled={isActive}
onClick={() => {
setSelectedAccount(accountIndex)
setActiveAccount(accountIndex)
}}
>
{isSelected ? 'Active' : 'Activate'}
{isActive ? 'Active' : 'Activate'}
</button>
)

Expand All @@ -94,7 +94,7 @@ const AccountTile = ({
)

return (
<div key={accountIndex} className={`card account ${isSelected ? 'selected' : ''}`}>
<div key={accountIndex} className={`card account ${isActive ? 'selected' : ''}`}>
<div className="header-wrapper mobile">
<h2 className="card-title small-margin">Account #{accountIndex}</h2>
</div>
Expand Down Expand Up @@ -146,14 +146,14 @@ const AccountTile = ({

type DashboardProps = {
accountsInfo: Array<any>
setSelectedAccount: any
setActiveAccount: any
exploreNewAccount: any
reloadWalletInfo: any
showSendTransactionModal: boolean
showDelegationModal: boolean
shouldShowSendTransactionModal: boolean
shouldShowDelegationModal: boolean
selectedAccountIndex: number
activeAccountIndex: number
totalWalletBalance: number
totalRewardsBalance: number
shouldShowConfirmTransactionDialog: boolean
Expand All @@ -164,14 +164,14 @@ type DashboardProps = {

const AccountsDashboard = ({
accountsInfo,
setSelectedAccount,
setActiveAccount,
exploreNewAccount,
reloadWalletInfo,
showSendTransactionModal,
showDelegationModal,
shouldShowSendTransactionModal,
shouldShowDelegationModal,
selectedAccountIndex,
activeAccountIndex,
totalWalletBalance,
totalRewardsBalance,
shouldShowConfirmTransactionDialog,
Expand Down Expand Up @@ -247,14 +247,14 @@ const AccountsDashboard = ({
<AccountTile
key={accountInfo.accountIndex}
accountIndex={accountInfo.accountIndex}
selectedAccountIndex={selectedAccountIndex}
activeAccountIndex={activeAccountIndex}
ticker={accountInfo.shelleyAccountInfo.delegation.ticker}
availableBalance={
accountInfo.shelleyBalances.stakingBalance +
accountInfo.shelleyBalances.nonStakingBalance
} // TODO: this should be in state}
rewardsBalance={accountInfo.shelleyBalances.rewardsAccountBalance}
setSelectedAccount={setSelectedAccount}
setActiveAccount={setActiveAccount}
exploreNewAccount={() => null}
showSendTransactionModal={showSendTransactionModal}
showDelegationModal={showDelegationModal}
Expand All @@ -264,11 +264,11 @@ const AccountsDashboard = ({
{accountsInfo[accountsInfo.length - 1].isUsed && (
<AccountTile
accountIndex={accountsInfo.length}
selectedAccountIndex={selectedAccountIndex}
activeAccountIndex={activeAccountIndex}
ticker={null}
availableBalance={null}
rewardsBalance={null}
setSelectedAccount={() => null}
setActiveAccount={() => null}
exploreNewAccount={exploreNewAccount}
showSendTransactionModal={showSendTransactionModal}
showDelegationModal={showSendTransactionModal}
Expand Down Expand Up @@ -302,7 +302,7 @@ export default connect(
accountsInfo: state.accountsInfo,
shouldShowSendTransactionModal: state.shouldShowSendTransactionModal,
shouldShowDelegationModal: state.shouldShowDelegationModal,
selectedAccountIndex: state.selectedAccountIndex,
activeAccountIndex: state.activeAccountIndex,
totalRewardsBalance: state.totalRewardsBalance,
totalWalletBalance: state.totalWalletBalance,
shouldShowConfirmTransactionDialog: state.shouldShowConfirmTransactionDialog,
Expand Down
8 changes: 4 additions & 4 deletions app/frontend/components/pages/advanced/keys.tsx
@@ -1,7 +1,7 @@
import {Fragment, h} from 'preact'
import {connect} from '../../../libs/unistore/preact'
import actions from '../../../actions'
import {State, selectedAccountState} from '../../../state'
import {State, activeAccountState} from '../../../state'

const Keys = ({byronXpub, shelleyXpub, accountPubkeyHex}) => {
return (
Expand Down Expand Up @@ -29,9 +29,9 @@ const Keys = ({byronXpub, shelleyXpub, accountPubkeyHex}) => {

export default connect(
(state: State) => ({
shelleyXpub: selectedAccountState(state).shelleyAccountInfo.shelleyXpub,
byronXpub: selectedAccountState(state).shelleyAccountInfo.byronXpub,
accountPubkeyHex: selectedAccountState(state).shelleyAccountInfo.accountPubkeyHex,
shelleyXpub: activeAccountState(state).shelleyAccountInfo.shelleyXpub,
byronXpub: activeAccountState(state).shelleyAccountInfo.byronXpub,
accountPubkeyHex: activeAccountState(state).shelleyAccountInfo.accountPubkeyHex,
}),
actions
)(Keys)
6 changes: 3 additions & 3 deletions app/frontend/components/pages/dashboard/dashboardPage.tsx
Expand Up @@ -91,7 +91,7 @@ class DashboardPage extends Component<Props> {
displayInfoModal,
shouldShowPremiumBanner,
shouldShowSaturatedBanner,
selectedAccountIndex,
activeAccountIndex,
}) {
// TODO: this approach doesnt allow multi-word tabs
const mainTabs = ['Accounts', 'Sending', 'Staking', 'Advanced']
Expand Down Expand Up @@ -123,7 +123,7 @@ class DashboardPage extends Component<Props> {
name={name}
selectedTab={selectedMainTab}
selectTab={this.selectMainTab}
displayName={name === 'Accounts' && `Account #${selectedAccountIndex}`}
displayName={name === 'Accounts' && `Account #${activeAccountIndex}`}
/>
))}
</ul>
Expand Down Expand Up @@ -212,7 +212,7 @@ export default connect(
shouldShowNonShelleyCompatibleDialog: state.shouldShowNonShelleyCompatibleDialog,
shouldShowPremiumBanner: state.shouldShowPremiumBanner,
shouldShowSaturatedBanner: state.shouldShowSaturatedBanner,
selectedAccountIndex: state.selectedAccountIndex,
activeAccountIndex: state.activeAccountIndex,
}),
actions
)(DashboardPage)
Expand Up @@ -2,7 +2,7 @@ import {Fragment, h} from 'preact'
import {connect} from '../../../libs/unistore/preact'
import actions from '../../../actions'
import printAda from '../../../helpers/printAda'
import {Lovelace, State, selectedAccountState} from '../../../state'
import {Lovelace, State, activeAccountState} from '../../../state'
import {LinkIconToPool} from './common'
import {EpochDateTime} from '../common'
import roundNumber from './../../../helpers/roundNumber'
Expand Down Expand Up @@ -109,11 +109,11 @@ const CurrentDelegationPage = ({

export default connect(
(state: State) => ({
pool: selectedAccountState(state).shelleyAccountInfo.delegation,
pool: activeAccountState(state).shelleyAccountInfo.delegation,
delegationValidationError: state.delegationValidationError,
calculatingDelegationFee: state.calculatingDelegationFee,
nearestReward: selectedAccountState(state).shelleyAccountInfo.rewardDetails.nearest,
currentDelegationReward: selectedAccountState(state).shelleyAccountInfo.rewardDetails
nearestReward: activeAccountState(state).shelleyAccountInfo.rewardDetails.nearest,
currentDelegationReward: activeAccountState(state).shelleyAccountInfo.rewardDetails
.currentDelegation,
}),
actions
Expand Down
12 changes: 6 additions & 6 deletions app/frontend/components/pages/delegations/shelleyBalances.tsx
Expand Up @@ -5,7 +5,7 @@ import actions from '../../../actions'
import {connect} from '../../../libs/unistore/preact'
import tooltip from '../../common/tooltip'
import toLocalDate from '../../../../frontend/helpers/toLocalDate'
import {selectedAccountState, State} from '../../../state'
import {activeAccountState, State} from '../../../state'

const shelleyBalances = ({
stakingBalance,
Expand Down Expand Up @@ -132,14 +132,14 @@ const shelleyBalances = ({

export default connect(
(state: State) => ({
stakingBalance: selectedAccountState(state).shelleyBalances.stakingBalance,
nonStakingBalance: selectedAccountState(state).shelleyBalances.nonStakingBalance,
rewardsAccountBalance: selectedAccountState(state).shelleyBalances.rewardsAccountBalance,
balance: selectedAccountState(state).balance,
stakingBalance: activeAccountState(state).shelleyBalances.stakingBalance,
nonStakingBalance: activeAccountState(state).shelleyBalances.nonStakingBalance,
rewardsAccountBalance: activeAccountState(state).shelleyBalances.rewardsAccountBalance,
balance: activeAccountState(state).balance,
calculatingDelegationFee: state.calculatingDelegationFee,
hwWalletName: state.hwWalletName,
isShelleyCompatible: state.isShelleyCompatible,
nearestReward: selectedAccountState(state).shelleyAccountInfo.rewardDetails.nearest,
nearestReward: activeAccountState(state).shelleyAccountInfo.rewardDetails.nearest,
}),
actions
)(shelleyBalances)
Expand Up @@ -2,7 +2,7 @@ import {h, Component} from 'preact'
import actions from '../../../actions'
import {connect} from '../../../libs/unistore/preact'
import {LinkIconToPool} from './common'
import {selectedAccountState, Lovelace, State} from '../../../state'
import {activeAccountState, Lovelace, State} from '../../../state'
import printAda from '../../../helpers/printAda'
import CopyOnClick from '../../common/copyOnClick'
import {EpochDateTime} from '../common'
Expand Down Expand Up @@ -228,7 +228,7 @@ class StakingHistoryPage extends Component<Props> {

export default connect(
(state: State) => ({
stakingHistory: selectedAccountState(state).stakingHistory,
stakingHistory: activeAccountState(state).stakingHistory,
}),
actions
)(StakingHistoryPage)
4 changes: 2 additions & 2 deletions app/frontend/components/pages/receiveAda/myAddresses.tsx
@@ -1,10 +1,10 @@
import {State, selectedAccountState} from '../../../../frontend/state'
import {State, activeAccountState} from '../../../../frontend/state'
import {h} from 'preact'
import {useSelector} from '../../../helpers/connect'
import AddressItem from './addressItem'

const MyAddresses = () => {
const addresses = useSelector((state: State) => selectedAccountState(state).visibleAddresses)
const addresses = useSelector((state: State) => activeAccountState(state).visibleAddresses)

return (
<div className="addresses card">
Expand Down
@@ -1,6 +1,6 @@
import {h, Component} from 'preact'
import printAda from '../../../helpers/printAda'
import {selectedAccountState, Lovelace, State} from '../../../state'
import {activeAccountState, Lovelace, State} from '../../../state'
import {ADALITE_CONFIG} from '../../../config'
import actions from '../../../actions'
import {connect} from '../../../libs/unistore/preact'
Expand Down Expand Up @@ -220,8 +220,8 @@ class TransactionHistory extends Component<Props> {

export default connect(
(state: State) => ({
transactionHistory: selectedAccountState(state).transactionHistory,
stakingHistory: selectedAccountState(state).stakingHistory,
transactionHistory: activeAccountState(state).transactionHistory,
stakingHistory: activeAccountState(state).stakingHistory,
}),
actions
)(TransactionHistory)
6 changes: 3 additions & 3 deletions app/frontend/state.ts
Expand Up @@ -152,7 +152,7 @@ export interface State {
accountIndex: number
}>
sourceAccountIndex: number
selectedAccountIndex: number
activeAccountIndex: number
targetAccountIndex: number
totalWalletBalance: number
totalRewardsBalance: number
Expand Down Expand Up @@ -277,7 +277,7 @@ const initialState: State = {
},
],
sourceAccountIndex: 0,
selectedAccountIndex: 0,
activeAccountIndex: 0,
targetAccountIndex: 0,
totalWalletBalance: 0,
totalRewardsBalance: 0,
Expand All @@ -290,6 +290,6 @@ export type SetStateFn = (newState: Partial<State>) => void
export type GetStateFn = () => State

export const sourceAccountState = (state: State) => state.accountsInfo[state.sourceAccountIndex]
export const selectedAccountState = (state: State) => state.accountsInfo[state.selectedAccountIndex]
export const activeAccountState = (state: State) => state.accountsInfo[state.activeAccountIndex]

export {initialState}

0 comments on commit 087764b

Please sign in to comment.