Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add event listener for fee token selection #420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
6bfdbfc
chore: add jsx support in snap
khanti42 Nov 6, 2024
76ae1eb
chore: add jsx support in snap
khanti42 Nov 6, 2024
065bf13
Merge branch 'feat/sf-705-add-jsx-support' into feat/sf-715-jsx-suppo…
khanti42 Nov 6, 2024
6cd5cd2
feat: jsx support management
khanti42 Nov 6, 2024
64e7d08
feat: common jsx components and fragments
khanti42 Nov 6, 2024
db7eafb
chore: fix test and lint
khanti42 Nov 6, 2024
f1976b8
Merge branch 'feat/sf-715-jsx-support-detection' into feat/sf-706-add…
khanti42 Nov 7, 2024
9db1d65
Merge branch 'main' into feat/sf-706-add-common-jsx-component
khanti42 Nov 10, 2024
a0de84b
feat: add interactive-ui for execute txn
khanti42 Nov 11, 2024
ce79daa
fix: add mutex in jsx support detection mechanism
khanti42 Nov 11, 2024
313eeac
Merge branch 'feat/sf-715-jsx-support-detection' into feat/sf-712-int…
khanti42 Nov 11, 2024
a37c70b
chore: fixture request addapted
khanti42 Nov 11, 2024
550bdb5
chore: ensure test pass
khanti42 Nov 11, 2024
069bfaa
Merge branch 'feat/sf-715-jsx-support-detection' into feat/sf-712-int…
khanti42 Nov 11, 2024
184d775
chore: lint
khanti42 Nov 11, 2024
62f1b43
feat: add interactive-ui in execute txn
khanti42 Nov 11, 2024
05e56c5
chore: remove console.log
khanti42 Nov 11, 2024
41a9469
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 11, 2024
70799fc
chore: missing helper in tests
khanti42 Nov 11, 2024
0bf7e56
chore: lint
khanti42 Nov 11, 2024
5d8402f
feat: event-handler in index.tsx
khanti42 Nov 12, 2024
63c3666
feat: event controller
khanti42 Nov 12, 2024
d3ef4a1
feat: error handling and tests suits for event controller
khanti42 Nov 13, 2024
f2734b0
fix: test suits
khanti42 Nov 13, 2024
b53b7be
fix: signer in fee-token-selector
khanti42 Nov 13, 2024
5b41514
chore: rollback jsx support detection not here
khanti42 Nov 14, 2024
38ab576
Merge branch 'feat/sf-706-add-common-jsx-component' into feat/sf-712-…
khanti42 Nov 14, 2024
dee34b9
chore: rollback index.tsx
khanti42 Nov 14, 2024
a37ba1b
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 14, 2024
230675f
Merge branch 'feat/sf-713-interactive-ui-in-execute-txn' into feat/sf…
khanti42 Nov 14, 2024
33f4b55
chore: lint
khanti42 Nov 14, 2024
eb772f4
Merge branch 'main' into feat/sf-705-add-jsx-support
khanti42 Nov 18, 2024
98deefe
chore: fix comment
khanti42 Nov 18, 2024
4057e3d
Merge branch 'feat/sf-705-add-jsx-support' into feat/sf-706-add-commo…
khanti42 Nov 18, 2024
30d061d
chore: fix comments
khanti42 Nov 18, 2024
73eaef9
chore: fix comments
khanti42 Nov 18, 2024
6016268
Merge branch 'feat/sf-706-add-common-jsx-component' into feat/sf-712-…
khanti42 Nov 18, 2024
b6760b7
chore: update yarn.lock
khanti42 Nov 18, 2024
fa2ae20
Merge branch 'feat/sf-705-add-jsx-support' into feat/sf-706-add-commo…
khanti42 Nov 18, 2024
7f3e73b
chore: update yarn.lock
khanti42 Nov 18, 2024
3ae1dee
Merge branch 'feat/sf-706-add-common-jsx-component' into feat/sf-712-…
khanti42 Nov 18, 2024
6e74bfb
feat: update wallet-ui message
khanti42 Nov 18, 2024
f71eb18
Merge branch 'feat/snap-fee-token-selection' into feat/sf-712-interac…
khanti42 Nov 18, 2024
f1bde36
chore: update yarn.lock
khanti42 Nov 18, 2024
da25436
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 18, 2024
67c3ee3
Merge branch 'feat/wallet-ui-update-unsupported-version-message' into…
khanti42 Nov 18, 2024
ab257a4
chore: rebase wallet-ui changes happening elsewhere
khanti42 Nov 18, 2024
0f2a283
chore: rebase wallet-ui changes happening elsewhere
khanti42 Nov 18, 2024
5987efc
chore: fix comments
khanti42 Nov 18, 2024
940ca47
chore: fix comments
khanti42 Nov 18, 2024
23ccced
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 18, 2024
1e589dd
fix: formatter-utils
khanti42 Nov 18, 2024
e956cc9
chore: fix comments
khanti42 Nov 18, 2024
aa43464
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 18, 2024
f9c95c0
chore: fix comments
khanti42 Nov 18, 2024
e0f6468
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 18, 2024
092d8f4
chore: lint
khanti42 Nov 18, 2024
3e0b92a
chore: lint
khanti42 Nov 18, 2024
000e933
chore: fix comments
khanti42 Nov 18, 2024
b2a16f1
chore: fix comments
khanti42 Nov 18, 2024
053d479
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 18, 2024
f4c75ea
chore: fix comments
khanti42 Nov 18, 2024
7e0db91
chore: fix comments
khanti42 Nov 18, 2024
855c168
Merge branch 'feat/sf-713-interactive-ui-in-execute-txn' into feat/sf…
khanti42 Nov 18, 2024
546b472
chore: lint
khanti42 Nov 18, 2024
b8ece59
chore: lint
khanti42 Nov 18, 2024
f338c54
chore: removed utils
khanti42 Nov 18, 2024
3cf9077
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 18, 2024
d0feda0
Merge branch 'feat/sf-713-interactive-ui-in-execute-txn' into feat/sf…
khanti42 Nov 18, 2024
1716243
feat: add comments in user-input classes
khanti42 Nov 18, 2024
02e9551
fix: implement comments
khanti42 Nov 19, 2024
c3f2059
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 19, 2024
b8073fd
fix: implement comments
khanti42 Nov 19, 2024
0120f8f
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 19, 2024
80a8fdb
chore: fix comments
khanti42 Nov 19, 2024
ea934df
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 19, 2024
8f7d915
chore: fix comments
khanti42 Nov 19, 2024
8c1b05b
Update packages/starknet-snap/src/ui/components/ExecuteTxnUI.tsx
khanti42 Nov 19, 2024
3d5bea2
Update packages/starknet-snap/src/ui/components/ExecuteTxnUI.tsx
khanti42 Nov 19, 2024
570ee93
Update packages/starknet-snap/src/ui/utils.test.tsx
khanti42 Nov 19, 2024
b53a281
Update packages/starknet-snap/src/types/snapState.ts
khanti42 Nov 19, 2024
2926565
Update packages/starknet-snap/src/ui/components/ExecuteTxnUI.tsx
khanti42 Nov 19, 2024
e1c288b
Update packages/starknet-snap/src/ui/components/ExecuteTxnUI.tsx
khanti42 Nov 19, 2024
086bc1e
Update packages/starknet-snap/src/ui/utils.test.tsx
khanti42 Nov 19, 2024
e1a888b
Update packages/starknet-snap/src/ui/utils.test.tsx
khanti42 Nov 19, 2024
a43fdfe
chore: fix comments
khanti42 Nov 19, 2024
ccf7e7a
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 19, 2024
9a27786
chore: fix comments
khanti42 Nov 19, 2024
59f592b
chore: fix comments
khanti42 Nov 19, 2024
54d94ef
chore: fix comments
khanti42 Nov 19, 2024
3fa6797
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 19, 2024
d47144f
chore: fix comments
khanti42 Nov 19, 2024
b6858f6
chore: lint
khanti42 Nov 19, 2024
0996a34
Merge branch 'feat/sf-712-interactive-ui-for-execute-txn' into feat/s…
khanti42 Nov 19, 2024
283985c
chore: lint
khanti42 Nov 19, 2024
8b5b388
Merge branch 'feat/snap-fee-token-selection' into feat/sf-713-interac…
khanti42 Nov 19, 2024
6e47c1d
Merge branch 'feat/sf-713-interactive-ui-in-execute-txn' into feat/sf…
khanti42 Nov 19, 2024
4c4c729
chore: fix rebase
khanti42 Nov 19, 2024
8bfd9ce
chore: fix comments
khanti42 Nov 19, 2024
f283525
Merge branch 'feat/sf-713-interactive-ui-in-execute-txn' into feat/sf…
khanti42 Nov 19, 2024
2ded1cf
chore: fix comments
khanti42 Nov 19, 2024
82d8a87
Merge branch 'feat/sf-713-interactive-ui-in-execute-txn' into feat/sf…
khanti42 Nov 19, 2024
d68b56e
chore: fix comments
khanti42 Nov 19, 2024
a9946ad
Merge branch 'feat/snap-fee-token-selection' into feat/sf-714-event-h…
khanti42 Nov 19, 2024
cdb0c95
chore: rebase
khanti42 Nov 19, 2024
5d17559
Merge branch 'feat/snap-fee-token-selection' into feat/sf-714-event-h…
khanti42 Nov 19, 2024
78b981c
fix: removed user-input controller abstract class and derived ones
khanti42 Nov 19, 2024
6b4fc58
chore: rollback execute-txn
khanti42 Nov 19, 2024
427fb13
chore: update
stanleyyconsensys Nov 20, 2024
bf8e89b
chore: fix comments
khanti42 Nov 20, 2024
ae7b4e1
Merge branch 'feat/snap-fee-token-selection' into feat/sf-714-event-h…
khanti42 Nov 20, 2024
386fcfe
chore: fix comments
khanti42 Nov 20, 2024
4fca384
chore: refine the code
stanleyyconsensys Nov 21, 2024
b7ee224
fix: add execution test
stanleyyconsensys Nov 21, 2024
06aad3a
fix: update execute txn test
stanleyyconsensys Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/starknet-snap/src/__tests__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export function generateTransactionRequests({
type: TransactionType.INVOKE,
networkName: 'Sepolia',
signer: address,
addressIndex: 0,
maxFee: '100',
selectedFeeToken:
feeTokens[Math.floor(generateRandomValue() * feeTokens.length)].symbol,
Expand All @@ -341,6 +342,18 @@ export function generateTransactionRequests({
},
],
includeDeploy: false,
resourceBounds: [
{
l1_gas: {
max_amount: '0',
max_price_per_unit: '0',
},
l2_gas: {
max_amount: '0',
max_price_per_unit: '0',
},
},
],
});
}

Expand Down
27 changes: 27 additions & 0 deletions packages/starknet-snap/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type {
OnHomePageHandler,
OnInstallHandler,
OnUpdateHandler,
OnUserInputHandler,
UserInputEvent,
InterfaceContext,
} from '@metamask/snaps-sdk';
import { MethodNotFoundError } from '@metamask/snaps-sdk';
import { Box, Link, Text } from '@metamask/snaps-sdk/jsx';
Expand Down Expand Up @@ -59,6 +62,7 @@ import type {
ApiRequestParams,
} from './types/snapApi';
import type { SnapState } from './types/snapState';
import { UserInputEventController } from './ui/controllers/user-input-event-controller';
import { upgradeAccContract } from './upgradeAccContract';
import {
ensureJsxSupport,
Expand Down Expand Up @@ -329,3 +333,26 @@ export const onUpdate: OnUpdateHandler = async () => {
export const onHomePage: OnHomePageHandler = async () => {
return await homePageController.execute();
};

/**
* Handle incoming user events coming from the MetaMask clients open interfaces.
*
* @param params - The event parameters.
* @param params.id - The Snap interface ID where the event was fired.
* @param params.event - The event object containing the event type, name, and
* value.
* @param params.context
* @see https://docs.metamask.io/snaps/reference/exports/#onuserinput
*/
export const onUserInput: OnUserInputHandler = async ({
id,
event,
context,
}: {
id: string;
event: UserInputEvent;
context: InterfaceContext | null;
}): Promise<void> => {
stanleyyconsensys marked this conversation as resolved.
Show resolved Hide resolved
const controller = new UserInputEventController(id, event, context);
await controller.handleEvent();
};
22 changes: 22 additions & 0 deletions packages/starknet-snap/src/rpcs/__tests__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@ import type { constants } from 'starknet';

import type { StarknetAccount } from '../../__tests__/helper';
import { generateAccounts, generateRandomValue } from '../../__tests__/helper';
import { TransactionRequestStateManager } from '../../state/request-state-manager';
import type { SnapState } from '../../types/snapState';
import { getExplorerUrl, shortenAddress, toJson } from '../../utils';
import * as snapHelper from '../../utils/snap';
import * as snapUtils from '../../utils/snapUtils';
import * as starknetUtils from '../../utils/starknetUtils';

export const mockTransactionRequestStateManager = () => {
const upsertTransactionRequestSpy = jest.spyOn(
TransactionRequestStateManager.prototype,
'upsertTransactionRequest',
);
const getTransactionRequestSpy = jest.spyOn(
TransactionRequestStateManager.prototype,
'getTransactionRequest',
);
const removeTransactionRequestSpy = jest.spyOn(
TransactionRequestStateManager.prototype,
'removeTransactionRequest',
);

return {
upsertTransactionRequestSpy,
getTransactionRequestSpy,
removeTransactionRequestSpy,
};
};

/**
*
* @param chainId
Expand Down
60 changes: 60 additions & 0 deletions packages/starknet-snap/src/rpcs/execute-txn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { executeTxn as executeTxnUtil } from '../utils/starknetUtils';
import {
generateRandomFee,
mockAccount,
mockTransactionRequestStateManager,
prepareConfirmDialogInteractiveUI,
prepareMockAccount,
} from './__tests__/helper';
Expand Down Expand Up @@ -88,6 +89,7 @@ const prepareMockExecuteTxn = async (
executeTxnUtilSpy,
getEstimatedFeesSpy,
getEstimatedFeesRepsMock,
...mockTransactionRequestStateManager(),
};
};

Expand All @@ -100,6 +102,8 @@ describe('ExecuteTxn', () => {
executeTxnRespMock,
getEstimatedFeesSpy,
getEstimatedFeesRepsMock,
upsertTransactionRequestSpy,
getTransactionRequestSpy,
request,
} = await prepareMockExecuteTxn(
calls.hash,
Expand All @@ -126,6 +130,8 @@ describe('ExecuteTxn', () => {
);
expect(getEstimatedFeesSpy).toHaveBeenCalled();
expect(createAccountSpy).not.toHaveBeenCalled();
expect(upsertTransactionRequestSpy).toHaveBeenCalled();
expect(getTransactionRequestSpy).toHaveBeenCalled();
});

it.each([
Expand Down Expand Up @@ -235,6 +241,60 @@ describe('ExecuteTxn', () => {
},
);

it('throws `Failed to retrieve the updated transaction request` error the transaction request can not retrieve after confirmation', async () => {
const calls = callsExamples.multipleCalls;
const { getTransactionRequestSpy, request } = await prepareMockExecuteTxn(
calls.hash,
calls.calls,
calls.details,
true,
);

getTransactionRequestSpy.mockResolvedValue(null);

await expect(executeTxn.execute(request)).rejects.toThrow(
'Failed to retrieve the updated transaction request',
);
});

it.each([
{
executeTxnResult: callsExamples.multipleCalls.hash,
testCase: 'the transaction executed successfully',
},
{
// Simulate the case where the transaction execution failed and does not return a transaction hash
// An error `Failed to execute transaction` will be thrown in this case
executeTxnResult: '',
testCase: 'the transaction failed to execute',
},
])(
'removes the transaction request from state if $testCase.',
async ({ executeTxnResult }) => {
const calls = callsExamples.multipleCalls;
const { executeTxnUtilSpy, removeTransactionRequestSpy, request } =
await prepareMockExecuteTxn(
executeTxnResult,
calls.calls,
calls.details,
true,
);

executeTxnUtilSpy.mockResolvedValue({
// eslint-disable-next-line @typescript-eslint/naming-convention
transaction_hash: executeTxnResult,
});

try {
await executeTxn.execute(request);
} catch (error) {
// eslint-disable-next-line no-empty
} finally {
expect(removeTransactionRequestSpy).toHaveBeenCalled();
}
},
);

it('throws UserRejectedOpError if user cancels execution', async () => {
const calls = callsExamples.multipleCalls;
const { request, confirmDialogSpy } = await prepareMockExecuteTxn(
Expand Down
Loading
Loading