Skip to content

Commit

Permalink
feat: Krystal walletconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
namgold committed Sep 17, 2023
1 parent 0f929f4 commit a207b38
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 41 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@coinbase/wallet-sdk": "^3.0.4",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@kybernetwork/oauth2": "1.0.0",
"@kyberswap/krystal-walletconnect-v2": "0.0.1-rc1.0",
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "1.0.11",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
Expand Down
3 changes: 3 additions & 0 deletions src/components/AddressInputPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ const Input = styled.input<{ error?: boolean }>`
}
padding: 0px;
-webkit-appearance: textfield;
appearance: textfield;
::-webkit-search-decoration {
-webkit-appearance: none;
appearance: none;
}
::-webkit-outer-spin-button,
::-webkit-inner-spin-button {
-webkit-appearance: none;
appearance: none;
}
`

Expand Down
8 changes: 6 additions & 2 deletions src/components/Header/web3/WalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,12 @@ export default function WalletModal() {
minHeight={false}
maxHeight={90}
maxWidth={600}
bypassScrollLock={walletView === WALLET_VIEWS.PENDING && ['WALLET_CONNECT'].includes(pendingWalletKey)}
bypassFocusLock={walletView === WALLET_VIEWS.PENDING && ['WALLET_CONNECT', 'BLOCTO'].includes(pendingWalletKey)}
bypassScrollLock={
walletView === WALLET_VIEWS.PENDING && ['WALLET_CONNECT', 'KRYSTAL_WC'].includes(pendingWalletKey)
}
bypassFocusLock={
walletView === WALLET_VIEWS.PENDING && ['WALLET_CONNECT', 'KRYSTAL_WC', 'BLOCTO'].includes(pendingWalletKey)
}
>
<Wrapper>{getModalContent()}</Wrapper>
</Modal>
Expand Down
1 change: 1 addition & 0 deletions src/components/TransactionConfirmationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function AddTokenToInjectedWallet({ token, chainId }: { token: Token; chainId: C
if (!walletKey) return null
if (!isEVM) return null
if (walletKey === 'WALLET_CONNECT') return null
if (walletKey === 'KRYSTAL_WC') return null
const walletConfig = SUPPORTED_WALLETS[walletKey]

return (
Expand Down
77 changes: 44 additions & 33 deletions src/constants/connectors/evm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BloctoConnector } from '@blocto/web3-react-connector'
import { WalletConnect as KrystalWalletConnect } from '@kyberswap/krystal-walletconnect-v2'
import { ChainId } from '@kyberswap/ks-sdk-core'
import { OPTIONAL_EVENTS } from '@walletconnect/ethereum-provider'
import { CoinbaseWallet } from '@web3-react/coinbase-wallet'
Expand Down Expand Up @@ -35,43 +36,53 @@ export const [blocto, bloctoHooks] = initializeConnector<BloctoConnector>(
export const [bloctoInject, bloctoInjectHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))

const darkmode = Boolean(window.matchMedia('(prefers-color-scheme: dark)'))
const walletconnectConfig = {
options: {
projectId: WALLETCONNECT_PROJECT_ID,
chains: WALLET_CONNECT_REQUIRED_CHAIN_IDS,
optionalChains: WALLET_CONNECT_OPTIONAL_CHAIN_IDS,
showQrModal: true,
methods: ['eth_sendTransaction', 'personal_sign', 'eth_signTypedData_v4'],
optionalMethods: ['eth_signTypedData', 'eth_sign'],
// optionalMethods: OPTIONAL_METHODS,
optionalEvents: OPTIONAL_EVENTS,
rpcMap: WALLET_CONNECT_SUPPORTED_CHAIN_IDS.reduce((acc, cur) => {
acc[cur] = NETWORKS_INFO[cur].defaultRpcUrl
return acc
}, {} as { [key in ChainId]: string }),
qrModalOptions: {
chainImages: undefined,
themeMode: darkmode ? ('dark' as const) : ('light' as const),
themeVariables: {
'--w3m-z-index': '1000',
'--w3m-logo-image-url': Kyber,
'--w3m-background-image-url': WC_BG,
'--w3m-accent-color': '#31CB9E',
'--w3m-accent-fill-color': '#222222',
'--w3m-color-bg-1': '#0F0F0F',
} as any,
},
metadata: {
name: 'Kyberswap',
description: document.title,
url: window.location.origin,
icons: ['https://kyberswap.com/favicon.svg'],
},
},
}

export const [walletConnectV2, walletConnectV2Hooks] = initializeConnector<WalletConnectV2>(
actions =>
new WalletConnectV2({
actions,
defaultChainId: ChainId.MAINNET,
options: {
projectId: WALLETCONNECT_PROJECT_ID,
chains: WALLET_CONNECT_REQUIRED_CHAIN_IDS,
optionalChains: WALLET_CONNECT_OPTIONAL_CHAIN_IDS,
showQrModal: true,
methods: ['eth_sendTransaction', 'personal_sign', 'eth_signTypedData_v4'],
optionalMethods: ['eth_signTypedData', 'eth_sign'],
// optionalMethods: OPTIONAL_METHODS,
optionalEvents: OPTIONAL_EVENTS,
rpcMap: WALLET_CONNECT_SUPPORTED_CHAIN_IDS.reduce((acc, cur) => {
acc[cur] = NETWORKS_INFO[cur].defaultRpcUrl
return acc
}, {} as { [key in ChainId]: string }),
qrModalOptions: {
chainImages: undefined,
themeMode: darkmode ? 'dark' : 'light',
themeVariables: {
'--w3m-z-index': '1000',
'--w3m-logo-image-url': Kyber,
'--w3m-background-image-url': WC_BG,
'--w3m-accent-color': '#31CB9E',
'--w3m-accent-fill-color': '#222222',
'--w3m-color-bg-1': '#0F0F0F',
} as any,
},
metadata: {
name: 'Kyberswap',
description: document.title,
url: window.location.origin,
icons: ['https://kyberswap.com/favicon.svg'],
},
},
...walletconnectConfig,
}),
)
export const [krystalWalletConnectV2, krystalWalletConnectV2Hooks] = initializeConnector<KrystalWalletConnect>(
actions =>
new KrystalWalletConnect({
actions,
...walletconnectConfig,
}),
)

Expand Down
16 changes: 16 additions & 0 deletions src/constants/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
injectedHooks,
krystal,
krystalHooks,
krystalWalletConnectV2,
krystalWalletConnectV2Hooks,
metaMask,
metamaskHooks,
rabby,
Expand Down Expand Up @@ -108,6 +110,11 @@ const detectKrystal = (): WalletReadyState => {
return WalletReadyState.NotDetected
}

const detectKrystalWC = (): WalletReadyState => {
if (!getIsKrystalWallet()) return WalletReadyState.Installed
return WalletReadyState.Unsupported
}

const detectBrave = (): WalletReadyState => {
//todo known issue: fail connect on mobile solana
if (getIsBraveWallet()) return WalletReadyState.Installed
Expand Down Expand Up @@ -187,6 +194,15 @@ export const SUPPORTED_WALLETS = {
installLink: 'https://wallet.krystal.app',
readyState: detectKrystal,
} as EVMWalletInfo,
KRYSTAL_WC: {
connector: krystalWalletConnectV2,
hooks: krystalWalletConnectV2Hooks,
name: 'Krystal',
icon: KRYSTAL,
iconLight: KRYSTAL,
installLink: 'https://wallet.krystal.app',
readyState: detectKrystalWC,
} as EVMWalletInfo,
RABBY: {
connector: rabby,
hooks: rabbyHooks,
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useEffect, useMemo } from 'react'
import { useSelector } from 'react-redux'
import { useSearchParams } from 'react-router-dom'

import { blocto, gnosisSafe, metaMask, walletConnectV2 } from 'constants/connectors/evm'
import { blocto, gnosisSafe, krystalWalletConnectV2, metaMask, walletConnectV2 } from 'constants/connectors/evm'
import { MOCK_ACCOUNT_EVM, MOCK_ACCOUNT_SOLANA } from 'constants/env'
import { NETWORKS_INFO, isSupportedChainId } from 'constants/networks'
import { NetworkInfo } from 'constants/networks/type'
Expand Down Expand Up @@ -60,6 +60,9 @@ export function useActiveWeb3React(): {
if (connectedConnectorEVM === walletConnectV2) {
return 'WALLET_CONNECT'
}
if (connectedConnectorEVM === krystalWalletConnectV2) {
return 'KRYSTAL_WC'
}
if (connectedConnectorEVM === gnosisSafe) {
return 'SAFE'
}
Expand Down
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" />
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowJs": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
Expand All @@ -22,7 +22,6 @@
"jsx": "react-jsx",
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"types": ["vite/client", "vite-plugin-svgr/client"],
"typeRoots": ["./types"],
"baseUrl": "src",
"useUnknownInCatchVariables": false
Expand Down
16 changes: 13 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2236,6 +2236,16 @@
axios "1.2.1"
client-oauth2 "^4.3.3"

"@kyberswap/krystal-walletconnect-v2@0.0.1-rc1.0":
version "0.0.1-rc1.0"
resolved "https://registry.yarnpkg.com/@kyberswap/krystal-walletconnect-v2/-/krystal-walletconnect-v2-0.0.1-rc1.0.tgz#eae5e9d6ebb05471fcd0170d30a54453bbadde19"
integrity sha512-TLw2DQsCH5eLhYdCRf48W7FM3LM7+d9+/e2l5ISEDxk0V6urbeybR1BIdQpsoojZiLhUWBjQdkJkXM1P0wRQpg==
dependencies:
"@walletconnect/ethereum-provider" "2.8.1"
"@walletconnect/modal" "2.4.7"
"@web3-react/types" "8.2.0"
eventemitter3 "4.0.7"

"@kyberswap/ks-sdk-classic@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@kyberswap/ks-sdk-classic/-/ks-sdk-classic-1.0.3.tgz#8ee8e454b2838359a36aee387729d1d2e5aa9c20"
Expand Down Expand Up @@ -5368,7 +5378,7 @@
dependencies:
tslib "1.14.1"

"@walletconnect/ethereum-provider@^2.8.0":
"@walletconnect/ethereum-provider@2.8.1", "@walletconnect/ethereum-provider@^2.8.0":
version "2.8.1"
resolved "https://registry.yarnpkg.com/@walletconnect/ethereum-provider/-/ethereum-provider-2.8.1.tgz#1743072f42b5c940648b0303a382e8907a362a00"
integrity sha512-YlF8CCiFTSEZRyANIBsop/U+t+d1Z1/UXXoE9+iwjSGKJsaym6PgBLPb2d8XdmS/qR6Tcx7lVodTp4cVtezKnA==
Expand Down Expand Up @@ -5530,7 +5540,7 @@
resolved "https://registry.yarnpkg.com/@walletconnect/mobile-registry/-/mobile-registry-1.4.0.tgz#502cf8ab87330841d794819081e748ebdef7aee5"
integrity sha512-ZtKRio4uCZ1JUF7LIdecmZt7FOLnX72RPSY7aUVu7mj7CSfxDwUn6gBuK6WGtH+NZCldBqDl5DenI5fFSvkKYw==

"@walletconnect/modal@^2.4.5":
"@walletconnect/modal@2.4.7", "@walletconnect/modal@^2.4.5":
version "2.4.7"
resolved "https://registry.yarnpkg.com/@walletconnect/modal/-/modal-2.4.7.tgz#fd84d6f1ac767865d63153e32150f790739a189a"
integrity sha512-kFpvDTT44CgNGcwQVC0jHrYed4xorghKX1DOGo8ZfBSJ5TJx3p6d6SzLxkH1cZupWbljWkYS6SqvZcUBs8vWpg==
Expand Down Expand Up @@ -9612,7 +9622,7 @@ eventemitter2@6.4.7:
resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-6.4.7.tgz#a7f6c4d7abf28a14c1ef3442f21cb306a054271d"
integrity sha512-tYUSVOGeQPKt/eC1ABfhHy5Xd96N3oIijJvN3O9+TsC28T5V9yX9oEfEK5faP0EFSNVOG97qtAS68GBrQB2hDg==

eventemitter3@^4.0.0, eventemitter3@^4.0.1, eventemitter3@^4.0.4, eventemitter3@^4.0.7:
eventemitter3@4.0.7, eventemitter3@^4.0.0, eventemitter3@^4.0.1, eventemitter3@^4.0.4, eventemitter3@^4.0.7:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==
Expand Down

0 comments on commit a207b38

Please sign in to comment.