import React from 'react'; import { Image, View, Modal } from 'react-native'; import { Button, Text } from 'react-native-paper'; import { SessionTypes } from '@walletconnect/types'; import { getSdkError } from '@walletconnect/utils'; import { PairingModalProps } from '../types'; import styles from '../styles/stylesheet'; import { web3wallet } from '../utils/wallet-connect/WalletConnectUtils'; const PairingModal = ({ visible, currentProposal, currentEthAddresses, setCurrentProposal, setModalVisible, setToastVisible, }: PairingModalProps) => { const url = currentProposal?.params?.proposer?.metadata.url; const methods = currentProposal?.params?.requiredNamespaces.eip155.methods; const events = currentProposal?.params?.requiredNamespaces.eip155.events; const chains = currentProposal?.params?.requiredNamespaces.eip155.chains; const icon = currentProposal?.params.proposer.metadata.icons[0]; const handleAccept = async () => { if (currentProposal) { const { id, params } = currentProposal; const { requiredNamespaces, relays } = params; const namespaces: SessionTypes.Namespaces = {}; Object.keys(requiredNamespaces).forEach(key => { const accounts: string[] = []; requiredNamespaces[key].chains!.map((chain: any) => { currentEthAddresses.map(acc => accounts.push(`${chain}:${acc}`)); }); namespaces[key] = { accounts, methods: requiredNamespaces[key].methods, events: requiredNamespaces[key].events, }; }); await web3wallet.approveSession({ id, relayProtocol: relays[0].protocol, namespaces, }); setModalVisible(false); setToastVisible(true); setCurrentProposal(undefined); } }; const handleReject = async () => { if (currentProposal) { const { id } = currentProposal; await web3wallet.rejectSession({ id, reason: getSdkError('USER_REJECTED_METHODS'), }); setModalVisible(false); setCurrentProposal(undefined); } }; return ( {icon && ( )} {url} Connect to this site? Chains: {chains} Methods Requested: {methods?.map(method => ( {method} ))} Events Requested: {events?.map(event => ( {event} ))} ); }; export default PairingModal;