Skip to content

Commit

Permalink
Merge pull request #1996 from oasisprotocol/lw/delegable-amount
Browse files Browse the repository at this point in the history
Show available amount next to delegation input
  • Loading branch information
lukaw3d authored Jul 9, 2024
2 parents e9a3aa4 + effa544 commit bd1a4aa
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 23 deletions.
1 change: 1 addition & 0 deletions .changelog/1996.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show available amount next to delegation input
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ exports[`<AddEscrowForm /> should match snapshot 1`] = `
}
.c7 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
box-sizing: border-box;
max-width: 100%;
margin-top: 6px;
-webkit-align-items: flex-end;
-webkit-box-align: flex-end;
-ms-flex-align: flex-end;
align-items: flex-end;
min-width: 0;
min-height: 0;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c9 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
box-sizing: border-box;
max-width: 100%;
min-width: 0;
min-height: 0;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c10 {
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
Expand All @@ -50,6 +83,12 @@ exports[`<AddEscrowForm /> should match snapshot 1`] = `
}
.c8 {
font-size: 14px;
line-height: 20px;
font-weight: bolder;
}
.c11 {
display: inline-block;
box-sizing: border-box;
cursor: pointer;
Expand Down Expand Up @@ -78,47 +117,47 @@ exports[`<AddEscrowForm /> should match snapshot 1`] = `
font-weight: bold;
}
.c8:hover {
.c11:hover {
box-shadow: 0px 0px 0px 2px #0500e2;
}
.c8:focus {
.c11:focus {
outline: none;
box-shadow: 0 0 2px 2px #00A9FF;
}
.c8:focus > circle,
.c8:focus > ellipse,
.c8:focus > line,
.c8:focus > path,
.c8:focus > polygon,
.c8:focus > polyline,
.c8:focus > rect {
.c11:focus > circle,
.c11:focus > ellipse,
.c11:focus > line,
.c11:focus > path,
.c11:focus > polygon,
.c11:focus > polyline,
.c11:focus > rect {
outline: none;
box-shadow: 0 0 2px 2px #00A9FF;
}
.c8:focus::-moz-focus-inner {
.c11:focus::-moz-focus-inner {
border: 0;
}
.c8:focus:not(:focus-visible) {
.c11:focus:not(:focus-visible) {
outline: none;
box-shadow: none;
}
.c8:focus:not(:focus-visible) > circle,
.c8:focus:not(:focus-visible) > ellipse,
.c8:focus:not(:focus-visible) > line,
.c8:focus:not(:focus-visible) > path,
.c8:focus:not(:focus-visible) > polygon,
.c8:focus:not(:focus-visible) > polyline,
.c8:focus:not(:focus-visible) > rect {
.c11:focus:not(:focus-visible) > circle,
.c11:focus:not(:focus-visible) > ellipse,
.c11:focus:not(:focus-visible) > line,
.c11:focus:not(:focus-visible) > path,
.c11:focus:not(:focus-visible) > polygon,
.c11:focus:not(:focus-visible) > polyline,
.c11:focus:not(:focus-visible) > rect {
outline: none;
box-shadow: none;
}
.c8:focus:not(:focus-visible)::-moz-focus-inner {
.c11:focus:not(:focus-visible)::-moz-focus-inner {
border: 0;
}
Expand Down Expand Up @@ -248,6 +287,12 @@ exports[`<AddEscrowForm /> should match snapshot 1`] = `
@media only screen and (max-width:768px) {
.c7 {
margin-top: 3px;
}
}
@media only screen and (max-width:768px) {
.c10 {
width: 6px;
}
}
Expand Down Expand Up @@ -287,12 +332,43 @@ exports[`<AddEscrowForm /> should match snapshot 1`] = `
value=""
/>
</div>
<div
class="c7"
>
<span
class="c8"
>
<span>
account.addEscrow.availableAmount
</span>
<span>
<div
class="c9"
style="display: inline-flex; white-space: nowrap;"
>
456.542341274
</div>
<span
class="c5"
>
<span
class="notranslate"
translate="no"
>
</span>
</span>
</span>
</span>
</div>
</div>
<div
class="c7"
class="c10"
/>
<button
class="c8"
class="c11"
style="height: 48px;"
type="submit"
>
account.addEscrow.delegate
Expand Down
7 changes: 6 additions & 1 deletion src/app/components/AddEscrowForm/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const renderComponent = (store: any, address: string, validatorStatus: Validator
<Provider store={store}>
<ThemeProvider>
<ModalProvider>
<AddEscrowForm validatorAddress={address} validatorStatus={validatorStatus} validatorRank={21} />
<AddEscrowForm
validatorAddress={address}
validatorStatus={validatorStatus}
validatorRank={21}
accountAvailableBalance={456542341274n.toString()}
/>
</ModalProvider>
</ThemeProvider>
</Provider>,
Expand Down
16 changes: 15 additions & 1 deletion src/app/components/AddEscrowForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import { TransactionStatus } from '../TransactionStatus'
import { usePreventChangeOnNumberInputScroll } from '../../lib/usePreventChangeOnNumberInputScroll'
import { AmountFormatter } from '../AmountFormatter'
import { StringifiedBigInt } from '../../../types/StringifiedBigInt'

interface Props {
validatorAddress: string
validatorStatus: Validator['status']
validatorRank: number
accountAvailableBalance: StringifiedBigInt | null
}

export const AddEscrowForm = memo((props: Props) => {
Expand Down Expand Up @@ -114,8 +117,19 @@ export const AddEscrowForm = memo((props: Props) => {
reverse
onWheel={onWheel}
/>
<Box align="end" margin={{ top: 'xsmall' }}>
<Text weight="bolder" size="small">
<span>{t('account.addEscrow.availableAmount', 'Available:')} </span>
<AmountFormatter amount={props.accountAvailableBalance} smallTicker />
</Text>
</Box>
</Box>
<Button label={t('account.addEscrow.delegate', 'Delegate')} type="submit" primary />
<Button
label={t('account.addEscrow.delegate', 'Delegate')}
type="submit"
primary
style={{ height: 48 }}
/>
</Box>
<TransactionStatus error={error} success={success} />
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { Box } from 'grommet/es6/components/Box'
import React from 'react'

import { ValidatorInformations } from './ValidatorInformations'
import { StringifiedBigInt } from '../../../../../types/StringifiedBigInt'

interface ValidatorProps {
data: Validator
details: ValidatorDetails | null
accountAvailableBalance: StringifiedBigInt | null
isAddressInWallet: boolean
}
export const ValidatorItem = (props: ValidatorProps) => {
Expand All @@ -24,6 +26,7 @@ export const ValidatorItem = (props: ValidatorProps) => {
validatorAddress={validator.address}
validatorStatus={validator.status}
validatorRank={validator.rank}
accountAvailableBalance={props.accountAvailableBalance}
/>
)}
</Box>
Expand Down
3 changes: 3 additions & 0 deletions src/app/pages/StakingPage/Features/ValidatorList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ValidatorItem } from './ValidatorItem'
import { formatCommissionPercent } from 'app/lib/helpers'
import { intlDateTimeFormat } from 'app/components/DateFormatter/intlDateTimeFormat'
import { StakeSubnavigation } from '../../../AccountPage/Features/StakeSubnavigation'
import { selectAccountAvailableBalance } from '../../../../state/account/selectors'

interface Props {}

Expand All @@ -42,6 +43,7 @@ export const ValidatorList = memo((props: Props) => {
const validatorsTimestamp = useSelector(selectValidatorsTimestamp)
const updateValidatorsError = useSelector(selectUpdateValidatorsError)
const isAddressInWallet = useSelector(selectIsAddressInWallet)
const accountAvailableBalance = useSelector(selectAccountAvailableBalance)
const selectedAddress = useSelector(selectSelectedAddress)
const validatorDetails = useSelector(selectValidatorDetails)

Expand Down Expand Up @@ -143,6 +145,7 @@ export const ValidatorList = memo((props: Props) => {
<ValidatorItem
data={{} as any}
details={validatorDetails}
accountAvailableBalance={accountAvailableBalance}
isAddressInWallet={isAddressInWallet}
key={selectedAddress}
/>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"account": {
"addEscrow": {
"availableAmount": "Available:",
"confirmDelegatingToInactive": {
"description": "Status of this validator is {{validatorStatus}}. Your delegation might not generate any rewards.",
"title": "Are you sure you want to continue?"
Expand Down

0 comments on commit bd1a4aa

Please sign in to comment.