Skip to content

Commit

Permalink
Adjusted for new conflicting changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Freshenext committed Jul 24, 2023
1 parent 83914ff commit 1d89f03
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 79 deletions.
6 changes: 3 additions & 3 deletions src/screens/walletConnect/WalletConnect2Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { getSdkError } from '@walletconnect/utils'
import Web3Wallet, { Web3WalletTypes } from '@walletconnect/web3wallet'
import { IWeb3Wallet } from '@walletconnect/web3wallet'
import { WalletConnectAdapter } from '@rsksmart/rif-wallet-adapters'
import { RIFWallet } from '@rsksmart/rif-wallet-core'

import {
createWeb3Wallet,
getProposalErrorComparedWithRskNamespace,
rskWalletConnectNamespace,
WalletConnect2SdkErrorString,
} from 'screens/walletConnect/walletConnect2.utils'
import { useAppSelector } from 'store/storeUtils'
import { selectActiveWallet } from 'store/slices/settingsSlice'

const onSessionApprove = async (
web3wallet: Web3Wallet,
Expand Down Expand Up @@ -81,12 +80,13 @@ export const WalletConnect2Context =

interface WalletConnect2ProviderProps {
children: ReactElement
wallet: RIFWallet
}

export const WalletConnect2Provider = ({
children,
wallet,
}: WalletConnect2ProviderProps) => {
const { wallet } = useAppSelector(selectActiveWallet)
const [sessions, setSessions] = useState<SessionStruct[]>([])
const [pendingSession, setPendingSession] = useState<
PendingSession | undefined
Expand Down
158 changes: 82 additions & 76 deletions src/screens/walletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
WalletConnectContext,
WalletConnectProviderElement,
} from './WalletConnectContext'
import { SessionStruct, WalletConnect2Context } from './WalletConnect2Context'
import {
SessionStruct,
WalletConnect2Context,
WalletConnect2Provider,
} from './WalletConnect2Context'

type Props = RootTabsScreenProps<rootTabsRouteNames.WalletConnect>

Expand Down Expand Up @@ -117,84 +121,86 @@ export const WalletConnectScreen = ({ route }: Props) => {
)
return (
<WalletConnectProviderElement>
<View style={styles.parent}>
<View style={styles.header}>
<View style={styles.innerHeader1}>
<Typography type="h2">{t('dapps_title')}</Typography>
<Typography type="h5" style={styles.subtitle}>
{t('dapps_instructions')}
</Typography>
<WalletConnect2Provider wallet={wallet}>
<View style={styles.parent}>
<View style={styles.header}>
<View style={styles.innerHeader1}>
<Typography type="h2">{t('dapps_title')}</Typography>
<Typography type="h5" style={styles.subtitle}>
{t('dapps_instructions')}
</Typography>
</View>
<View style={styles.innerHeader2} />
</View>
<View style={styles.innerHeader2} />
</View>

{mergedWalletConnectSessions.length === 0 ? (
<>
<Image
source={require('src/images/empty-dapps.png')}
style={styles.noDappsImage}
/>
</>
) : (
<ScrollView style={styles.dappsList}>
{mergedWalletConnectSessions.map(session => (
<DappItem
key={session.key}
name={session.name}
url={session.url}
isDisconnecting={session === disconnectingWC}
onDisconnect={onWCDisconnect(session)}
{mergedWalletConnectSessions.length === 0 ? (
<>
<Image
source={require('src/images/empty-dapps.png')}
style={styles.noDappsImage}
/>
</>
) : (
<ScrollView style={styles.dappsList}>
{mergedWalletConnectSessions.map(session => (
<DappItem
key={session.key}
name={session.name}
url={session.url}
isDisconnecting={session === disconnectingWC}
onDisconnect={onWCDisconnect(session)}
/>
))}
</ScrollView>
)}

{pendingConnector ? (
<ConfirmationModal
isVisible={!pendingConnector.connected}
title={t('dapps_confirmation_title')}
description={`${t('dapps_confirmation_description')}${
pendingConnector.peerMeta?.name
? ` ${pendingConnector.peerMeta?.name}`
: ''
}?`}
okText={t('dapps_confirmation_button_connect')}
cancelText={t('dapps_confirmation_button_cancel')}
onOk={() => handleApprove(pendingConnector, wallet)}
onCancel={() => handleReject(pendingConnector)}
/>
) : null}

{pendingSession ? (
<ConfirmationModal
isVisible
title={t('dapps_confirmation_title')}
description={`${t('dapps_confirmation_description')}${
pendingSession.proposal.params.proposer.metadata.name
? ` ${pendingSession.proposal.params.proposer.metadata.name}`
: ''
}?`}
okText={t('dapps_confirmation_button_connect')}
cancelText={t('dapps_confirmation_button_cancel')}
onOk={onUserApprovedSession}
onCancel={onUserRejectedSession}
/>
))}
</ScrollView>
)}

{pendingConnector ? (
<ConfirmationModal
isVisible={!pendingConnector.connected}
title={t('dapps_confirmation_title')}
description={`${t('dapps_confirmation_description')}${
pendingConnector.peerMeta?.name
? ` ${pendingConnector.peerMeta?.name}`
: ''
}?`}
okText={t('dapps_confirmation_button_connect')}
cancelText={t('dapps_confirmation_button_cancel')}
onOk={() => handleApprove(pendingConnector, wallet)}
onCancel={() => handleReject(pendingConnector)}
/>
) : null}

{pendingSession ? (
<ConfirmationModal
isVisible
title={t('dapps_confirmation_title')}
description={`${t('dapps_confirmation_description')}${
pendingSession.proposal.params.proposer.metadata.name
? ` ${pendingSession.proposal.params.proposer.metadata.name}`
: ''
}?`}
okText={t('dapps_confirmation_button_connect')}
cancelText={t('dapps_confirmation_button_cancel')}
onOk={onUserApprovedSession}
onCancel={onUserRejectedSession}
/>
) : null}

{disconnectingWC ? (
<ConfirmationModal
isVisible={Boolean(disconnectingWC)}
title={t('dapps_confirm_disconnection_title')}
description={`${t('dapps_confirm_disconnection_description')}${
disconnectingWC.name ? ` ${disconnectingWC.name}` : ''
}?`}
okText={t('dapps_confirm_disconnection_confirm')}
cancelText={t('dapps_confirm_disconnection_cancel')}
onOk={handleDisconnectSession(disconnectingWC)}
onCancel={() => setDisconnectingWC(null)}
/>
) : null}
</View>
) : null}

{disconnectingWC ? (
<ConfirmationModal
isVisible={Boolean(disconnectingWC)}
title={t('dapps_confirm_disconnection_title')}
description={`${t('dapps_confirm_disconnection_description')}${
disconnectingWC.name ? ` ${disconnectingWC.name}` : ''
}?`}
okText={t('dapps_confirm_disconnection_confirm')}
cancelText={t('dapps_confirm_disconnection_cancel')}
onOk={handleDisconnectSession(disconnectingWC)}
onCancel={() => setDisconnectingWC(null)}
/>
) : null}
</View>
</WalletConnect2Provider>
</WalletConnectProviderElement>
)
}
Expand Down

0 comments on commit 1d89f03

Please sign in to comment.