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 100 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
14 changes: 13 additions & 1 deletion packages/starknet-snap/src/__tests__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export function generateTransactionRequests({
networkName: 'Sepolia',
signer: address,
maxFee: '100',
feeToken:
selectedFeeToken:
feeTokens[Math.floor(generateRandomValue() * feeTokens.length)].symbol,
calls: [
{
Expand All @@ -341,6 +341,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
41 changes: 40 additions & 1 deletion packages/starknet-snap/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import type {
OnHomePageHandler,
OnInstallHandler,
OnUpdateHandler,
OnUserInputHandler,
UserInputEvent,
InterfaceContext,
} from '@metamask/snaps-sdk';
import { MethodNotFoundError } from '@metamask/snaps-sdk';
import { MethodNotFoundError, UserInputEventType } from '@metamask/snaps-sdk';
import { Box, Link, Text } from '@metamask/snaps-sdk/jsx';

import { addNetwork } from './addNetwork';
Expand Down Expand Up @@ -60,6 +63,7 @@ import type {
} from './types/snapApi';
import type { SnapState } from './types/snapState';
import { upgradeAccContract } from './upgradeAccContract';
import { feeTokenSelectorController } from './user-inputs';
import {
getDappUrl,
getStateData,
Expand Down Expand Up @@ -341,3 +345,38 @@ 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 generateEventKey = (type: UserInputEventType, name: string) =>
`${type}_${name}`;
const eventKey = generateEventKey(event.type, event.name ?? '');

switch (eventKey) {
case generateEventKey(
stanleyyconsensys marked this conversation as resolved.
Show resolved Hide resolved
UserInputEventType.InputChangeEvent,
'feeTokenSelector',
):
await feeTokenSelectorController.execute(id, event, context);
break;
default:
throw new MethodNotFoundError() as unknown as Error;
stanleyyconsensys marked this conversation as resolved.
Show resolved Hide resolved
}
};
14 changes: 14 additions & 0 deletions packages/starknet-snap/src/rpcs/__tests__/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ export function prepareConfirmDialog() {
};
}

/**
*
*/
export function prepareConfirmDialogInteractiveUI() {
const confirmDialogSpy = jest.spyOn(
snapHelper,
'createInteractiveConfirmDialog',
);
confirmDialogSpy.mockResolvedValue(true);
return {
confirmDialogSpy,
};
}

/**
*
*/
Expand Down
7 changes: 4 additions & 3 deletions packages/starknet-snap/src/rpcs/execute-txn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { executeTxn as executeTxnUtil } from '../utils/starknetUtils';
import {
generateRandomFee,
mockAccount,
prepareConfirmDialog,
prepareConfirmDialogInteractiveUI,
prepareMockAccount,
} from './__tests__/helper';
import type { ExecuteTxnParams } from './execute-txn';
Expand All @@ -35,7 +35,7 @@ const prepareMockExecuteTxn = async (
networks: [STARKNET_SEPOLIA_TESTNET_NETWORK],
transactions: [],
};
const { confirmDialogSpy } = prepareConfirmDialog();
const { confirmDialogSpy } = prepareConfirmDialogInteractiveUI();

const account = await mockAccount(constants.StarknetChainId.SN_SEPOLIA);
prepareMockAccount(account, state);
Expand Down Expand Up @@ -141,6 +141,7 @@ describe('ExecuteTxn', () => {
'stores transaction in state correctly if the params `calls` is $testCaseTitle',
async ({ calls }: { calls: any }) => {
const call = Array.isArray(calls.calls) ? calls.calls[0] : calls.calls;
const callsArray = ([] as Call[]).concat(calls.calls);
const {
account,
createAccountSpy,
Expand All @@ -163,7 +164,7 @@ describe('ExecuteTxn', () => {
STARKNET_SEPOLIA_TESTNET_NETWORK,
account.address,
account.privateKey,
request.calls,
callsArray,
undefined,
{
...calls.details,
Expand Down
Loading
Loading