Changeset View
Changeset View
Standalone View
Standalone View
native/account/siwe-panel.react.js
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | function SIWEPanel(props: Props): React.Node { | ||||
React.useEffect(() => { | React.useEffect(() => { | ||||
// When the snapPoints change, always reset to the first one | // When the snapPoints change, always reset to the first one | ||||
// Without this, when we close the WalletConnect modal we don't resize | // Without this, when we close the WalletConnect modal we don't resize | ||||
snapToIndex?.(0); | snapToIndex?.(0); | ||||
}, [snapToIndex, snapPoints]); | }, [snapToIndex, snapPoints]); | ||||
const closeBottomSheet = bottomSheetRef.current?.close; | const closeBottomSheet = bottomSheetRef.current?.close; | ||||
const { closing, onSuccessfulWalletSignature } = props; | const { closing, onSuccessfulWalletSignature } = props; | ||||
const disableOnClose = React.useRef(false); | |||||
const handleMessage = React.useCallback( | const handleMessage = React.useCallback( | ||||
async event => { | async event => { | ||||
const data: SIWEWebViewMessage = JSON.parse(event.nativeEvent.data); | const data: SIWEWebViewMessage = JSON.parse(event.nativeEvent.data); | ||||
if (data.type === 'siwe_success') { | if (data.type === 'siwe_success') { | ||||
const { address, message, signature } = data; | const { address, message, signature } = data; | ||||
if (address && signature) { | if (address && signature) { | ||||
disableOnClose.current = true; | |||||
closeBottomSheet?.(); | closeBottomSheet?.(); | ||||
await onSuccessfulWalletSignature({ address, message, signature }); | await onSuccessfulWalletSignature({ address, message, signature }); | ||||
} | } | ||||
} else if (data.type === 'siwe_closed') { | } else if (data.type === 'siwe_closed') { | ||||
onClosing(); | onClosing(); | ||||
closeBottomSheet?.(); | closeBottomSheet?.(); | ||||
} else if (data.type === 'walletconnect_modal_update') { | } else if (data.type === 'walletconnect_modal_update') { | ||||
setWalletConnectModalOpen(data.state === 'open'); | setWalletConnectModalOpen(data.state === 'open'); | ||||
Show All 36 Lines | () => ({ | ||||
backgroundColor: 'white', | backgroundColor: 'white', | ||||
}), | }), | ||||
[], | [], | ||||
); | ); | ||||
const { onClosed } = props; | const { onClosed } = props; | ||||
const onBottomSheetChange = React.useCallback( | const onBottomSheetChange = React.useCallback( | ||||
(index: number) => { | (index: number) => { | ||||
if (disableOnClose.current) { | |||||
disableOnClose.current = false; | |||||
return; | |||||
} | |||||
if (index === -1) { | if (index === -1) { | ||||
onClosed(); | onClosed(); | ||||
} | } | ||||
}, | }, | ||||
[onClosed], | [onClosed], | ||||
); | ); | ||||
let bottomSheet; | let bottomSheet; | ||||
Show All 31 Lines |