Skip to content

Commit 29599e3

Browse files
fix(wallet, wallet-dashboard): Allow accessing active stakes at all times (#6796)
## Links to any relevant issues fixes #6784 --------- Co-authored-by: Marc Espin <[email protected]>
1 parent 007c5c3 commit 29599e3

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

apps/core/src/hooks/stake/useNewUnstakeTransaction.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export function useNewUnstakeTransaction(senderAddress: string, unstakeIotaId: s
1515
queryFn: async () => {
1616
const transaction = createUnstakeTransaction(unstakeIotaId);
1717
transaction.setSender(senderAddress);
18-
await transaction.build({ client });
1918
const txBytes = await transaction.build({ client });
2019
const txDryRun = await client.dryRunTransactionBlock({
2120
transactionBlock: txBytes,

apps/wallet-dashboard/components/dialogs/unstake/views/UnstakeView.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ import {
2121
useNewUnstakeTransaction,
2222
Validator,
2323
toast,
24+
NOT_ENOUGH_BALANCE_ID,
25+
GAS_BUDGET_ERROR_MESSAGES,
26+
GAS_BALANCE_TOO_LOW_ID,
2427
} from '@iota/core';
2528
import { useCurrentAccount, useSignAndExecuteTransaction } from '@iota/dapp-kit';
26-
import { Warning } from '@iota/apps-ui-icons';
29+
import { Warning, Info } from '@iota/apps-ui-icons';
2730
import { StakeRewardsPanel, ValidatorStakingData } from '@/components';
2831
import { DialogLayout, DialogLayoutFooter, DialogLayoutBody } from '../../layout';
2932

@@ -46,10 +49,11 @@ export function UnstakeView({
4649
showActiveStatus,
4750
}: UnstakeDialogProps): JSX.Element {
4851
const activeAddress = useCurrentAccount()?.address ?? '';
49-
const { data: unstakeData, isPending: isUnstakeTxPending } = useNewUnstakeTransaction(
50-
activeAddress,
51-
extendedStake.stakedIotaId,
52-
);
52+
const {
53+
data: unstakeData,
54+
isPending: isUnstakeTxPending,
55+
error,
56+
} = useNewUnstakeTransaction(activeAddress, extendedStake.stakedIotaId);
5357
const [gasFormatted] = useFormatCoin({
5458
balance: unstakeData?.gasSummary?.totalGas,
5559
format: CoinFormat.FULL,
@@ -74,7 +78,10 @@ export function UnstakeView({
7478
} = delegatedStakeDataResult;
7579

7680
const delegationId = extendedStake?.stakedIotaId;
77-
const isPreparingUnstake = !unstakeData || isUnstakeTxPending;
81+
const isNotEnoughGas =
82+
error &&
83+
(error.message.includes(NOT_ENOUGH_BALANCE_ID) ||
84+
error.message.includes(GAS_BALANCE_TOO_LOW_ID));
7885

7986
async function handleUnstake(): Promise<void> {
8087
if (!unstakeData) return;
@@ -156,14 +163,30 @@ export function UnstakeView({
156163
</DialogLayoutBody>
157164

158165
<DialogLayoutFooter>
166+
{isNotEnoughGas && (
167+
<div className="pt-sm">
168+
<InfoBox
169+
supportingText={GAS_BUDGET_ERROR_MESSAGES[GAS_BALANCE_TOO_LOW_ID]}
170+
icon={<Info />}
171+
type={InfoBoxType.Error}
172+
style={InfoBoxStyle.Elevated}
173+
/>
174+
</div>
175+
)}
159176
<Button
160177
type={ButtonType.Secondary}
161178
fullWidth
162179
onClick={handleUnstake}
163-
disabled={isPreparingUnstake || isTransactionPending || !delegationId}
180+
disabled={
181+
!unstakeData ||
182+
isUnstakeTxPending ||
183+
isTransactionPending ||
184+
isNotEnoughGas ||
185+
!delegationId
186+
}
164187
text="Unstake"
165188
icon={
166-
isPreparingUnstake ? (
189+
isUnstakeTxPending || isTransactionPending ? (
167190
<LoadingIndicator data-testid="loading-indicator" />
168191
) : null
169192
}

apps/wallet/src/ui/app/pages/home/tokens/TokenStakingOverview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function TokenStakingOverview({
2828
disabled,
2929
}: {
3030
accountAddress: string;
31-
disabled: boolean;
31+
disabled?: boolean;
3232
}) {
3333
const navigate = useNavigate();
3434
const { data: delegatedStake, isPending } = useGetDelegatedStake({

apps/wallet/src/ui/app/pages/home/tokens/TokensDetails.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ export function TokenDetails() {
250250
<div className="flex w-full flex-col items-center gap-xs">
251251
{accountHasIota || delegatedStake?.length ? (
252252
<TokenStakingOverview
253-
disabled={!tokenBalance}
254253
accountAddress={activeAccountAddress}
255254
/>
256255
) : null}

apps/wallet/src/ui/app/staking/stake/UnstakeForm.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717
getDelegationDataByStakeId,
1818
Validator,
1919
toast,
20+
GAS_BUDGET_ERROR_MESSAGES,
21+
NOT_ENOUGH_BALANCE_ID,
22+
GAS_BALANCE_TOO_LOW_ID,
2023
} from '@iota/core';
2124
import { useMemo } from 'react';
2225
import { useActiveAccount, useSigner } from '_hooks';
@@ -79,6 +82,7 @@ export function UnStakeForm({ stakedIotaId, validatorAddress, epoch, onSuccess }
7982
data: unstakeData,
8083
isLoading: isUnstakeTokenTransactionLoading,
8184
isError,
85+
error,
8286
} = useNewUnstakeTransaction(activeAddress, stakedIotaId);
8387
const transaction = unstakeData?.transaction;
8488

@@ -154,6 +158,10 @@ export function UnStakeForm({ stakedIotaId, validatorAddress, epoch, onSuccess }
154158
const isLoading =
155159
isPending || isUnstakeTokenTransactionPending || isUnstakeTokenTransactionLoading;
156160

161+
const isNotEnoughGas =
162+
error &&
163+
(error.message.includes(NOT_ENOUGH_BALANCE_ID) ||
164+
error.message.includes(GAS_BALANCE_TOO_LOW_ID));
157165
return (
158166
<>
159167
<div className="flex flex-1 flex-col flex-nowrap gap-y-md overflow-auto">
@@ -209,6 +217,16 @@ export function UnStakeForm({ stakedIotaId, validatorAddress, epoch, onSuccess }
209217
/>
210218
</div>
211219
)}
220+
{isNotEnoughGas && (
221+
<div className="pt-sm">
222+
<InfoBox
223+
supportingText={GAS_BUDGET_ERROR_MESSAGES[GAS_BALANCE_TOO_LOW_ID]}
224+
icon={<Info />}
225+
type={InfoBoxType.Error}
226+
style={InfoBoxStyle.Elevated}
227+
/>
228+
</div>
229+
)}
212230
<div className="pt-sm">
213231
<Button
214232
type={ButtonType.Primary}
@@ -217,7 +235,7 @@ export function UnStakeForm({ stakedIotaId, validatorAddress, epoch, onSuccess }
217235
disabled={isError || isLoading}
218236
text="Unstake"
219237
icon={
220-
isLoading ? (
238+
isLoading && !isError ? (
221239
<Loader className="animate-spin" data-testid="loading-indicator" />
222240
) : null
223241
}

0 commit comments

Comments
 (0)