import React , { FunctionComponent , useEffect } from "react" ; import { observer } from "mobx-react-lite" ; import { useStore } from "../../stores" ; import { SignModal } from "../../modals/sign" ; import { LedgerGranterModal } from "../../modals/ledger" ; import { WalletConnectApprovalModal } from "../../modals/wallet-connect-approval" ; import { WCMessageRequester } from "../../stores/wallet-connect/msg-requester" ; import { WCGoBackToBrowserModal } from "../../modals/wc-go-back-to-browser" ; import { BackHandler , Platform } from "react-native" ; import { LoadingScreenModal } from "../loading-screen/modal" ; import { KeyRingStatus } from "@keplr-wallet/background" ; export const InteractionModalsProivder = observer ( ( { children } ) => { const { keyRingStore , ledgerInitStore , permissionStore , signInteractionStore , walletConnectStore , } = useStore ( ) ; useEffect ( ( ) => { if ( walletConnectStore . needGoBackToBrowser && Platform . OS === "android" ) { BackHandler . exitApp ( ) ; } } , [ walletConnectStore . needGoBackToBrowser ] ) ; useEffect ( ( ) => { for ( const data of permissionStore . waitingDatas ) { if ( data . data . origins . length !== 1 || ! WCMessageRequester . isVirtualSessionURL ( data . data . origins [ 0 ] ) ) { permissionStore . reject ( data . id ) ; } } } , [ permissionStore , permissionStore . waitingDatas ] ) ; return ( < React . Fragment > { } { keyRingStore . status === KeyRingStatus . UNLOCKED && walletConnectStore . isPendingClientFromDeepLink ? ( < LoadingScreenModal isOpen = { true } close = { ( ) => { } } />) : null} { walletConnectStore . needGoBackToBrowser && Platform . OS === "ios" ? ( < WCGoBackToBrowserModal isOpen = { walletConnectStore . needGoBackToBrowser } close = { ( ) => { walletConnectStore . clearNeedGoBackToBrowser ( ) ; } } />) : null} { } { ledgerInitStore . isInitNeeded ? ( < LedgerGranterModal isOpen = { true } close = { ( ) => ledgerInitStore . abortAll ( ) } />) : null} { permissionStore . waitingDatas . map ( ( data ) => { if ( data . data . origins . length === 1 ) { if ( WCMessageRequester . isVirtualSessionURL ( data . data . origins [ 0 ] ) ) { return ( < WalletConnectApprovalModal key = { data . id } isOpen = { true } close = { ( ) => permissionStore . reject ( data . id ) } id = { data . id } data = { data . data } / > ) ; } } return null ; } ) } { signInteractionStore . waitingData ? ( < SignModal isOpen = { true } close = { ( ) => signInteractionStore . rejectAll ( ) } />) : null} { children } < /React.Fragment>); } ) ;