import * as React from "react" ; import { CoreContext , useSelector as useKirbySelector , CenteredPage } from "@kirby-web3/child-react" ; import { SignatureInterceptorPlugin , ProviderTypes } from "@kirby-web3/plugin-ethereum" ; export const SignatureConfirm = ( ) => { const ctx = React . useContext ( CoreContext ) ; const sig = ctx . core . plugins . signatureInterceptor as SignatureInterceptorPlugin ; const [ isPending , setPending ] = React . useState ( false ) ; const providerType = useKirbySelector ( ( state ) => state . ethereum . providerType ) ; const plaintext = useKirbySelector ( ( state ) => { if ( state . signatureInterceptor . requests && state . signatureInterceptor . requests [ 0 ] ) { return state . signatureInterceptor . requests [ 0 ] . plaintext ; } } ) ; React . useMemo ( ( ) => { if ( [ ProviderTypes . METAMASK , ProviderTypes . PORTIS ] . indexOf ( providerType ) > - 1 ) { sig . approveAction ( ) ; setPending ( true ) ; } } , [ ] ) ; if ( isPending ) { return < > < />; } return ( < CenteredPage > < small > signature requested : < /small> < div > { plaintext } < /div> < div > < button onClick = { ( ) => sig . approveAction ( ) } > approve < /button> < button onClick = { ( ) => sig . rejectAction ( ) } > reject < /button> < /div> < /CenteredPage>); } ;