Skip to content

Commit e0cead8

Browse files
committed
🐛 app: fall back to server account deployment
1 parent beb3176 commit e0cead8

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

‎.changeset/quiet-falcon-deploy.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@exactly/mobile": patch
3+
---
4+
5+
🐛 fall back to server account deployment

‎src/utils/accountClient.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
type Deferrable,
1717
type GetEntryPointFromAccount,
1818
type MiddlewareClient,
19+
type SendUserOperationParameters,
1920
type SmartAccountClient,
2021
type SmartContractAccount,
2122
type UserOperationContext,
@@ -50,6 +51,7 @@ import {
5051
waitForTransactionReceipt,
5152
} from "@wagmi/core/actions";
5253
import {
54+
BaseError,
5355
bytesToBigInt,
5456
bytesToHex,
5557
concat,
@@ -65,6 +67,7 @@ import {
6567
isHex,
6668
maxUint256,
6769
numberToHex,
70+
RpcRequestError,
6871
sliceHex,
6972
trim,
7073
type Address,
@@ -238,7 +241,7 @@ export default async function createAccountClient({ credentialId, factory, x, y
238241
: { opts: { feeOptions: { maxPriorityFeePerGas: { multiplier: 1.5 } } } }),
239242
gasEstimator,
240243
});
241-
const { hash } = await crossClient.sendUserOperation({
244+
const { hash } = await sendUserOperation(crossClient, {
242245
uo: suffix ? concatHex([await remote.account.encodeBatchExecute(uo), suffix]) : uo,
243246
});
244247
return { id: concat([hash, numberToHex(targetChainId, { size: 32 }), UO_MAGIC_ID]) };
@@ -258,7 +261,7 @@ export default async function createAccountClient({ credentialId, factory, x, y
258261
gasEstimator,
259262
})
260263
: client;
261-
const { hash } = await uoClient.sendUserOperation({
264+
const { hash } = await sendUserOperation(uoClient, {
262265
uo: suffix ? concatHex([await account.encodeBatchExecute(uo), suffix]) : uo,
263266
});
264267
return { id: concat([hash, numberToHex(chain.id, { size: 32 }), UO_MAGIC_ID]) };
@@ -447,6 +450,25 @@ function noRetry(provider: Parameters<typeof custom>[0]) {
447450
return custom(provider, { retryCount: 0 });
448451
}
449452

453+
async function sendUserOperation(
454+
client: SmartAccountClient<Transport, Chain, SmartContractAccount>,
455+
parameters: SendUserOperationParameters<SmartContractAccount>,
456+
) {
457+
const deployed = await client.account.isAccountDeployed();
458+
try {
459+
return await client.sendUserOperation(parameters);
460+
} catch (error) {
461+
if (deployed || !(error instanceof BaseError) || !error.walk((cause) => cause instanceof RpcRequestError)) {
462+
throw error;
463+
}
464+
for (let attempt = 0; attempt < 30; attempt++) {
465+
if (await client.account.isAccountDeployed()) return client.sendUserOperation(parameters);
466+
await new Promise((resolve) => setTimeout(resolve, 2000));
467+
}
468+
throw error;
469+
}
470+
}
471+
450472
function wrapSignature(ownerIndex: number, signature: Hex) {
451473
return encodePacked(["uint8", "bytes"], [ownerIndex, signature]);
452474
}

0 commit comments

Comments
 (0)