Skip to content

Commit 4fcdda6

Browse files
authored
Fix send flow snap (#3267)
Previous PR failed to parse the event value as it is a `CaipAccountId`, updated the implementation to parse the value before checking against the struct.
1 parent 82ea67b commit 4fcdda6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/examples/packages/send-flow/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "5qERUafayyDWQ12V/+htfEs2wzmQwhSn0EcQolI7quo=",
10+
"shasum": "INn+njbWhdgWBpvU4y5opvJpDWSyT14xl7DQEvwY0JM=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/send-flow/src/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import type {
33
OnHomePageHandler,
44
OnUserInputHandler,
55
OnRpcRequestHandler,
6+
CaipAccountId,
67
} from '@metamask/snaps-sdk';
78
import { UserInputEventType } from '@metamask/snaps-sdk';
89
import { is } from '@metamask/superstruct';
9-
import { HexChecksumAddressStruct } from '@metamask/utils';
10+
import { HexChecksumAddressStruct, parseCaipAccountId } from '@metamask/utils';
1011

1112
import { SendFlow } from './components';
1213
import { accountsArray, accounts } from './data';
@@ -102,6 +103,14 @@ export const onUserInput: OnUserInputHandler = async ({
102103
case 'amount':
103104
case 'to': {
104105
// For testing purposes, we display the avatar if the address is a valid hex checksum address.
106+
let parsedAddress;
107+
try {
108+
parsedAddress = parseCaipAccountId(
109+
event.value as CaipAccountId,
110+
).address;
111+
} catch {
112+
/** noop */
113+
}
105114
await snap.request({
106115
method: 'snap_updateInterface',
107116
params: {
@@ -114,7 +123,7 @@ export const onUserInput: OnUserInputHandler = async ({
114123
total={total}
115124
fees={fees}
116125
errors={formErrors}
117-
displayAvatar={is(event.value, HexChecksumAddressStruct)}
126+
displayAvatar={is(parsedAddress, HexChecksumAddressStruct)}
118127
/>
119128
),
120129
},

0 commit comments

Comments
 (0)