-
Notifications
You must be signed in to change notification settings - Fork 89
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
refactor(wallet): fix wallet module relations with app #3108
Changes from 1 commit
72fe4a7
7454fab
02e0522
07f4c8d
8404000
75ea3f4
6aeb42b
4064698
522a1ad
78d69b0
7cc7caf
96bd88e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,21 @@ import { getExplorerAddressLink } from 'legacy/utils/explorer' | |
import { isMobile } from 'legacy/utils/userAgent' | ||
|
||
import Activity from 'modules/account/containers/Transaction' | ||
import { ConnectionType, useDisconnectWallet, useWalletInfo, WalletDetails } from 'modules/wallet' | ||
import { Identicon } from 'modules/wallet/api/container/Identicon' | ||
import { useWalletDetails } from 'modules/wallet/api/hooks' | ||
import { useIsWalletConnect } from 'modules/wallet/web3-react/hooks/useIsWalletConnect' | ||
import { | ||
ConnectionType, | ||
useDisconnectWallet, | ||
useWalletInfo, | ||
WalletDetails, | ||
getConnectionIcon, | ||
getConnectionName, | ||
getIsCoinbaseWallet, | ||
getIsMetaMask, | ||
} from 'modules/wallet/api/utils/connection' | ||
import { getIsHardWareWallet, getWeb3ReactConnection } from 'modules/wallet/web3-react/connection' | ||
Identicon, | ||
useWalletDetails, | ||
useIsWalletConnect, | ||
getWeb3ReactConnection, | ||
getIsHardWareWallet, | ||
} from 'modules/wallet' | ||
|
||
import { UNSUPPORTED_WALLET_TEXT } from 'common/containers/WalletUnsupportedNetworkBanner' | ||
import { useIsProviderNetworkUnsupported } from 'common/hooks/useIsProviderNetworkUnsupported' | ||
|
@@ -194,9 +198,7 @@ export function AccountDetails({ | |
)} | ||
</WalletSelector> | ||
|
||
{(ENSName || account) && ( | ||
<Copy toCopy={ENSName ? ENSName : account ? account : ''} /> | ||
)} | ||
{(ENSName || account) && <Copy toCopy={ENSName ? ENSName : account ? account : ''} />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this expression sth that could be expressed simpler? would it be equivalent to: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might, will change it after this PR. I try to keep this PR as simple as possible, just imports replacements |
||
</WalletWrapper> | ||
|
||
<WalletActions> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ConnectionType } from '../../api/types' | ||
|
||
// TODO: add others | ||
export const HARDWARE_WALLETS = [ConnectionType.TREZOR] as const | ||
|
||
export type HardWareWallet = (typeof HARDWARE_WALLETS)[number] | ||
|
||
export const getIsHardWareWallet = (connectionType: ConnectionType) => | ||
HARDWARE_WALLETS.includes(connectionType as HardWareWallet) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Connector } from '@web3-react/types' | ||
|
||
import { ConnectionType } from '../../api/types' | ||
import { coinbaseWalletConnection } from '../connection/coinbase' | ||
import { fortmaticConnection } from '../connection/formatic' | ||
import { injectedConnection } from '../connection/injected' | ||
import { injectedWidgetConnection } from '../connection/injectedWidget' | ||
import { keystoneConnection } from '../connection/keystone' | ||
import { ledgerConnection } from '../connection/ledger' | ||
import { networkConnection } from '../connection/network' | ||
import { gnosisSafeConnection } from '../connection/safe' | ||
import { tallyWalletConnection } from '../connection/tally' | ||
import { trezorConnection } from '../connection/trezor' | ||
import { trustWalletConnection } from '../connection/trust' | ||
import { walletConnectConnection } from '../connection/walletConnect' | ||
import { walletConnectConnectionV2 } from '../connection/walletConnectV2' | ||
import { Web3ReactConnection } from '../types' | ||
|
||
const connectionTypeToConnection: Record<ConnectionType, Web3ReactConnection> = { | ||
[ConnectionType.INJECTED]: injectedConnection, | ||
[ConnectionType.COINBASE_WALLET]: coinbaseWalletConnection, | ||
[ConnectionType.WALLET_CONNECT]: walletConnectConnection, | ||
[ConnectionType.WALLET_CONNECT_V2]: walletConnectConnectionV2, | ||
[ConnectionType.ZENGO]: walletConnectConnection, | ||
[ConnectionType.FORTMATIC]: fortmaticConnection, | ||
[ConnectionType.NETWORK]: networkConnection, | ||
[ConnectionType.GNOSIS_SAFE]: gnosisSafeConnection, | ||
[ConnectionType.AMBIRE]: walletConnectConnection, | ||
[ConnectionType.ALPHA]: walletConnectConnection, | ||
[ConnectionType.TALLY]: tallyWalletConnection, | ||
[ConnectionType.TRUST]: trustWalletConnection, | ||
[ConnectionType.LEDGER]: ledgerConnection, | ||
[ConnectionType.KEYSTONE]: keystoneConnection, | ||
[ConnectionType.INJECTED_WIDGET]: injectedWidgetConnection, | ||
[ConnectionType.TREZOR]: trezorConnection, | ||
} | ||
const CONNECTIONS: Web3ReactConnection[] = Object.values(connectionTypeToConnection) | ||
|
||
export function getWeb3ReactConnection(c: Connector | ConnectionType): Web3ReactConnection { | ||
if (c instanceof Connector) { | ||
const connection = CONNECTIONS.find((connection) => connection.connector === c) | ||
if (!connection) { | ||
throw Error('unsupported connector') | ||
} | ||
return connection | ||
} | ||
|
||
return connectionTypeToConnection[c] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because im only starting the review, and i don't know where this is ending, my comment might get outdated soon, but one thought here is that long term we shouldn't export something Web3React related (if we can avoid it).
Ideally the module would abstract that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% agree. In this PR I only moved all imports from
modules/wallet/*
tomodules/wallet
to replace it by import from a in in the future