Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init pairing if last connected wallet not available
Browse files Browse the repository at this point in the history
katspaugh committed May 12, 2022
1 parent 059276f commit 021ea2d
Showing 5 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -7,9 +7,7 @@ import { Link } from '@gnosis.pm/safe-react-components'
import QRCode from 'qrcode.react'

import Paragraph from 'src/components/layout/Paragraph'
import usePairing from 'src/logic/wallets/pairing/hooks/usePairing'
import { initPairing, isPairingModule } from 'src/logic/wallets/pairing/utils'
import { useGetPairingUri } from 'src/logic/wallets/pairing/hooks/useGetPairingUri'
import { getPairingUri, initPairing, isPairingModule } from 'src/logic/wallets/pairing/utils'
import { OVERVIEW_EVENTS } from 'src/utils/events/overview'
import Track from 'src/components/Track'
import AppstoreButton from 'src/components/AppstoreButton'
@@ -59,9 +57,8 @@ type PairingDetailsProps = {
}

const PairingDetails = ({ vertical = false }: PairingDetailsProps): ReactElement => {
const uri = useGetPairingUri()
const uri = getPairingUri()
const isPairingLoaded = isPairingModule()
usePairing()

const qr = uri ? (
<QRCode value={uri} size={QR_DIMENSION} />
4 changes: 3 additions & 1 deletion src/components/AppLayout/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import {
} from 'src/logic/wallets/store/selectors'
import onboard, { loadLastUsedProvider } from 'src/logic/wallets/onboard'
import { isSupportedWallet } from 'src/logic/wallets/utils/walletList'
import { isPairingSupported } from 'src/logic/wallets/pairing/utils'
import { initPairing, isPairingSupported } from 'src/logic/wallets/pairing/utils'
import { wrapInSuspense } from 'src/utils/wrapInSuspense'

const HidePairingModule = lazy(
@@ -44,6 +44,8 @@ const HeaderComponent = (): React.ReactElement => {
const isProviderEnabled = lastUsedProvider && isSupportedWallet(lastUsedProvider)
if (isProviderEnabled) {
await onboard().walletSelect(lastUsedProvider)
} else if (isPairingSupported()) {
await initPairing()
}
}

4 changes: 2 additions & 2 deletions src/logic/wallets/onboard.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import { _getChainId, getChainName } from 'src/config'
import transactionDataCheck from 'src/logic/wallets/transactionDataCheck'
import { getSupportedWallets } from 'src/logic/wallets/utils/walletList'
import { ChainId, CHAIN_ID } from 'src/config/chain.d'
import { loadFromStorageWithExpiry, removeFromStorage, saveToStorageWithExpiry } from 'src/utils/storage'
import { loadFromStorageWithExpiry, removeFromStorageWithExpiry, saveToStorageWithExpiry } from 'src/utils/storage'
import { store } from 'src/store'
import updateProviderWallet from 'src/logic/wallets/store/actions/updateProviderWallet'
import updateProviderAccount from 'src/logic/wallets/store/actions/updateProviderAccount'
@@ -42,7 +42,7 @@ export const loadLastUsedProvider = (): string | undefined => {
}

export const removeLastUsedProvider = (): void => {
removeFromStorage(LAST_USED_PROVIDER_KEY)
removeFromStorageWithExpiry(LAST_USED_PROVIDER_KEY)
}

const getNetworkName = (chainId: ChainId) => {
15 changes: 0 additions & 15 deletions src/logic/wallets/pairing/hooks/useGetPairingUri.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/utils/storage/index.ts
Original file line number Diff line number Diff line change
@@ -43,3 +43,7 @@ export const saveToStorageWithExpiry = <T = unknown>(key: string, value: T, expi
export const loadFromStorageWithExpiry = <T = unknown>(key: string): T | undefined => {
return storage.getWithExpiry<T>(key)
}

export const removeFromStorageWithExpiry = (key: string): void => {
return storage.removeItem(key)
}

0 comments on commit 021ea2d

Please sign in to comment.