Skip to content

Commit

Permalink
Merge branch 'develop' into tooling-wallet/fix-wallet-build-rc-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
begonaalvarezd authored Nov 5, 2024
2 parents 2c24857 + ce6b0ea commit 5ef8f60
Show file tree
Hide file tree
Showing 23 changed files with 642 additions and 570 deletions.
12 changes: 0 additions & 12 deletions .changeset/seven-falcons-return.md

This file was deleted.

2 changes: 1 addition & 1 deletion apps/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"@ledgerhq/hw-transport-webhid": "^6.27.15",
"@ledgerhq/hw-transport-webusb": "^6.27.13",
"@ledgerhq/logs": "^6.12.0",
"@metamask/browser-passworder": "^5.0.1",
"@metamask/browser-passworder": "4.1.0",
"@noble/hashes": "^1.4.0",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-collapsible": "^1.0.3",
Expand Down
10 changes: 4 additions & 6 deletions apps/wallet/src/ui/app/staking/stake/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,20 @@ function StakeForm({ validatorAddress, coinBalance, coinType, epoch }: StakeFrom
transaction ?? new Transaction(),
);

const gasSummary = useMemo(() => {
if (!txDryRunResponse) return null;
return getGasSummary(txDryRunResponse);
}, [txDryRunResponse]);
const gasSummary = txDryRunResponse ? getGasSummary(txDryRunResponse) : undefined;

const stakeAllTransaction = useMemo(() => {
return createStakeTransaction(coinBalance, validatorAddress);
}, [coinBalance, validatorAddress, decimals]);
}, [coinBalance, validatorAddress]);

const { data: stakeAllTransactionDryRun } = useTransactionDryRun(
activeAddress ?? undefined,
stakeAllTransaction ?? new Transaction(),
stakeAllTransaction,
);

const gasBudget = BigInt(stakeAllTransactionDryRun?.input.gasData.budget ?? 0);

// do not remove: gasBudget field is used in the validation schema apps/wallet/src/ui/app/staking/stake/utils/validation.ts
useEffect(() => {
setFieldValue('gasBudget', gasBudget);
}, [gasBudget]);
Expand Down
148 changes: 79 additions & 69 deletions apps/wallet/src/ui/app/staking/stake/StakingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function StakingCard() {
return getDelegationDataByStakeId(allDelegation, stakeIotaIdParams);
}, [allDelegation, stakeIotaIdParams]);

const coinSymbol = useMemo(() => (coinType && Coin.getCoinSymbol(coinType)) || '', [coinType]);
const coinSymbol = (coinType && Coin.getCoinSymbol(coinType)) || '';

const iotaEarned =
(stakeData as Extract<StakeObject, { estimatedReward: string }>)?.estimatedReward || '0';
Expand All @@ -94,33 +94,69 @@ function StakingCard() {
);

const queryClient = useQueryClient();
const delegationId = useMemo(() => {
if (!stakeData || stakeData.status === 'Pending') return null;
return stakeData.stakedIotaId;
}, [stakeData]);
const delegationId =
stakeData?.status === 'Unstaked' || stakeData?.status === 'Active'
? stakeData?.stakedIotaId
: undefined;

const navigate = useNavigate();
const signer = useSigner(activeAccount);

const { mutateAsync: stakeTokenMutateAsync } = useMutation({
mutationFn: async ({
tokenTypeArg,
amount,
validatorAddress,
}: {
tokenTypeArg: string;
amount: bigint;
validatorAddress: string;
}) => {
if (!validatorAddress || !amount || !tokenTypeArg || !signer) {
throw new Error('Failed, missing required field');
}
const { mutateAsync: stakeTokenMutateAsync, isPending: isStakeTokenTransactionPending } =
useMutation({
mutationFn: async ({
tokenTypeArg,
amount,
validatorAddress,
}: {
tokenTypeArg: string;
amount: bigint;
validatorAddress: string;
}) => {
if (!validatorAddress || !amount || !tokenTypeArg || !signer) {
throw new Error('Failed, missing required field');
}

// const sentryTransaction = Sentry.startTransaction({
// name: 'stake',
// });
try {
const transactionBlock = createStakeTransaction(amount, validatorAddress);
// const sentryTransaction = Sentry.startTransaction({
// name: 'stake',
// });
try {
const transactionBlock = createStakeTransaction(amount, validatorAddress);
const tx = await signer.signAndExecuteTransaction({
transactionBlock,
options: {
showInput: true,
showEffects: true,
showEvents: true,
},
});
await signer.client.waitForTransaction({
digest: tx.digest,
});
return tx;
} finally {
// sentryTransaction.finish();
}
},
onSuccess: (_, { amount, validatorAddress }) => {
ampli.stakedIota({
stakedAmount: Number(amount / NANOS_PER_IOTA),
validatorAddress: validatorAddress,
});
},
});

const { mutateAsync: unStakeTokenMutateAsync, isPending: isUnstakeTokenTransactionPending } =
useMutation({
mutationFn: async ({ stakedIotaId }: { stakedIotaId: string }) => {
if (!stakedIotaId || !signer) {
throw new Error('Failed, missing required field.');
}

// const sentryTransaction = Sentry.startTransaction({
// name: 'stake',
// });
const transactionBlock = createUnstakeTransaction(stakedIotaId);
const tx = await signer.signAndExecuteTransaction({
transactionBlock,
options: {
Expand All @@ -133,58 +169,23 @@ function StakingCard() {
digest: tx.digest,
});
return tx;
} finally {
// sentryTransaction.finish();
}
},
onSuccess: (_, { amount, validatorAddress }) => {
ampli.stakedIota({
stakedAmount: Number(amount / NANOS_PER_IOTA),
validatorAddress: validatorAddress,
});
},
});

const { mutateAsync: unStakeTokenMutateAsync } = useMutation({
mutationFn: async ({ stakedIotaId }: { stakedIotaId: string }) => {
if (!stakedIotaId || !signer) {
throw new Error('Failed, missing required field.');
}

// const sentryTransaction = Sentry.startTransaction({
// name: 'stake',
// });
const transactionBlock = createUnstakeTransaction(stakedIotaId);
const tx = await signer.signAndExecuteTransaction({
transactionBlock,
options: {
showInput: true,
showEffects: true,
showEvents: true,
},
});
await signer.client.waitForTransaction({
digest: tx.digest,
});
return tx;
// finally {
// sentryTransaction.finish();
// }
},
onSuccess: () => {
ampli.unstakedIota({
validatorAddress: validatorAddress!,
});
},
});
// finally {
// sentryTransaction.finish();
// }
},
onSuccess: () => {
ampli.unstakedIota({
validatorAddress: validatorAddress!,
});
},
});

const onSubmit = useCallback(
async ({ amount }: FormValues, { resetForm }: FormikHelpers<FormValues>) => {
if (coinType === null || validatorAddress === null) {
return;
}
try {
const bigIntAmount = parseAmount(amount, coinDecimals);
let response;
let txDigest;
if (unstake) {
Expand All @@ -198,6 +199,7 @@ function StakingCard() {

txDigest = response.digest;
} else {
const bigIntAmount = parseAmount(amount, coinDecimals);
response = await stakeTokenMutateAsync({
amount: bigIntAmount,
tokenTypeArg: coinType,
Expand Down Expand Up @@ -260,7 +262,15 @@ function StakingCard() {
}
return (
<div className="flex h-full w-full flex-grow flex-col flex-nowrap">
<Loading loading={isPending || validatorsIsPending || loadingIotaBalances}>
<Loading
loading={
isPending ||
validatorsIsPending ||
loadingIotaBalances ||
isStakeTokenTransactionPending ||
isUnstakeTokenTransactionPending
}
>
<Formik
initialValues={INITIAL_VALUES}
validationSchema={validationSchema}
Expand Down
Loading

0 comments on commit 5ef8f60

Please sign in to comment.