Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't require wallet connection #1452

Draft
wants to merge 92 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
f9b3eb5
initial commit
spsjvc Jan 19, 2024
5647bc7
hide token balance while not connected
spsjvc Jan 19, 2024
ac2904c
move to separate file
spsjvc Jan 19, 2024
761f76b
clean up
spsjvc Jan 19, 2024
8983c6c
rename component
spsjvc Jan 19, 2024
7fc643a
christophe and fionna told me to make those hooks
spsjvc Jan 19, 2024
83ff1e0
rename files
spsjvc Jan 19, 2024
fd27e67
remove return value
spsjvc Jan 19, 2024
6c5f22f
blah
spsjvc Jan 19, 2024
9024c9f
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jan 22, 2024
ffdaa64
add settings toggle
fionnachan Jan 22, 2024
7afe65c
remove address requirement for select token
fionnachan Jan 22, 2024
b7e88e2
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Feb 9, 2024
a4b42b9
clean up after merging
fionnachan Feb 9, 2024
4d41c70
Fix gas loading when user is not connected
chrstph-dvx Feb 12, 2024
31ca518
Allow token import for non connected user
chrstph-dvx Feb 12, 2024
b09541e
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Mar 6, 2024
2bc8d60
update padding
fionnachan Mar 6, 2024
70009f6
clean up
fionnachan Mar 6, 2024
0cfd82b
feat: add Xai Sepolia (#1580)
brtkx Mar 7, 2024
8308443
Merge branch 'master' into feat-dont-require-wallet
chrstph-dvx Mar 8, 2024
3559b13
Move addBridgeTokenListToBridge to useArbTokenBridge
chrstph-dvx Mar 8, 2024
8da44c8
Add condition for non connected user in usGasSummary
chrstph-dvx Mar 8, 2024
372d448
Show 0 balance for non connected user in TokenRow
chrstph-dvx Mar 8, 2024
eacaf21
Merge branch 'master' into feat-dont-require-wallet
chrstph-dvx Mar 8, 2024
cac297d
Fix e2e tests
chrstph-dvx Mar 11, 2024
4d1d3a0
Record e2e
chrstph-dvx Mar 11, 2024
ccaa45b
Set URL with query param in cy.visit
chrstph-dvx Mar 11, 2024
ad56e66
Pass query param in login
chrstph-dvx Mar 11, 2024
bd63a10
Remove query param, fix connect wallet getter
chrstph-dvx Mar 11, 2024
d487132
Remove video record
chrstph-dvx Mar 11, 2024
17fcc0e
Fix import token test
chrstph-dvx Mar 13, 2024
5963c24
Merge branch 'master' into feat-dont-require-wallet
chrstph-dvx Mar 13, 2024
185f985
Rework type
chrstph-dvx Mar 13, 2024
cff40a4
Remove cypress logs
chrstph-dvx Mar 13, 2024
1fb780b
Record failling tests
chrstph-dvx Mar 13, 2024
9c6386f
WIP tx history
chrstph-dvx Mar 13, 2024
fa6956b
Fix import token test
chrstph-dvx Mar 13, 2024
a3e5a46
Add minimum amount in e2e tests
chrstph-dvx Mar 13, 2024
b081628
Don't connect metamask in importToken test
chrstph-dvx Mar 13, 2024
b155e33
Remove unecessary wait
chrstph-dvx Mar 13, 2024
9e2cbf5
Update connect wallet button color
chrstph-dvx Mar 13, 2024
c4c2ac4
try fix tx history
brtkx Mar 14, 2024
34e738f
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jul 17, 2024
e3899dc
show gas estimation for unconnected wallet
fionnachan Jul 17, 2024
4a26749
show gas estimate on summary panel; show 0 balance for ETH
fionnachan Jul 17, 2024
6c8a094
fix merge conflicts
fionnachan Jul 17, 2024
628b2df
undo useArbTokenBridge changes
fionnachan Jul 17, 2024
1e0bca7
revert to old way of calling addBridgeTokenListToBridge
fionnachan Jul 17, 2024
01440ca
update useBalance test
fionnachan Jul 18, 2024
b919b1a
fix cypress type
fionnachan Jul 18, 2024
4410acf
hide tx history button when not connected
fionnachan Jul 18, 2024
58aa6ec
turn off video recordings
fionnachan Jul 18, 2024
706aea6
Merge branch 'master' into feat-dont-require-wallet
fionnachan Jul 18, 2024
a46e804
fix bug
fionnachan Jul 18, 2024
1cb8915
Merge branch 'feat-dont-require-wallet' of github.com:OffchainLabs/ar…
fionnachan Jul 18, 2024
3ae13c1
undo unnecessary changes?
fionnachan Jul 18, 2024
f1f8cd4
Merge branch 'master' into feat-dont-require-wallet
fionnachan Jul 19, 2024
bb03868
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jul 19, 2024
7b8b0da
update tests
fionnachan Jul 19, 2024
9434492
update
fionnachan Jul 19, 2024
82be657
try
fionnachan Jul 19, 2024
24d4540
Merge branch 'master' into feat-dont-require-wallet
fionnachan Jul 22, 2024
cf2fe84
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jul 23, 2024
ffaaed9
Merge branch 'master' into feat-dont-require-wallet
fionnachan Jul 23, 2024
ec99753
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jul 29, 2024
38ab23e
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jul 29, 2024
692932b
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jul 29, 2024
5711ed3
minor changes
fionnachan Jul 29, 2024
abdb15e
update
fionnachan Jul 29, 2024
aad2762
Merge branch 'master' into feat-dont-require-wallet
fionnachan Jul 30, 2024
c4f6b11
remove workaround
fionnachan Jul 30, 2024
23d11b0
Merge branch 'master' into feat-dont-require-wallet
fionnachan Jul 30, 2024
9e6d9cd
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Jul 31, 2024
b3e758b
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Aug 5, 2024
e5f7919
Merge branch 'master' into feat-dont-require-wallet
fionnachan Aug 6, 2024
89f1dae
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Aug 8, 2024
fd7e13b
Merge branch 'master' into feat-dont-require-wallet
fionnachan Aug 12, 2024
3b1e1ce
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Aug 20, 2024
4bbabfb
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Aug 21, 2024
d16ba20
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Aug 29, 2024
660868c
undo changes
fionnachan Aug 29, 2024
43f81d3
Merge branch 'master' into feat-dont-require-wallet
fionnachan Aug 30, 2024
5c15c73
Merge branch 'master' into feat-dont-require-wallet
fionnachan Sep 2, 2024
cd4de57
Merge branch 'master' into feat-dont-require-wallet
fionnachan Sep 3, 2024
b3de47e
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Sep 9, 2024
be282e0
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Sep 16, 2024
efe9ccf
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Oct 7, 2024
6367f2b
return 0 balance when wallet is not connected
fionnachan Oct 7, 2024
8364d25
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Oct 22, 2024
a79bf54
update
fionnachan Oct 22, 2024
9417a00
Merge remote-tracking branch 'origin/master' into feat-dont-require-w…
fionnachan Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 11 additions & 140 deletions packages/arb-token-bridge-ui/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { useCallback, useEffect, useState } from 'react'
import { useEffect, useState } from 'react'
import { useAccount, WagmiConfig } from 'wagmi'
import { darkTheme, RainbowKitProvider, Theme } from '@rainbow-me/rainbowkit'

import { useAccount, useNetwork, WagmiConfig, useDisconnect } from 'wagmi'
import {
darkTheme,
RainbowKitProvider,
Theme,
useConnectModal
} from '@rainbow-me/rainbowkit'
import merge from 'lodash-es/merge'
import axios from 'axios'
import { createOvermind, Overmind } from 'overmind'
Expand All @@ -24,23 +19,16 @@ import { ArbTokenBridgeStoreSync } from '../syncers/ArbTokenBridgeStoreSync'
import { BalanceUpdater } from '../syncers/BalanceUpdater'
import { TokenListSyncer } from '../syncers/TokenListSyncer'
import { Header } from '../common/Header'
import { HeaderAccountPopover } from '../common/HeaderAccountPopover'
import { getNetworkName } from '../../util/networks'
import {
ArbQueryParamProvider,
useArbQueryParams
} from '../../hooks/useArbQueryParams'
import { ArbQueryParamProvider } from '../../hooks/useArbQueryParams'
import { TOS_LOCALSTORAGE_KEY } from '../../constants'
import { getProps } from '../../util/wagmi/setup'
import { useAccountIsBlocked } from '../../hooks/useAccountIsBlocked'
import { useCCTPIsBlocked } from '../../hooks/CCTP/useCCTPIsBlocked'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
import { sanitizeQueryParams, useNetworks } from '../../hooks/useNetworks'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { HeaderConnectWalletButton } from '../common/HeaderConnectWalletButton'
import { onDisconnectHandler } from '../../util/walletConnectUtils'
import { addressIsSmartContract } from '../../util/AddressUtils'
import { useSyncConnectedChainToAnalytics } from './useSyncConnectedChainToAnalytics'
import { useSyncConnectedChainToQueryParams } from './useSyncConnectedChainToQueryParams'
import { isDepositMode } from '../../util/isDepositMode'

declare global {
Expand Down Expand Up @@ -71,6 +59,9 @@ const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => {
// We want to be sure this fetch is completed by the time we open the USDC modals
useCCTPIsBlocked()

useSyncConnectedChainToAnalytics()
useSyncConnectedChainToQueryParams()

const [tokenBridgeParams, setTokenBridgeParams] =
useState<TokenBridgeParams | null>(null)

Expand Down Expand Up @@ -159,18 +150,9 @@ const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => {
}

function AppContent() {
const { address, isConnected } = useAccount()
const { address } = useAccount()
const { isBlocked } = useAccountIsBlocked()
const [tosAccepted] = useLocalStorage<boolean>(TOS_LOCALSTORAGE_KEY, false)
const { openConnectModal } = useConnectModal()

useEffect(() => {
if (tosAccepted && !isConnected) {
openConnectModal?.()
}
}, [isConnected, tosAccepted, openConnectModal])

useSyncConnectedChainToAnalytics()

if (!tosAccepted) {
return (
Expand All @@ -181,23 +163,6 @@ function AppContent() {
)
}

if (!isConnected) {
return (
<>
<Header>
<HeaderConnectWalletButton />
</Header>

<div className="flex flex-col items-start gap-4 px-6 pb-8 pt-12 text-white">
<p className="text-5xl">No wallet connected</p>
<p className="text-xl">
Please connect your wallet to use the bridge.
</p>
</div>
</>
)
}

if (address && isBlocked) {
return (
<BlockedDialog
Expand All @@ -215,9 +180,7 @@ function AppContent() {

return (
<>
<Header>
<HeaderAccountPopover />
</Header>
<Header />
<TokenListSyncer />
<BalanceUpdater />
<ArbTokenBridgeStoreSyncWrapper />
Expand Down Expand Up @@ -248,97 +211,6 @@ Object.keys(localStorage).forEach(key => {
}
})

function ConnectedChainSyncer() {
const { address } = useAccount()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted into useSyncConnectedChainToQueryParams

const [shouldSync, setShouldSync] = useState(false)
const [didSync, setDidSync] = useState(false)
const { disconnect } = useDisconnect({
onSettled: onDisconnectHandler
})

const [{ sourceChain, destinationChain }, setQueryParams] =
useArbQueryParams()
const { chain } = useNetwork()

const setSourceChainToConnectedChain = useCallback(() => {
if (typeof chain === 'undefined') {
return
}

const { sourceChainId: sourceChain, destinationChainId: destinationChain } =
sanitizeQueryParams({
sourceChainId: chain.id,
destinationChainId: undefined
})

setQueryParams({ sourceChain, destinationChain })
}, [chain, setQueryParams])

useEffect(() => {
async function checkCorrectChainForSmartContractWallet() {
if (typeof chain === 'undefined') {
return
}
if (!address) {
return
}
const isSmartContractWallet = await addressIsSmartContract(
address,
chain.id
)
if (isSmartContractWallet && sourceChain !== chain.id) {
const chainName = getNetworkName(chain.id)

setSourceChainToConnectedChain()

window.alert(
`You're connected to the app with a smart contract wallet on ${chainName}. In order to properly enable transfers, the app will now reload.\n\nPlease reconnect after the reload.`
)
disconnect()
}
}

checkCorrectChainForSmartContractWallet()
}, [
address,
chain,
disconnect,
setQueryParams,
setSourceChainToConnectedChain,
sourceChain
])

useEffect(() => {
if (shouldSync) {
return
}

// Only sync connected chain to query params if the query params were not initially provided
if (
typeof sourceChain === 'undefined' &&
typeof destinationChain === 'undefined'
) {
setShouldSync(true)
}
}, [shouldSync, sourceChain, destinationChain])

useEffect(() => {
// When the chain is connected and we should sync, and we haven't synced yet, sync the connected chain to the query params
if (chain && shouldSync && !didSync) {
setSourceChainToConnectedChain()
setDidSync(true)
}
}, [
chain,
shouldSync,
didSync,
setQueryParams,
setSourceChainToConnectedChain
])

return null
}

export default function App() {
const [overmind] = useState<Overmind<typeof config>>(createOvermind(config))

Expand All @@ -350,7 +222,6 @@ export default function App() {
theme={rainbowkitTheme}
{...rainbowKitProviderProps}
>
<ConnectedChainSyncer />
<AppContextProvider>
<AppContent />
</AppContextProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useCallback } from 'react'
import { useLocalStorage } from '@uidotdev/usehooks'

import { ExternalLink } from '../common/ExternalLink'
import { errorToast } from '../common/atoms/Toast'
import { TOS_LOCALSTORAGE_KEY } from '../../constants'
import { Button } from '../common/Button'
import { captureSentryErrorWithExtraData } from '../../util/SentryUtils'

export function WelcomeDialog() {
const [, setTosAccepted] = useLocalStorage<boolean>(
TOS_LOCALSTORAGE_KEY,
false
)

const { openConnectModal } = useConnectModal()

const closeHandler = useCallback(() => {
setTosAccepted(true)

try {
openConnectModal?.()
} catch (error) {
errorToast('Failed to open up RainbowKit Connect Modal')
captureSentryErrorWithExtraData({
error,
originFunction: 'WelcomeDialog closeHandler'
})
}
}, [openConnectModal, setTosAccepted])
}, [setTosAccepted])

return (
<div className="mx-4 my-16 max-w-[380px] overflow-hidden rounded border border-gray-dark bg-gray-1 pt-3 text-white sm:mx-auto">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAccount } from 'wagmi'
import { useEffect } from 'react'
import { useAccount } from 'wagmi'
import * as Sentry from '@sentry/react'

import { useNetworks } from '../../hooks/useNetworks'
Expand All @@ -16,53 +16,57 @@ function getWalletName(connectorName: string): ProviderName {
case 'Safe':
case 'Injected':
case 'Ledger':
return connectorName

case 'WalletConnectLegacy':
case 'WalletConnect':
return 'WalletConnect'
return connectorName

default:
return 'Other'
}
}

/** given our RPC url, sanitize it before logging to Sentry, to only pass the url and not the keys */
function getBaseUrl(url: string) {
function getBaseUrl(url: string | undefined): string | null {
if (typeof url === 'undefined') {
return null
}

try {
const urlObject = new URL(url)
return `${urlObject.protocol}//${urlObject.hostname}`
} catch {
// if invalid url passed
return ''
return null
}
}

export function useSyncConnectedChainToAnalytics() {
const { isConnected, connector } = useAccount()
const [networks] = useNetworks()
const { parentChain, childChain } = useNetworksRelationship(networks)
const { isConnected, connector } = useAccount()

useEffect(() => {
if (isConnected && connector) {
const walletName = getWalletName(connector.name)
trackEvent('Connect Wallet Click', { walletName })
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's coming exactly from the previous file, but wouldn't this fire on every-refresh? Ideally we want it to fire only when we connect to UI using the connect wallet button.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isConnected and connector are not changing on every refresh, so it should be fine


// set a custom tag in sentry to filter issues by connected wallet.name
Sentry.setTag('wallet.name', connector?.name ?? '')
// set a custom tag in sentry to filter issues by connected wallet.name
Sentry.setTag('wallet.name', walletName)
}
}, [isConnected, connector])

useEffect(() => {
Sentry.setTag('network.parent_chain_id', parentChain.id)
Sentry.setTag(
'network.parent_chain_rpc_url',
getBaseUrl(rpcURLs[parentChain.id] ?? '')
)
Sentry.setTag('network.child_chain_id', childChain.id)
Sentry.setTag(
'network.child_chain_rpc_url',
getBaseUrl(rpcURLs[childChain.id] ?? '')
)

const parentChainRpcUrl = getBaseUrl(rpcURLs[parentChain.id])
const childChainRpcUrl = getBaseUrl(rpcURLs[childChain.id])

if (parentChainRpcUrl) {
Sentry.setTag('network.parent_chain_rpc_url', parentChainRpcUrl)
}

if (childChainRpcUrl) {
Sentry.setTag('network.child_chain_rpc_url', childChainRpcUrl)
}
}, [childChain.id, parentChain.id])
}
Loading
Loading