Skip to content

Commit

Permalink
feat: Added support for CANCELLED status to the Passport client (#1629)
Browse files Browse the repository at this point in the history
  • Loading branch information
shirren authored Mar 27, 2024
1 parent b28088d commit 3ba6a14
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
27 changes: 26 additions & 1 deletion packages/passport/sdk/src/zkEvm/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ describe('sendTransaction', () => {
signedTransactions,
);
relayerClient.ethSendTransaction.mockResolvedValue(relayerTransactionId);
withConfirmationScreenStub.mockImplementation(() => (task: () => void) => task());
withConfirmationScreenStub.mockImplementation(
() => (task: () => void) => task(),
);
guardianClient.withConfirmationScreen = withConfirmationScreenStub;
rpcProvider.detectNetwork.mockResolvedValue({ chainId });
});
Expand Down Expand Up @@ -205,4 +207,27 @@ describe('sendTransaction', () => {
),
);
});

it('returns and surfaces an error if the relayer cancels a transaction', async () => {
(retryWithDelay as jest.Mock).mockResolvedValue({
status: RelayerTransactionStatus.CANCELLED,
statusMessage: 'Transaction cancelled',
} as RelayerTransaction);

await expect(
sendTransaction({
params: [transactionRequest],
ethSigner,
rpcProvider: rpcProvider as unknown as StaticJsonRpcProvider,
relayerClient: relayerClient as unknown as RelayerClient,
zkevmAddress: mockUserZkEvm.zkEvm.ethAddress,
guardianClient: guardianClient as unknown as GuardianClient,
}),
).rejects.toThrow(
new JsonRpcError(
RpcErrorCode.INTERNAL_ERROR,
'Transaction failed to submit with status CANCELLED. Error message: Transaction cancelled',
),
);
});
});
40 changes: 22 additions & 18 deletions packages/passport/sdk/src/zkEvm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum RelayerTransactionStatus {
SUCCESSFUL = 'SUCCESSFUL',
REVERTED = 'REVERTED',
FAILED = 'FAILED',
CANCELLED = 'CANCELLED',
}

export interface RelayerTransaction {
Expand All @@ -26,22 +27,22 @@ export interface FeeOption {
}

export interface MetaTransaction {
to: string
value?: BigNumberish
data?: BytesLike
nonce?: BigNumberish
gasLimit?: BigNumberish
delegateCall?: boolean
revertOnError?: boolean
to: string;
value?: BigNumberish;
data?: BytesLike;
nonce?: BigNumberish;
gasLimit?: BigNumberish;
delegateCall?: boolean;
revertOnError?: boolean;
}

export interface MetaTransactionNormalised {
delegateCall: boolean
revertOnError: boolean
gasLimit: BigNumberish
target: string
value: BigNumberish
data: BytesLike
delegateCall: boolean;
revertOnError: boolean;
gasLimit: BigNumberish;
target: string;
value: BigNumberish;
data: BytesLike;
}

// https://eips.ethereum.org/EIPS/eip-712
Expand All @@ -52,7 +53,7 @@ export interface TypedDataPayload {
};
domain: {
name?: string;
version? :string;
version?: string;
chainId?: number;
verifyingContract?: string;
salt?: string;
Expand All @@ -72,7 +73,10 @@ export type JsonRpcRequestPayload = RequestArguments & {
};

export interface JsonRpcRequestCallback {
(err: JsonRpcError | null, result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null): void;
(
err: JsonRpcError | null,
result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null
): void;
}

export interface JsonRpcResponsePayload {
Expand All @@ -86,12 +90,12 @@ export type Provider = {
request: (request: RequestArguments) => Promise<any>;
sendAsync: (
request: JsonRpcRequestPayload | JsonRpcRequestPayload[],
callback: JsonRpcRequestCallback,
callback: JsonRpcRequestCallback
) => void;
send: (
request: string | JsonRpcRequestPayload | JsonRpcRequestPayload[],
callbackOrParams?: JsonRpcRequestCallback | Array<any>,
callback?: JsonRpcRequestCallback,
callback?: JsonRpcRequestCallback
) => void;
on: (event: string, listener: (...args: any[]) => void) => void;
removeListener: (event: string, listener: (...args: any[]) => void) => void;
Expand All @@ -105,5 +109,5 @@ export enum ProviderEvent {
export type AccountsChangedEvent = Array<string>;

export interface ProviderEventMap extends Record<string, any> {
[ProviderEvent.ACCOUNTS_CHANGED]: [AccountsChangedEvent],
[ProviderEvent.ACCOUNTS_CHANGED]: [AccountsChangedEvent];
}

0 comments on commit 3ba6a14

Please sign in to comment.