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: add support of xdefi wallet #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 26 additions & 1 deletion src/App/SelectWalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ const SelectEtherBaseWalletModal = (): ReactElement => {
}
}

const onClickXDEFIExtension = async (): Promise<void> => {
const xdefiExtInstalled =
terraService.checkInstalled() && window?.xfi.terra !== undefined

if (xdefiExtInstalled) {
const result = await terraService.connect()

await login({
user: {
address: result.address,
Copy link
Contributor

Choose a reason for hiding this comment

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

@dimitrykislichenko it doesn't work for me,
with the Prioritise XDEFI wallet option enabled i receive an error in this line:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'address')
    at onClickXDEFIExtension (index.tsx:65:1)

without the prioritise option it doesn't detect the wallet

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry I made the comment some time ago, now it detect the extension without the prioritise option.
But it is still throwing the Cannot read properties of undefined (reading 'address') error

Copy link

Choose a reason for hiding this comment

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

Manage your work-related matters with patience.
Sometimes the problem is not the program and the solution is waiting

Copy link
Contributor

Choose a reason for hiding this comment

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

What?? 🤔

walletType: WalletEnum.XDEFIExtension,
},
})
} else {
setIsVisibleModalType(SelectWalletModalType.xdefiExtInstall)
}
}

const onClickTerraWalletConnect = async (): Promise<void> => {
try {
const connector = await terraWalletConnectService.connect()
Expand Down Expand Up @@ -189,6 +207,9 @@ const SelectEtherBaseWalletModal = (): ReactElement => {
case WalletEnum.TerraExtension:
onClickTerraExtension()
break
case WalletEnum.XDEFIExtension:
onClickXDEFIExtension()
break
case WalletEnum.TerraWalletConnect:
onClickTerraWalletConnect()
break
Expand All @@ -198,7 +219,11 @@ const SelectEtherBaseWalletModal = (): ReactElement => {
}
}

let buttons = [WalletEnum.TerraExtension, WalletEnum.TerraWalletConnect]
let buttons = [
WalletEnum.TerraExtension,
WalletEnum.TerraWalletConnect,
WalletEnum.XDEFIExtension,
]
if (
fromBlockChain === BlockChainType.ethereum ||
fromBlockChain === BlockChainType.hmy
Expand Down
77 changes: 77 additions & 0 deletions src/App/XDefiExtensionDownModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { ReactElement } from 'react'
import styled from 'styled-components'
import { useRecoilState } from 'recoil'

import { NETWORK } from 'consts'

import { Text } from 'components'
import Button from 'components/Button'
import DefaultModal from 'components/Modal'
import ExtLink from 'components/ExtLink'

import SelectWalletStore, {
SelectWalletModalType,
} from 'store/SelectWalletStore'

const StyledContainer = styled.div`
padding: 0 30px 30px;
`

const XDefiExtensionDownModal = (): ReactElement => {
const handleInstalled = (): void => {
window.location.reload()
}

const [isVisibleModalType, setIsVisibleModalType] = useRecoilState(
SelectWalletStore.isVisibleModalType
)
return (
<DefaultModal
{...{
isOpen: isVisibleModalType === SelectWalletModalType.xdefiExtInstall,
close: (): void => {
setIsVisibleModalType(undefined)
},
}}
>
<StyledContainer>
{!navigator.userAgent.includes('Chrome') ? (
<div style={{ textAlign: 'center' }}>
<Text style={{ fontSize: 18 }}>
{'Bridge currently\nonly supports desktop Chrome'}
</Text>
<br />
<ExtLink href={NETWORK.CHROME}>
<Text
style={{
color: 'inherit',
fontSize: 18,
marginTop: 10,
marginBottom: 30,
}}
>
Download Chrome
</Text>
</ExtLink>
</div>
) : (
<>
<div>
<ExtLink href={NETWORK.XDEFI_EXTENSION}>
<Text style={{ color: 'inherit', fontSize: 18 }}>
Download XDEFI Wallet Extension
</Text>
</ExtLink>
<br />
<Text style={{ fontSize: 18 }}>{'to connect your wallet'}</Text>
</div>
<br />
<Button onClick={handleInstalled}>I installed it.</Button>
</>
)}
</StyledContainer>
</DefaultModal>
)
}

export default XDefiExtensionDownModal
2 changes: 2 additions & 0 deletions src/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TerraExtensionDownModal from './TerraExtensionDownModal'
import BscExtensionDownModal from './BscExtensionDownModal'
import KeplrDownModal from './KeplrDownModal'
import NotSupportNetworkModal from './NotSupportNetworkModal'
import XDefiExtensionDownModal from './XDefiExtensionDownModal'
import NetworkErrorScreen from './NetworkErrorScreen'
import UnderMaintenance from './UnderMaintenance'

Expand Down Expand Up @@ -45,6 +46,7 @@ const App = (): ReactElement => {
</StyledContainer>
<SelectWalletModal />
<TerraExtensionDownModal />
<XDefiExtensionDownModal />
<BscExtensionDownModal />
<KeplrDownModal />
<NotSupportNetworkModal />
Expand Down
2 changes: 2 additions & 0 deletions src/components/WalletLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MetamaskSvg from 'images/metamask.svg'
import WalletConnectSvg from 'images/walletconnect.svg'
import CoinbaseWalletPng from 'images/CoinbaseWallet.png'
import KeplrPng from 'images/Keplr.png'
import XDefiSvg from 'images/XDefi.svg'
import { WalletEnum } from 'types/wallet'
import FormImage from './FormImage'

Expand All @@ -24,6 +25,7 @@ const walletLogo: Record<WalletEnum, string | ComponentType<IconProps>> = {
[WalletEnum.TerraWalletConnect]: WalletConnectSvg,
[WalletEnum.CoinbaseWallet]: CoinbaseWalletPng,
[WalletEnum.Keplr]: KeplrPng,
[WalletEnum.XDEFIExtension]: XDefiSvg,
}

const WalletLogo = ({
Expand Down
4 changes: 4 additions & 0 deletions src/consts/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ const TERRA_EXTENSION =
const TERRA_EXTENSION_FIREFOX =
'https://addons.mozilla.org/en-US/firefox/addon/terra-station-wallet/'

const XDEFI_EXTENSION =
'https://chrome.google.com/webstore/detail/xdefi-wallet/hmeobnfnfcmdkdcmlblgagmfpfboieaf'

const BSC_EXTENSION =
'https://chrome.google.com/webstore/detail/binance-chain-wallet/fhbohimaelbohpjbbldcngcnapndodjp'
const KEPLR_EXTENSION =
Expand Down Expand Up @@ -257,6 +260,7 @@ export default {
TERRA_ASSETS_URL,
TERRA_EXTENSION,
TERRA_EXTENSION_FIREFOX,
XDEFI_EXTENSION,
BSC_EXTENSION,
KEPLR_EXTENSION,
CHROME,
Expand Down
3 changes: 3 additions & 0 deletions src/images/XDefi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/store/SelectWalletStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { atom } from 'recoil'
export enum SelectWalletModalType {
selectWallet,
terraExtInstall,
xdefiExtInstall,
bscInstall,
keplrInstall,
}
Expand Down
6 changes: 6 additions & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export type NominalType<T extends string> = { __type: T }

declare global {
interface Window {
xfi: any
}
}
6 changes: 6 additions & 0 deletions src/types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

export enum WalletEnum {
TerraExtension = 'TerraExtension',
XDEFIExtension = 'XDEFIExtension',
Binance = 'Binance',
MetaMask = 'MetaMask',
TerraWalletConnect = 'TerraWalletConnect',
Expand All @@ -17,6 +18,7 @@ export enum WalletEnum {

export const WalletTitle: Record<WalletEnum, string> = {
TerraExtension: 'Terra Station (Extension)',
XDEFIExtension: 'XDEFI Wallet (Extension)',
TerraWalletConnect: 'Terra Station (Mobile)',
Binance: 'Binance Chain Wallet',
MetaMask: 'MetaMask',
Expand All @@ -33,6 +35,10 @@ export const WalletSupportBrowser: Record<
isSupport: isBrowser && (isChrome || isEdgeChromium || isFirefox),
errorMessage: 'Available for desktop Chrome and Firefox.',
},
XDEFIExtension: {
isSupport: isBrowser && (isChrome || isEdgeChromium),
errorMessage: 'Available for desktop Chrome.',
},
// support all browser
TerraWalletConnect: {
isSupport: true,
Expand Down