Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
19 deletions.
There are no files selected for viewing
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,30 +1,113 @@ | ||
import {h} from 'preact' | ||
import {Fragment, h} from 'preact' | ||
import {connect} from '../../../helpers/connect' | ||
import actions from '../../../actions' | ||
import range from '../../../../frontend/wallet/helpers/range' | ||
import printAda from '../../../helpers/printAda' | ||
import {Lovelace} from '../../../state' | ||
import {AdaIcon} from '../../common/svg' | ||
import {UNKNOWN_POOL_NAME} from '../../../../frontend/wallet/constants' | ||
|
||
const Accounts = ({setAccount}) => ( | ||
<div className="card" style={'width: 100%;'}> | ||
<h2 className="card-title small-margin" /> | ||
<div className="account-dropdown"> | ||
{range(0, 5).map((i) => ( | ||
<a | ||
key={i} | ||
const Account = ({i, account, setAccount, selectedAccount, toggleDisplayStakingPage}) => { | ||
return ( | ||
<div key={i} className="card account" style={'width: 75%;'}> | ||
<div className="card-column" style="align-self: center;"> | ||
<button | ||
className="button primary" | ||
disabled={false} //{selectedAccount === i} | ||
onClick={() => { | ||
setAccount(i) | ||
toggleDisplayStakingPage('Sending') | ||
window.scrollTo({top: 0, behavior: 'smooth'}) | ||
}} | ||
> | ||
Account {i} | ||
</a> | ||
))} | ||
</button> | ||
</div> | ||
<div className="card-column"> | ||
<h2 className="card-title small-margin">Available balance</h2> | ||
<div className="balance-amount small"> | ||
{printAda( | ||
account | ||
? account.shelleyBalances.stakingBalance + account.shelleyBalances.nonStakingBalance | ||
: 0 | ||
)} | ||
<AdaIcon /> | ||
</div> | ||
</div> | ||
<div className="card-column"> | ||
<h2 className="card-title small-margin">Rewards balance</h2> | ||
<div className="balance-amount small"> | ||
{printAda(account ? account.shelleyBalances.rewardsAccountBalance : 0)} | ||
<AdaIcon /> | ||
</div> | ||
</div> | ||
<div className="card-column"> | ||
<h2 className="card-title small-margin">Delegation</h2> | ||
<div> | ||
{account | ||
? account.shelleyAccountInfo.delegation.name || UNKNOWN_POOL_NAME | ||
: 'Not delegated'} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
) | ||
} | ||
|
||
const Accounts = ({accounts, setAccount, selectedAccount, toggleDisplayStakingPage}) => { | ||
const accountInfos = Object.values(accounts) | ||
const totalBalance = accountInfos.reduce( | ||
(a, {shelleyBalances}) => | ||
shelleyBalances.stakingBalance + shelleyBalances.nonStakingBalance + a, | ||
0 | ||
) | ||
const totalRewardBalance = accountInfos.reduce( | ||
(a, {shelleyBalances}) => shelleyBalances.rewardsAccountBalance + a, | ||
0 | ||
) | ||
return ( | ||
<Fragment> | ||
<div className="dashboard-column account"> | ||
<div className="card account" style={'width: 100%;'}> | ||
<div> | ||
<h2 className="card-title small-margin">Total balance</h2> | ||
<div className="balance-amount"> | ||
{printAda(totalBalance as Lovelace)} | ||
<AdaIcon /> | ||
</div> | ||
</div> | ||
<div> | ||
<h2 className="card-title small-margin">Total rewards balance</h2> | ||
<div className="balance-amount"> | ||
{printAda(totalRewardBalance as Lovelace)} | ||
<AdaIcon /> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="dashboard-column account wide"> | ||
<div> | ||
{range(0, Object.keys(accounts).length + 1).map((i) => ( | ||
<Account | ||
key={i} | ||
i={i} | ||
account={accounts[i]} | ||
setAccount={setAccount} | ||
selectedAccount={selectedAccount} | ||
toggleDisplayStakingPage={toggleDisplayStakingPage} | ||
/> | ||
))} | ||
</div> | ||
<div className="dashboard-column account narrow"> </div> | ||
</div> | ||
</div> | ||
</Fragment> | ||
) | ||
} | ||
|
||
export default connect( | ||
(state) => ({ | ||
isDemoWallet: state.isDemoWallet, | ||
router: state.router, | ||
accounts: state.accounts, | ||
selectedAccount: state.selectedAccount, | ||
}), | ||
actions | ||
)(Accounts) |
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
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