Skip to content

Commit

Permalink
fix: stake sheet amount error validation after submission (#1188)
Browse files Browse the repository at this point in the history
* fix: dappStaking error, do not display when submitting extrinsic

* fix: nominationPoolsStakeSideSheet error, do not display when submitting extrinsic

* fix: subtensorStakeSideSheet, do not display error when submitting extrinsic

* fix: slpxStakeSideSheet, do not display error when submitting extrinsic

* fix: dapp staking error message handling

* fix: storybook types
  • Loading branch information
UrbanWill authored Oct 11, 2024
1 parent 24054fa commit 6c2227a
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const AddStakeForm = (props: AddStakeFormProps) => (
leadingLabel="Available to stake"
trailingLabel={props.availableToStake}
leadingSupportingText={props.fiatAmount}
trailingSupportingText={props.inputSupportingText}
trailingSupportingText={props.confirmState !== 'pending' && props.inputSupportingText}
trailingIcon={<TextInput.LabelButton onClick={props.onRequestMaxAmount}>Max</TextInput.LabelButton>}
value={props.amount}
onChange={event => props.onChangeAmount(event.target.value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const Default: Story = {
amountInput: (
<DappStakingForm.AmountInput
amount="2 ASTAR"
isLoading={false}
fiatAmount="$1.00"
availableToStake="1 ASTAR"
onChangeAmount={() => {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type AmountInputProps =
fiatAmount: ReactNode
availableToStake: ReactNode
error?: string
isLoading: boolean
}
| {
disabled: true
Expand All @@ -50,7 +51,9 @@ const AmountInput = (props: AmountInputProps) => {
leadingSupportingText={
props.disabled
? ''
: Maybe.of(props.error).mapOr(props.fiatAmount, x => <TextInput.ErrorLabel>{x}</TextInput.ErrorLabel>)
: Maybe.of(props.isLoading ? undefined : props.error).mapOr(props.fiatAmount, x => (
<TextInput.ErrorLabel>{x}</TextInput.ErrorLabel>
))
}
trailingSupportingText={
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Default.args = {
amountInput: (
<StakeForm.AmountInput
amount="1000"
isLoading={false}
onChangeAmount={() => {}}
onRequestMaxAmount={() => {}}
fiatAmount="$0.00"
Expand Down
7 changes: 6 additions & 1 deletion apps/portal/src/components/recipes/StakeForm/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type AmountInputProps = {
fiatAmount: ReactNode
availableToStake: ReactNode
error?: string
isLoading: boolean
}

const AmountInput = (props: AmountInputProps) => (
Expand All @@ -42,7 +43,11 @@ const AmountInput = (props: AmountInputProps) => (
leadingLabel="Available to stake"
trailingLabel={props.availableToStake}
leadingSupportingText={
isNilOrWhitespace(props.error) ? props.fiatAmount : <TextInput.ErrorLabel>{props.error}</TextInput.ErrorLabel>
isNilOrWhitespace(props.error) || props.isLoading ? (
props.fiatAmount
) : (
<TextInput.ErrorLabel>{props.error}</TextInput.ErrorLabel>
)
}
trailingSupportingText={<SurfaceChip onClick={props.onRequestMaxAmount}>Max</SurfaceChip>}
css={{ fontSize: '3rem' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const StakeForm = (props: StakeFormProps) => {
availableToStake={available.decimalAmount.toLocaleString()}
assetSelector={props.assetSelector}
error={error?.message}
isLoading={extrinsic.state === 'loading'}
/>
}
dappSelectionInProgress={props.dappSelectionInProgress}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ export const ControlledStakeForm = (props: { assetSelector: ReactNode; account?:
fiatAmount={localizedFiatAmount}
availableToStake={availableBalance.decimalAmount?.toLocaleString() ?? '...'}
error={inputError?.message}
isLoading={joinPoolExtrinsic.state === 'loading'}
/>
}
poolInfo={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const StakeForm = (props: StakeFormProps) => {
availableToStake={transferable.decimalAmount.toLocaleString()}
assetSelector={props.assetSelector}
error={error?.message}
isLoading={extrinsic.state === 'loading'}
/>
}
selectionInProgress={props.selectionInProgress}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type AmountInputProps =
fiatAmount: ReactNode
availableToStake: ReactNode
error?: string
isLoading: boolean
}
| {
disabled: true
Expand All @@ -50,7 +51,9 @@ const AmountInput = (props: AmountInputProps) => {
leadingSupportingText={
props.disabled
? ''
: Maybe.of(props.error).mapOr(props.fiatAmount, x => <TextInput.ErrorLabel>{x}</TextInput.ErrorLabel>)
: Maybe.of(props.isLoading ? undefined : props.error).mapOr(props.fiatAmount, x => (
<TextInput.ErrorLabel>{x}</TextInput.ErrorLabel>
))
}
trailingSupportingText={
<Button
Expand Down

0 comments on commit 6c2227a

Please sign in to comment.