Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stake sheet amount error validation after submission #1188

Merged
merged 7 commits into from
Oct 11, 2024
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
Loading