forked from anoma/namada
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* changed all fake data to go through actions * cleaned up staking-related types * Added links to the UI descriptions to the local readme of the state * removed empty reducers * added staking position listing to validator details * added a comment about the redundancy of actions
- Loading branch information
1 parent
0b1360f
commit f057a4f
Showing
20 changed files
with
580 additions
and
89 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
apps/namada-interface/src/App/Staking/NewBondingPosition/NewBondingPosition.components.ts
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,17 @@ | ||
import styled from "styled-components/macro"; | ||
|
||
export const BondingPositionContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: start; | ||
align-items: center; | ||
width: 100%; | ||
margin: 16px 0 16px; | ||
overflow-y: scroll; | ||
color: ${(props) => props.theme.colors.utility2.main}; | ||
`; | ||
|
||
export const BondingAmountInputContainer = styled.div` | ||
display: flex; | ||
width: 100%; | ||
`; |
150 changes: 150 additions & 0 deletions
150
apps/namada-interface/src/App/Staking/NewBondingPosition/NewBondingPosition.tsx
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,150 @@ | ||
import { useState } from "react"; | ||
import { | ||
BondingPositionContainer, | ||
BondingAmountInputContainer, | ||
} from "./NewBondingPosition.components"; | ||
import { Table, TableConfigurations, KeyValueData } from "components/Table"; | ||
import { Button, ButtonVariant } from "components/Button"; | ||
import { | ||
StakingPosition, | ||
ChangeInStakingPosition, | ||
} from "slices/StakingAndGovernance"; | ||
|
||
const REMAINS_BONDED_KEY = "Remains bonded"; | ||
|
||
// configuration for the summary table that represents all the data in this view | ||
const bondingDetailsConfigurations: TableConfigurations<KeyValueData, never> = { | ||
rowRenderer: (rowData: KeyValueData) => { | ||
// if this is the last row we style it bold | ||
const styleForRemainsBondedRow = | ||
rowData.key === REMAINS_BONDED_KEY ? { fontWeight: "bold" } : {}; | ||
return ( | ||
<> | ||
<td style={{ display: "flex", ...styleForRemainsBondedRow }}> | ||
{rowData.key} | ||
</td> | ||
<td style={styleForRemainsBondedRow}>{rowData.value}</td> | ||
</> | ||
); | ||
}, | ||
columns: [ | ||
{ uuid: "1", columnLabel: "", width: "30%" }, | ||
{ uuid: "2", columnLabel: "", width: "70%" }, | ||
], | ||
}; | ||
|
||
type Props = { | ||
currentBondingPosition: StakingPosition; | ||
// this is how much we have available for bonding | ||
totalFundsToBond: number; | ||
// called when the user confirms bonding | ||
confirmBonding: (changeInStakingPosition: ChangeInStakingPosition) => void; | ||
// called when the user cancels bonding | ||
cancelBonding: () => void; | ||
}; | ||
|
||
// contains everything what the user needs for bonding funds | ||
export const NewBondingPosition = (props: Props): JSX.Element => { | ||
const { | ||
currentBondingPosition, | ||
totalFundsToBond, | ||
confirmBonding, | ||
cancelBonding, | ||
} = props; | ||
const { validatorId, stakedCurrency } = currentBondingPosition; | ||
|
||
// storing the unbonding input value locally here as string | ||
// we threat them as strings except below in validation | ||
// might have to change later to numbers | ||
const [amountToBond, setAmountToBond] = useState(""); | ||
|
||
// unbonding amount and displayed value with a very naive validation | ||
// TODO (https://github.com/anoma/namada-interface/issues/4#issuecomment-1260564499) | ||
// do proper validation as part of input | ||
const bondedAmountAsNumber = Number(currentBondingPosition.stakedAmount); | ||
const amountToBondNumber = Number(amountToBond); | ||
|
||
// if this is the case, we display error message | ||
const isEntryIncorrect = | ||
(amountToBond !== "" && amountToBondNumber <= 0) || | ||
amountToBondNumber > totalFundsToBond || | ||
Number.isNaN(amountToBondNumber); | ||
|
||
// if incorrect or empty value we disable the button | ||
const isEntryIncorrectOrEmpty = isEntryIncorrect || amountToBond === ""; | ||
|
||
// we convey this with an object that can be used | ||
const remainsBondedToDisplay = isEntryIncorrect | ||
? `The bonding amount can be more than 0 and at most ${totalFundsToBond}` | ||
: `${bondedAmountAsNumber + amountToBondNumber}`; | ||
|
||
// data for the table | ||
const bondingSummary = [ | ||
{ | ||
uuid: "1", | ||
key: "Total Funds", | ||
value: `${totalFundsToBond}`, | ||
}, | ||
{ | ||
uuid: "2", | ||
key: "Bonded amount", | ||
value: currentBondingPosition.stakedAmount, | ||
}, | ||
{ | ||
uuid: "3", | ||
key: "Amount to bond", | ||
value: amountToBond, | ||
hint: "stake", | ||
}, | ||
{ | ||
uuid: "4", | ||
key: REMAINS_BONDED_KEY, | ||
value: remainsBondedToDisplay, | ||
}, | ||
]; | ||
|
||
return ( | ||
<BondingPositionContainer> | ||
{/* input field */} | ||
<BondingAmountInputContainer> | ||
<input | ||
onChange={(event) => { | ||
setAmountToBond(event.target.value); | ||
}} | ||
/> | ||
</BondingAmountInputContainer> | ||
|
||
{/* summary table */} | ||
<Table | ||
title="Summary" | ||
tableConfigurations={bondingDetailsConfigurations} | ||
data={bondingSummary} | ||
/> | ||
|
||
{/* confirmation and cancel */} | ||
<Button | ||
variant={ButtonVariant.Contained} | ||
onClick={() => { | ||
const changeInStakingPosition: ChangeInStakingPosition = { | ||
amount: amountToBond, | ||
stakingCurrency: stakedCurrency, | ||
validatorId: validatorId, | ||
}; | ||
confirmBonding(changeInStakingPosition); | ||
}} | ||
disabled={isEntryIncorrectOrEmpty} | ||
> | ||
Confirm | ||
</Button> | ||
<Button | ||
variant={ButtonVariant.Contained} | ||
onClick={() => { | ||
cancelBonding(); | ||
}} | ||
style={{ backgroundColor: "lightgrey", color: "black" }} | ||
> | ||
Cancel | ||
</Button> | ||
</BondingPositionContainer> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
apps/namada-interface/src/App/Staking/NewBondingPosition/index.ts
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 @@ | ||
export { NewBondingPosition } from "./NewBondingPosition"; |
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
12 changes: 12 additions & 0 deletions
12
apps/namada-interface/src/App/Staking/UnbondPosition/UnbondPosition.components.ts
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,12 @@ | ||
import styled from "styled-components/macro"; | ||
|
||
export const UnstakePositionContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: start; | ||
align-items: center; | ||
width: 100%; | ||
margin: 16px 0 16px; | ||
overflow-y: scroll; | ||
color: ${(props) => props.theme.colors.utility2.main}; | ||
`; |
Oops, something went wrong.