Skip to content

Commit 1caae44

Browse files
authored
Fix withdrawals by using withdraw from total balance (#34)
1 parent 7acea25 commit 1caae44

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/api/modules/aptos/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const withdrawConfidentialBalance = async (
185185
) => {
186186
const decryptionKey = new TwistedEd25519PrivateKey(decryptionKeyHex);
187187

188-
return confidentialAssets.withdraw({
188+
return confidentialAssets.withdrawWithTotalBalance({
189189
signer: account,
190190
recipient: receiver,
191191
tokenAddress,

src/app/dashboard/components/WithdrawForm.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default function WithdrawForm({
172172
setIsSubmitting(false);
173173
return;
174174
}
175-
const [txReceipt, withdrawErr] = await tryCatch(
175+
const [responses, withdrawErr] = await tryCatch(
176176
withdrawTo(
177177
parseUnits(String(formData.amount), token.decimals).toString(),
178178
recipientAddress,
@@ -187,9 +187,15 @@ export default function WithdrawForm({
187187
setIsSubmitting(false);
188188
return;
189189
}
190+
if (responses.length === 0) {
191+
ErrorHandler.process(new Error('No responses were returned'));
192+
enableForm();
193+
setIsSubmitting(false);
194+
return;
195+
}
190196

191197
const [, reloadError] = await tryCatch(
192-
reloadBalances(BigInt(txReceipt.version)),
198+
reloadBalances(BigInt(responses[responses.length - 1].version)),
193199
);
194200
if (reloadError) {
195201
ErrorHandler.process(reloadError);

src/app/dashboard/context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type ConfidentialCoinContextType = {
154154
opts?: {
155155
isSyncFirst?: boolean;
156156
},
157-
) => Promise<CommittedTransactionResponse>;
157+
) => Promise<CommittedTransactionResponse[]>;
158158
depositTo: (amount: bigint, to: string) => Promise<CommittedTransactionResponse>;
159159
depositCoinTo: (amount: bigint, to: string) => Promise<CommittedTransactionResponse>;
160160
// TODO: rotate keys
@@ -212,7 +212,7 @@ const confidentialCoinContext = createContext<ConfidentialCoinContextType>({
212212
rolloverAccount: async () => ({}) as CommittedTransactionResponse[],
213213
transfer: async () => ({}) as CommittedTransactionResponse[],
214214
buildWithdrawToTx: async () => ({}) as SimpleTransaction,
215-
withdrawTo: async () => ({}) as CommittedTransactionResponse,
215+
withdrawTo: async () => ({}) as CommittedTransactionResponse[],
216216
depositTo: async () => ({}) as CommittedTransactionResponse,
217217
depositCoinTo: async () => ({}) as CommittedTransactionResponse,
218218

0 commit comments

Comments
 (0)