@@ -3,16 +3,13 @@ import type {
33 OnHomePageHandler ,
44 OnUserInputHandler ,
55 OnRpcRequestHandler ,
6- CaipAccountId ,
76} from '@metamask/snaps-sdk' ;
87import { UserInputEventType } from '@metamask/snaps-sdk' ;
9- import { is } from '@metamask/superstruct' ;
10- import { HexChecksumAddressStruct , parseCaipAccountId } from '@metamask/utils' ;
118
129import { SendFlow } from './components' ;
1310import { accountsArray , accounts } from './data' ;
1411import type { SendFormState , SendFlowContext } from './types' ;
15- import { formValidation , generateSendFlow } from './utils' ;
12+ import { formValidation , generateSendFlow , isCaipHexAddress } from './utils' ;
1613
1714/**
1815 * Handle incoming JSON-RPC requests from the dapp, sent through the
@@ -102,15 +99,6 @@ export const onUserInput: OnUserInputHandler = async ({
10299 switch ( event . name ) {
103100 case 'amount' :
104101 case 'to' : {
105- // 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- }
114102 await snap . request ( {
115103 method : 'snap_updateInterface' ,
116104 params : {
@@ -123,13 +111,16 @@ export const onUserInput: OnUserInputHandler = async ({
123111 total = { total }
124112 fees = { fees }
125113 errors = { formErrors }
126- displayAvatar = { is ( parsedAddress , HexChecksumAddressStruct ) }
114+ // For testing purposes, we display the avatar if the address is
115+ // a valid hex checksum address.
116+ displayAvatar = { isCaipHexAddress ( event . value ) }
127117 />
128118 ) ,
129119 } ,
130120 } ) ;
131121 break ;
132122 }
123+
133124 case 'accountSelector' : {
134125 await snap . request ( {
135126 method : 'snap_updateInterface' ,
@@ -150,6 +141,7 @@ export const onUserInput: OnUserInputHandler = async ({
150141
151142 break ;
152143 }
144+
153145 default :
154146 break ;
155147 }
0 commit comments