This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
feat(frontend): display detailed balance information on AccountDetails page #447
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c8be2ff
simple build need fix
icerove 57d4469
change timestamp and update test
icerove 7fb82f4
no expose lockup timestamp
icerove 491f774
small fixes
icerove f753ccc
delete view state
icerove df99e11
finish build
icerove a923a62
update test
icerove 927aedb
delete unused comments
icerove 5bd7dba
Update frontend/src/components/accounts/AccountDetails.tsx
icerove 61283ec
fix as suggested
icerove 992c709
moved the account details (balances) collection to the backend (WIP)
frol 47bee36
delete unused
icerove 0d3a81f
Merge branch 'master' into feature/lockup-balance
icerove 3445497
fix and update as suggested
icerove 11dc73d
update test
icerove 8b94af1
fix as suggested
icerove 4154824
fix glitch
icerove bf86e9e
delete console
icerove 15227da
fix: Accurately compute all the balances
frol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import Balance from "../utils/Balance"; | |
import CardCell from "../utils/CardCell"; | ||
import TransactionLink from "../utils/TransactionLink"; | ||
import Term from "../utils/Term"; | ||
import AccountLink from "../utils/AccountLink"; | ||
|
||
export interface Props { | ||
account: A.Account; | ||
|
@@ -18,36 +19,55 @@ export interface Props { | |
export default class extends React.Component<Props> { | ||
render() { | ||
const { account } = this.props; | ||
console.log(account); | ||
return ( | ||
<div className="account-info-container"> | ||
<Row noGutters> | ||
<Col md="3"> | ||
<CardCell | ||
title={ | ||
<Term title={"Ⓝ Balance"}> | ||
{"NEAR token that is spendable all the time. "} | ||
<a href={"https://docs.near.org/docs/concepts/account"}> | ||
docs | ||
</a> | ||
<Term title={"Ⓝ Available Balance"}> | ||
{ | ||
"This is your spendable NEAR balance, and can be used or transferred immediately. This will be lower than your Total Balance." | ||
} | ||
</Term> | ||
} | ||
text={<Balance amount={account.amount} />} | ||
text={<Balance amount={account.availableBalance} />} | ||
className="border-0" | ||
/> | ||
</Col> | ||
<Col md="3"> | ||
<CardCell | ||
title={ | ||
<Term title={"Ⓝ Locked"}> | ||
<Term title={"Minimum Balance"}> | ||
{ | ||
"NEAR token balance that is currently staked, and thus not immediately spendable. " | ||
"This is the minimum NEAR balance your account must maintain to remain active. This balance represents the storage space your account is using on the NEAR blockchain, and will go up or down as you use more or less space. " | ||
} | ||
<a href={"https://docs.near.org/docs/concepts/account"}> | ||
<a | ||
href={ | ||
"https://docs.near.org/docs/roles/integrator/faq#is-there-a-minimum-account-balance" | ||
} | ||
> | ||
docs | ||
</a> | ||
</Term> | ||
} | ||
text={<Balance amount={account.locked} />} | ||
imgLink="/static/images/icon-storage.svg" | ||
text={<Balance amount={account.minimumBalance} />} | ||
/> | ||
</Col> | ||
<Col md="3"> | ||
<CardCell | ||
title={ | ||
<Term title={"Storage Used"}> | ||
{"Total blockchain storage (in bytes) used by this account. "} | ||
<a href={"https://docs.near.org/docs/concepts/storage"}> | ||
docs | ||
</a> | ||
</Term> | ||
} | ||
imgLink="/static/images/icon-storage.svg" | ||
text={`${account.storageUsage.toLocaleString()} B`} | ||
/> | ||
</Col> | ||
<Col md="3"> | ||
|
@@ -74,18 +94,102 @@ export default class extends React.Component<Props> { | |
} | ||
/> | ||
</Col> | ||
<Col md="3"> | ||
</Row> | ||
<Row> | ||
<Col md="4"> | ||
<CardCell | ||
title={ | ||
<Term title={"Storage Used"}> | ||
{"Total blockchain storage (in bytes) used by this account. "} | ||
<Term title={"Ⓝ Total Balance"}> | ||
{ | ||
"Your total balance represents all NEAR tokens under your control. In many cases, you will not have immediate access to this entire balance (e.g. if it is locked, delegated, or staked). Check your Available Balance for the NEAR you can actively use, transfer, delegate, and stake." | ||
} | ||
</Term> | ||
} | ||
imgLink="/static/images/icon-storage.svg" | ||
text={`${account.storageUsage.toLocaleString()} B`} | ||
text={<Balance amount={account.totalBalance} />} | ||
className="border-0" | ||
/> | ||
</Col> | ||
<Col md="4"> | ||
<CardCell | ||
title={ | ||
<Term title={"Ⓝ Staked Balance"}> | ||
{ | ||
"This NEAR is actively being used to back a validator and secure the network. When you decide to unstake this NEAR, it will take some time to be shown in your Available Balance, as NEAR takes 3 epochs (~36 hours) to unstake. " | ||
} | ||
<a | ||
href={ | ||
"https://docs.near.org/docs/validator/economics#1-near-tokens-to-stake" | ||
} | ||
> | ||
docs | ||
</a> | ||
</Term> | ||
} | ||
text={<Balance amount={account.stakedBalance} />} | ||
/> | ||
</Col> | ||
<Col md="4"> | ||
<CardCell | ||
title={ | ||
<Term title={"Ⓝ Non Staked Balance"}> | ||
{ | ||
"The amount of NEAR Token that is stored as amount in your account." | ||
} | ||
</Term> | ||
} | ||
text={<Balance amount={account.nonStakedBalance} />} | ||
/> | ||
</Col> | ||
</Row> | ||
{account.lockupTotalBalance && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that we will miss the total balance information if there is no information about the lockup balance. This should not be the case |
||
<Row noGutters> | ||
<Col md="6"> | ||
<CardCell | ||
title={ | ||
<Term title={"Ⓝ Total Lockup Balance"}> | ||
{ | ||
"This NEAR is locked in a lockup contract, and cannot be withdrawn. You may still delegate or stake this NEAR. Once the NEAR is unlocked, you can view it in your Unlocked Balance, and chose to withdraw it (moving to your Available Balance). " | ||
} | ||
<a | ||
href={ | ||
"https://docs.near.org/docs/tokens/lockup#lockup-basics" | ||
} | ||
> | ||
docs | ||
</a> | ||
</Term> | ||
} | ||
text={<Balance amount={account.lockupTotalBalance} />} | ||
/> | ||
</Col> | ||
<Col md="6"> | ||
<CardCell | ||
title={ | ||
<Term title={"Lockup Account"}> | ||
{ | ||
"Lockup is a special smart contract that ensures that the full amount or even a partial amount is not transferable until it is supposed to be. " | ||
} | ||
<a | ||
href={ | ||
"https://docs.near.org/docs/tokens/lockup#the-lockup-contract" | ||
} | ||
> | ||
docs | ||
</a> | ||
</Term> | ||
} | ||
imgLink="/static/images/icon-m-transaction.svg" | ||
text={ | ||
account.lockupAccountId ? ( | ||
<AccountLink accountId={account.lockupAccountId} /> | ||
) : ( | ||
"" | ||
) | ||
} | ||
/> | ||
</Col> | ||
</Row> | ||
)} | ||
<Row noGutters className="border-0"> | ||
<Col md="4"> | ||
<CardCell | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,50 @@ import renderer from "react-test-renderer"; | |
import AccountDetails from "../AccountDetails"; | ||
|
||
describe("<AccountDetails />", () => { | ||
it("renders", () => { | ||
it("renders with lockup account", () => { | ||
expect( | ||
renderer.create( | ||
<AccountDetails | ||
account={{ | ||
id: "account", | ||
amount: "1", | ||
locked: "1", | ||
storageUsage: 0, | ||
storagePaidAt: 1, | ||
inTransactionsCount: 0, | ||
outTransactionsCount: 0, | ||
accountId: "megan.near", | ||
inTransactionsCount: 10, | ||
outTransactionsCount: 7, | ||
createdAtBlockTimestamp: Number(new Date(2019, 1, 1)), | ||
createdByTransactionHash: | ||
"EVvWW1S9BFaEjY1JBNSdstb7ZTtTFjQ6cygkbw1KY4tL", | ||
accountIndex: 1234567890, | ||
stakedBalance: "0", | ||
nonStakedBalance: "654345665432345678765", | ||
minimumBalance: "87600000000000", | ||
availableBalance: "43454321345678765432345678", | ||
totalBalance: "9876545678765432134567876543", | ||
storageUsage: "876", | ||
lockupTotalBalance: "765654565324543", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a test for an account without lockup account information |
||
lockupAccountId: "gjturigjgkjnfidsjffjsa.lockup.near", | ||
}} | ||
/> | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
it("renders without lockup account", () => { | ||
expect( | ||
renderer.create( | ||
<AccountDetails | ||
account={{ | ||
accountId: "near.near", | ||
inTransactionsCount: 10, | ||
outTransactionsCount: 7, | ||
createdAtBlockTimestamp: Number(new Date(2019, 1, 1)), | ||
createdByTransactionHash: | ||
"EVvWW1S9BFlkjkmnjmkb7ZTtTFjQ6cygkbw1KY4tL", | ||
accountIndex: 1234567890, | ||
stakedBalance: "0", | ||
nonStakedBalance: "6987876845678765", | ||
minimumBalance: "187600000000000", | ||
availableBalance: "434345678765432345678", | ||
totalBalance: "98765445654565134567876543", | ||
storageUsage: "1876", | ||
}} | ||
/> | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the log