Skip to content

Commit

Permalink
reorder component items
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoncalves committed Sep 13, 2023
1 parent 04c47e4 commit 77e3d5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/screens/walletConnect/WalletConnect2Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ export const WalletConnect2Provider = ({
prevSessions.filter(prevSession => prevSession.topic !== session.topic),
)
} catch (err) {
console.log(234, err)
// @TODO handle error disconnecting
console.log('WC2.0 error disconnect', err)
}
}

Expand Down
64 changes: 26 additions & 38 deletions src/screens/walletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,36 @@ export const WalletConnectScreen = ({ route }: Props) => {
onUserRejectedSession,
onCreateNewSession,
} = useContext(WalletConnect2Context)

const [disconnectingWC, setDisconnectingWC] = useState<WC2Session | null>(
null,
)

const methods = useForm({ defaultValues: { wcUri: '' } })
const { watch, setValue } = methods
const wcUri = watch('wcUri')

const wc2Sessions: WC2Session[] = sessions.map(session => ({
name: session.peer.metadata.name,
url: session.peer.metadata.url,
key: session.topic,
wc: session,
}))

const handlePaste = async () => {
const clipboardText = await Clipboard.getString()
setValue('wcUri', clipboardText)
}

const onUriSubmitted = () => onCreateNewSession(wcUri)

const handleDisconnectSession = (mergedWc: WC2Session) => async () => {
await onDisconnectSession(mergedWc.wc)
setDisconnectingWC(null)
}

const onWCDisconnect = (wc: WC2Session) => () => setDisconnectingWC(wc)

/**
* useEffect that watches when we pass data to the route params and connects user depending on WC version
*/
Expand All @@ -85,16 +111,6 @@ export const WalletConnectScreen = ({ route }: Props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [route.params?.data])

const handleDisconnectSession = (mergedWc: WC2Session) => async () => {
try {
await onDisconnectSession(mergedWc.wc)
setDisconnectingWC(null)
} catch (err) {
// @TODO handle error disconnecting
console.log(63, 'WC2.0 error disconnect', err)
}
}

/**
* When there is an error in WC2.0 - this effect will show it to the UI
*/
Expand All @@ -105,40 +121,12 @@ export const WalletConnectScreen = ({ route }: Props) => {
}
}, [walletConnect2Error, t, setWalletConnect2Error])

const onWCDisconnect = (wc: WC2Session) => () => setDisconnectingWC(wc)

const wc2Sessions: WC2Session[] = useMemo(
() =>
sessions.map(session => {
return {
name: session.peer.metadata.name,
url: session.peer.metadata.url,
key: session.topic,
wc: session,
}
}),
[sessions],
)

useEffect(() => {
if (isFocused) {
dispatch(changeTopColor(sharedColors.secondary))
}
}, [dispatch, isFocused])

const methods = useForm({ defaultValues: { wcUri: '' } })
const { watch, setValue } = methods
const wcUri = watch('wcUri')

const handlePaste = async () => {
const clipboardText = await Clipboard.getString()
setValue('wcUri', clipboardText)
}

const onUriSubmitted = () => {
onCreateNewSession(wcUri)
}

return (
<KeyboardAvoidingView
style={sharedStyles.screen}
Expand Down

0 comments on commit 77e3d5d

Please sign in to comment.