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: integrate wallets #2177

Merged
merged 66 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8611a66
feat: integrate safe + krystal
namgold Aug 15, 2023
d11240d
update detect Krystal
namgold Aug 16, 2023
18e8e7d
update
namgold Aug 16, 2023
a71630e
Merge branch 'main' into feat/integrate-wallets
namgold Aug 16, 2023
e10291c
update detect safe
namgold Aug 16, 2023
70ed1c0
Merge branch 'main' into feat/integrate-wallets
namgold Aug 17, 2023
6d8d9be
debug blocto
namgold Aug 17, 2023
6194881
update lint
namgold Aug 17, 2023
a3bd06e
detect blocto
namgold Aug 17, 2023
7935cbd
fix(kyber-AI): remove referral link ellipsis (#2175)
namgold Aug 17, 2023
61a9311
feat: walletconnect modal theme (#2176)
namgold Aug 17, 2023
38d7331
add log
namgold Aug 17, 2023
81b381a
Merge branch 'main' into feat/integrate-wallets
namgold Aug 17, 2023
e6554a2
timeout capture
namgold Aug 17, 2023
b728a85
add Phantom
namgold Aug 17, 2023
c9accbd
detect phantom
namgold Aug 18, 2023
8e08d9a
env prod
namgold Aug 18, 2023
49f4529
debug safe
namgold Aug 21, 2023
19e50cb
update debug safe & rm phantom
namgold Aug 21, 2023
c7c2016
disable whitelist domain
namgold Aug 21, 2023
d0d2ac3
detect safe
namgold Aug 21, 2023
8b8b6e1
add comment
namgold Aug 21, 2023
f9d387c
add debug
namgold Aug 21, 2023
5832d08
clean
namgold Aug 21, 2023
9daa905
gnosis chains
namgold Aug 21, 2023
d663503
lint
namgold Aug 21, 2023
b389de1
rm debug
namgold Aug 22, 2023
8c50abe
fix name
namgold Aug 22, 2023
67d5254
blocto
namgold Aug 23, 2023
f33d50a
Merge branch 'main' into feat/integrate-wallets
namgold Aug 23, 2023
f3b5f52
lint
namgold Aug 23, 2023
8ee835d
blocto injected
namgold Aug 23, 2023
37ba09c
focus lock blocto
namgold Aug 23, 2023
b02f317
detect blocto
namgold Aug 23, 2023
15cee5a
clean unused package
namgold Aug 23, 2023
e242aeb
blocto prevent change chain
namgold Aug 23, 2023
7561c8e
add cmt
namgold Aug 24, 2023
22efffd
fix blocto networks
namgold Aug 24, 2023
5bf32fc
tooltip width
namgold Aug 24, 2023
2f4212e
try fix safe
namgold Aug 24, 2023
a07d3a4
eager with safe
namgold Aug 24, 2023
3a1efa0
catch freeze
namgold Aug 24, 2023
2642a60
Merge branch 'main' into feat/integrate-wallets
namgold Aug 24, 2023
4fb297c
success callback after activate success
namgold Aug 25, 2023
a108959
Merge branch 'main' into feat/integrate-wallets
namgold Aug 25, 2023
f26fdbc
disable select network if cant change
namgold Aug 25, 2023
3ea4d9a
improve debug
namgold Aug 25, 2023
0364c0c
fix krystal change wallet
namgold Aug 25, 2023
1ec399a
add multiple prefered solutions to add new network
namgold Aug 25, 2023
a86899a
fix detect rejected
namgold Aug 25, 2023
28bed4f
fix eager connect key is overriden
namgold Aug 25, 2023
9980f16
improve reject detect
namgold Aug 25, 2023
ac66dfd
improve message
namgold Aug 26, 2023
c3c52fb
fix crash string
namgold Aug 28, 2023
cb75698
lint
namgold Aug 28, 2023
0b7bdc1
add rule rejected
namgold Aug 28, 2023
b212b64
fix rejected
namgold Aug 28, 2023
d6c6140
Merge branch 'main' into feat/integrate-wallets
namgold Aug 28, 2023
07e59cc
improve logs
namgold Aug 28, 2023
8258f72
improve logs
namgold Aug 28, 2023
921adfe
disable blocto
namgold Aug 29, 2023
c8bef78
blocto injected
namgold Aug 29, 2023
7cb7a48
revert env
namgold Aug 29, 2023
78f2809
hide injected blocto
namgold Aug 29, 2023
9a719e7
fix tried eager
namgold Aug 29, 2023
c606819
Merge branch 'main' into feat/integrate-wallets
namgold Aug 29, 2023
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
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"dependencies": {
"@0xsquid/sdk": "^1.4.1",
"@apollo/client": "^3.7.1",
"@blocto/web3-react-connector": "^1.0.0",
"@datadog/browser-rum": "^4.23.3",
"@coinbase/wallet-sdk": "^3.0.4",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@kybernetwork/oauth2": "1.0.0",
"@kyberswap/ks-sdk-classic": "^1.0.3",
Expand All @@ -69,12 +71,12 @@
"@solana/wallet-adapter-wallets": "^0.19.5",
"@solana/web3.js": "^1.66.2",
"@use-gesture/react": "^10.2.27",
"@web3-react/coinbase-wallet": "^8.2.0",
"@web3-react/core": "^8.2.0",
"@web3-react/coinbase-wallet": "8.2.0",
"@web3-react/core": "8.2.0",
"@web3-react/gnosis-safe": "8.2.0",
"@web3-react/metamask": "^8.2.1",
"@web3-react/types": "^8.2.0",
"@web3-react/types": "8.2.0",
"@web3-react/walletconnect-v2": "^8.3.3",
"@web3-react/walletlink-connector": "^6.2.14",
"aos": "^2.3.4",
"axios": "1.2.1",
"base64-js": "^1.5.1",
Expand Down Expand Up @@ -204,4 +206,4 @@
"@lingui/core": "3.14.0",
"@lingui/conf": "3.16.0"
}
}
}
18 changes: 18 additions & 0 deletions src/assets/wallets-connect/bocto.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/assets/wallets-connect/krystal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions src/assets/wallets-connect/rabby.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/assets/wallets-connect/safe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/FeeSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function FeeSelector({
(acc, cur, index) => ({ ...acc, [cur]: poolAddresses[index] }),
{} as { [key in FeeAmount]: string },
)
const tiersThatHasFarmV1 = FEE_AMOUNTS.filter((_fee, i) => {
const tiersThatHasFarmV1: FeeAmount[] = FEE_AMOUNTS.filter((_fee, i) => {
const poolAddress = poolAddresses[i].toLowerCase()
return farmingPoolAddress.includes(poolAddress)
})
Expand Down Expand Up @@ -249,7 +249,7 @@ function FeeSelector({
</Flex>

<Flex alignItems="center" sx={{ gap: '8px' }}>
{(tiersThatHasFarmV1.includes(feeAmount) ||
{(tiersThatHasFarmV1.includes(feeAmount as any) ||
activeFarmV2s?.find(item => item.poolAddress === poolByFeeAmount[feeAmount].toLowerCase())) && (
<FarmTag address={poolByFeeAmount[feeAmount]} />
)}
Expand Down
26 changes: 17 additions & 9 deletions src/components/Header/web3/NetworkModal/Networks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ const Networks = ({
customToggleModal?: () => void
disabledMsg?: string
}) => {
const { chainId: currentChainId, isWrongNetwork } = useActiveWeb3React()
const { chainId: currentChainId, isWrongNetwork, walletEVM, walletSolana } = useActiveWeb3React()
const { changeNetwork } = useChangeNetwork()
const qs = useParsedQueryString()
const navigate = useNavigate()
const isDarkMode = useIsDarkMode()
const theme = useTheme()
const { walletEVM, walletSolana } = useActiveWeb3React()
const onSelect = (chainId: ChainId) => {
customToggleModal?.()
if (customOnSelectNetwork) {
Expand Down Expand Up @@ -160,20 +159,29 @@ const Networks = ({

return (
<NetworkList mt={mt} mb={mb}>
{MAINNET_NETWORKS.map((key: ChainId, i: number) => {
const { iconDark, icon, name } = NETWORKS_INFO[key]
const disabled = !isAcceptedTerm || (activeChainIds ? !activeChainIds?.includes(key) : false)
const selected = selectedId === key && !isWrongNetwork
{MAINNET_NETWORKS.map((itemChainId: ChainId, i: number) => {
const { iconDark, icon, name } = NETWORKS_INFO[itemChainId]
const disabled = !isAcceptedTerm || (activeChainIds ? !activeChainIds?.includes(itemChainId) : false)
const selected = selectedId === itemChainId && !isWrongNetwork

const imgSrc = (isDarkMode ? iconDark : icon) || icon
const walletKey =
key === ChainId.SOLANA ? walletSolana.walletKey : walletEVM.chainId === key ? walletEVM.walletKey : null
itemChainId === ChainId.SOLANA
? walletSolana.walletKey
: walletEVM.chainId === itemChainId
? walletEVM.walletKey
: null
return (
<MouseoverTooltip style={{ zIndex: Z_INDEXS.MODAL + 1 }} key={key} text={disabled ? disabledMsg : ''}>
<MouseoverTooltip
style={{ zIndex: Z_INDEXS.MODAL + 1 }}
key={itemChainId}
text={disabled ? disabledMsg : ''}
width="fit-content"
>
<SelectNetworkButton
key={i}
padding="0"
onClick={() => !selected && onSelect(key)}
onClick={() => !selected && onSelect(itemChainId)}
data-testid="network-button"
disabled={disabled}
>
Expand Down
11 changes: 9 additions & 2 deletions src/components/Header/web3/SelectNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ReactComponent as DropdownSvg } from 'assets/svg/down.svg'
import Card from 'components/Card'
import NetworkModal from 'components/Header/web3/NetworkModal'
import Row from 'components/Row'
import { MouseoverTooltip } from 'components/Tooltip'
import { TutorialIds } from 'components/Tutorial/TutorialSwap/constant'
import { NativeCurrencies } from 'constants/tokens'
import { useActiveWeb3React } from 'hooks'
Expand Down Expand Up @@ -82,10 +83,11 @@ function SelectNetwork(): JSX.Element | null {
return `${balanceFixed} ${NativeCurrencies[chainId].symbol}`
}, [userEthBalance, chainId, networkInfo])
const walletSupportsChain = useWalletSupportedChains()
const disableSelectNetwork = walletSupportsChain.length <= 1

return (
const button = (
<NetworkCard
onClick={() => toggleNetworkModal()}
onClick={() => (disableSelectNetwork ? null : toggleNetworkModal())}
role="button"
id={TutorialIds.SELECT_NETWORK}
data-testid="select-network"
Expand All @@ -108,6 +110,11 @@ function SelectNetwork(): JSX.Element | null {
/>
</NetworkCard>
)
if (disableSelectNetwork)
return (
<MouseoverTooltip text={t`Unable to switch network. Please try it on your wallet`}>{button}</MouseoverTooltip>
)
return button
}

export default SelectNetwork
4 changes: 2 additions & 2 deletions src/components/Header/web3/WalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ export default function WalletModal() {
minHeight={false}
maxHeight={90}
maxWidth={600}
bypassScrollLock={walletView === WALLET_VIEWS.PENDING && pendingWalletKey === 'WALLET_CONNECT'}
bypassFocusLock={walletView === WALLET_VIEWS.PENDING && pendingWalletKey === 'WALLET_CONNECT'}
bypassScrollLock={walletView === WALLET_VIEWS.PENDING && ['WALLET_CONNECT'].includes(pendingWalletKey)}
bypassFocusLock={walletView === WALLET_VIEWS.PENDING && ['WALLET_CONNECT', 'BLOCTO'].includes(pendingWalletKey)}
>
<Wrapper>{getModalContent()}</Wrapper>
</Modal>
Expand Down
8 changes: 3 additions & 5 deletions src/components/SwapForm/SlippageSettingGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ export default function SlippageSettingGroup({
chainId === ChainId.MAINNET && walletEVM.isConnected ? (
<PriceAlertButton onClick={addMevProtectionHandler}>
<Shield size={14} color={theme.subText} />
{upToXXSmall ? null : (
<Text color={theme.subText} style={{ whiteSpace: 'nowrap' }}>
<Trans>Add MEV Protection</Trans>
</Text>
)}
<Text color={theme.subText} style={{ whiteSpace: 'nowrap' }}>
{upToXXSmall ? <Trans>MEV Protection</Trans> : <Trans>Add MEV Protection</Trans>}
</Text>
</PriceAlertButton>
) : null

Expand Down
6 changes: 3 additions & 3 deletions src/components/SwapForm/SwapActionButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ const SwapActionButton: React.FC<Props> = ({
const toggleApprovalModal = useToggleModal(ApplicationModal.SWAP_APPROVAL)

const handleApproveClick = () => {
if (walletKey && ['METAMASK', 'TRUST_WALLET'].includes(walletKey?.toString())) {
approveCallback()
} else {
if (['COIN98', 'BRAVE', 'COINBASE'].includes(walletKey)) {
namgold marked this conversation as resolved.
Show resolved Hide resolved
toggleApprovalModal()
} else {
approveCallback()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/TransactionConfirmationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export function TransactionErrorContent({
confirmText?: string
}) {
const theme = useTheme()
const [showDetail, setShowDetail] = useState<boolean>(true)
const [showDetail, setShowDetail] = useState<boolean>(false)
namgold marked this conversation as resolved.
Show resolved Hide resolved

return (
<Wrapper>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Web3ReactManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export default function Web3ReactManager({ children }: { children: JSX.Element }
const triedEager = useEagerConnect()

// when there's no account connected, react to logins (broadly speaking) on the injected provider, if it exists
useInactiveListener(!triedEager)
useInactiveListener(!triedEager.current)
const dispatch = useDispatch()
/** On user change network from wallet, update chainId in store, only work on EVM wallet */
useEffect(() => {
if (triedEager && chainIdEVM && chainIdState !== chainIdEVM && active && isEVM) {
if (triedEager.current && chainIdEVM && chainIdState !== chainIdEVM && active && isEVM) {
viet-nv marked this conversation as resolved.
Show resolved Hide resolved
dispatch(updateChainId(chainIdEVM))
}
// Only run on change network from wallet
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [chainIdEVM, triedEager, active])
}, [chainIdEVM, triedEager.current, active])

// on page load, do nothing until we've tried to connect to the injected connector
if (isEVM && !triedEager) {
if (isEVM && !triedEager.current) {
return <LocalLoader />
}

Expand Down
17 changes: 15 additions & 2 deletions src/constants/connectors/evm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { BloctoConnector } from '@blocto/web3-react-connector'
import { ChainId } from '@kyberswap/ks-sdk-core'
import { OPTIONAL_EVENTS } from '@walletconnect/ethereum-provider'
import { CoinbaseWallet } from '@web3-react/coinbase-wallet'
import { initializeConnector } from '@web3-react/core'
import { GnosisSafe } from '@web3-react/gnosis-safe'
import { MetaMask } from '@web3-react/metamask'
import { WalletConnect as WalletConnectV2 } from '@web3-react/walletconnect-v2'

Expand All @@ -16,10 +18,21 @@ import {
} from 'constants/networks'

export const [injected, injectedHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [rabby, rabbyHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [krystal, krystalHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [metaMask, metamaskHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [gnosisSafe, gnosisSafeHooks] = initializeConnector<GnosisSafe>(actions => new GnosisSafe({ actions }))
export const [coin98, coin98Hooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [brave, braveHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [trustWallet, trustWalletHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [trust, trustHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [blocto, bloctoHooks] = initializeConnector<BloctoConnector>(
actions =>
new BloctoConnector({
actions,
options: { chainId: ChainId.MATIC, rpc: NETWORKS_INFO[ChainId.MATIC].defaultRpcUrl },
}),
)
export const [bloctoInject, bloctoInjectHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))

const darkmode = Boolean(window.matchMedia('(prefers-color-scheme: dark)'))
export const [walletConnectV2, walletConnectV2Hooks] = initializeConnector<WalletConnectV2>(
Expand Down Expand Up @@ -50,7 +63,7 @@ export const [walletConnectV2, walletConnectV2Hooks] = initializeConnector<Walle
'--w3m-accent-color': '#31CB9E',
'--w3m-accent-fill-color': '#222222',
'--w3m-color-bg-1': '#0F0F0F',
},
} as any,
},
metadata: {
name: 'Kyberswap',
Expand Down
Loading
Loading