-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #958 from crypto-com/dev
Internal Release v0.6.6
- Loading branch information
Showing
51 changed files
with
2,084 additions
and
5,250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "chain-desktop-wallet", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "Crypto.com Chain Desktop Wallet App", | ||
"repository": "github:crypto-com/chain-desktop-wallet", | ||
"author": "Crypto.org <[email protected]>", | ||
|
@@ -58,6 +58,7 @@ | |
"react-script": "2.0.5", | ||
"react-sticky-mouse-tooltip": "0.0.1", | ||
"recoil": "0.1.3", | ||
"recoil-nexus": "0.3.15", | ||
"scrypt-js": "3.0.1", | ||
"stylelint-config-css-modules": "2.2.0", | ||
"stylelint-config-prettier": "8.0.2", | ||
|
@@ -343,4 +344,4 @@ | |
"json-schema": "0.4.0", | ||
"follow-redirects": "1.14.7" | ||
} | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
src/components/LedgerNotification/LedgerNotification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import React from 'react'; | ||
import { Button, notification } from 'antd'; | ||
import { setRecoil } from 'recoil-nexus'; | ||
import i18n from '../../language/I18n'; | ||
import { LedgerConnectedApp, ledgerIsConnectedState } from '../../recoil/atom'; | ||
import { Wallet } from '../../models/Wallet'; | ||
import IconEth from '../../svg/IconEth'; | ||
import IconCro from '../../svg/IconCro'; | ||
import { createLedgerDevice, LEDGER_WALLET_TYPE } from '../../service/LedgerService'; | ||
import { UserAsset, UserAssetType } from '../../models/UserAsset'; | ||
|
||
export function ledgerNotification(wallet: Wallet, asset: UserAsset) { | ||
const { assetType } = asset; | ||
|
||
const LedgerNotificationKey = 'LedgerNotification'; | ||
const LedgerSuccessNotificationKey = 'LedgerSuccessNotification'; | ||
const LedgerErrorNotificationKey = 'LedgerErrorNotification'; | ||
|
||
const clickCheckLedger = async () => { | ||
try { | ||
const { addressIndex, config, walletType } = wallet; | ||
const addressprefix = config.network.addressPrefix; | ||
if (LEDGER_WALLET_TYPE === walletType) { | ||
const device = createLedgerDevice(); | ||
if (assetType === UserAssetType.TENDERMINT || assetType === UserAssetType.IBC) { | ||
const ledgerAddress = await device.getAddress(addressIndex, addressprefix, true); | ||
|
||
if (ledgerAddress === wallet.address) { | ||
setRecoil(ledgerIsConnectedState, LedgerConnectedApp.CRYPTO_ORG); | ||
notification.close(LedgerNotificationKey); | ||
notification.close(LedgerErrorNotificationKey); | ||
notification.success({ | ||
message: i18n.t('home.ledgerModalPopup.tendermintAsset.title1'), | ||
description: i18n.t('home.ledgerModalPopup.tendermintAsset.description1'), | ||
placement: 'topRight', | ||
duration: 2, | ||
key: LedgerSuccessNotificationKey, | ||
}); | ||
} else { | ||
notification.error({ | ||
message: i18n.t('general.ledgerNotification.error.addressMismatch.title'), | ||
description: i18n.t('general.ledgerNotification.error.addressMismatch.description'), | ||
duration: 10, | ||
key: LedgerErrorNotificationKey, | ||
}); | ||
} | ||
} | ||
if ( | ||
assetType === UserAssetType.EVM || | ||
assetType === UserAssetType.CRC_20_TOKEN || | ||
assetType === UserAssetType.ERC_20_TOKEN | ||
) { | ||
const ledgerAddress = await device.getEthAddress(addressIndex, true); | ||
|
||
if (ledgerAddress === asset.address) { | ||
setRecoil(ledgerIsConnectedState, LedgerConnectedApp.ETHEREUM); | ||
notification.close(LedgerNotificationKey); | ||
notification.close(LedgerErrorNotificationKey); | ||
notification.success({ | ||
message: i18n.t('home.ledgerModalPopup.tendermintAsset.title1'), | ||
description: i18n.t('home.ledgerModalPopup.tendermintAsset.description1'), | ||
placement: 'topRight', | ||
duration: 2, | ||
key: LedgerSuccessNotificationKey, | ||
}); | ||
} else { | ||
notification.error({ | ||
message: i18n.t('general.ledgerNotification.error.addressMismatch.title'), | ||
description: i18n.t('general.ledgerNotification.error.addressMismatch.description'), | ||
duration: 10, | ||
key: LedgerErrorNotificationKey, | ||
}); | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
notification.error({ | ||
message: i18n.t('receive.notification.ledgerConnect.message'), | ||
description: ( | ||
<> | ||
{i18n.t('receive.notification.ledgerConnect.description')} | ||
<br /> -{' '} | ||
<a | ||
href="https://crypto.org/docs/wallets/ledger_desktop_wallet.html#ledger-connection-troubleshoot" | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{i18n.t('general.errorModalPopup.ledgerTroubleshoot')} | ||
</a> | ||
</> | ||
), | ||
placement: 'topRight', | ||
duration: 10, | ||
key: LedgerErrorNotificationKey, | ||
}); | ||
setRecoil(ledgerIsConnectedState, LedgerConnectedApp.NOT_CONNECTED); | ||
} | ||
}; | ||
|
||
const checkLedgerBtn = ( | ||
<Button | ||
type="primary" | ||
size="small" | ||
className="btn-restart" | ||
onClick={() => { | ||
clickCheckLedger(); | ||
}} | ||
style={{ height: '30px', margin: '0px', lineHeight: 1.0 }} | ||
> | ||
{i18n.t('general.connect')} | ||
</Button> | ||
); | ||
|
||
switch (assetType) { | ||
case UserAssetType.EVM: | ||
case UserAssetType.CRC_20_TOKEN: | ||
case UserAssetType.ERC_20_TOKEN: | ||
notification.open({ | ||
key: LedgerNotificationKey, | ||
message: i18n.t('create.ledgerModalPopup.evmAddress.title2'), | ||
description: <div>{i18n.t('create.ledgerModalPopup.evmAddress.description2')}</div>, | ||
duration: 60, | ||
placement: 'topRight', | ||
className: 'notification-ledger', | ||
icon: ( | ||
<div className="ledger-app-icon"> | ||
<IconEth style={{ color: '#fff' }} /> | ||
</div> | ||
), | ||
btn: checkLedgerBtn, | ||
}); | ||
break; | ||
case UserAssetType.TENDERMINT: | ||
case UserAssetType.IBC: | ||
notification.open({ | ||
key: LedgerNotificationKey, | ||
message: i18n.t('create.ledgerModalPopup.tendermintAddress.title2'), | ||
description: <div>{i18n.t('create.ledgerModalPopup.tendermintAddress.description2')}</div>, | ||
duration: 60, | ||
placement: 'topRight', | ||
className: 'notification-ledger', | ||
icon: ( | ||
<div className="ledger-app-icon"> | ||
<IconCro style={{ color: '#fff' }} /> | ||
</div> | ||
), | ||
btn: checkLedgerBtn, | ||
}); | ||
break; | ||
default: | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useMemo } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { walletAllAssetsState } from '../recoil/atom'; | ||
import { getCronosAsset } from '../utils/utils'; | ||
|
||
export const useCronosAsset = () => { | ||
const allAssets = useRecoilValue(walletAllAssetsState); | ||
|
||
const cronosAsset = useMemo(() => { | ||
return getCronosAsset(allAssets); | ||
}, [allAssets]); | ||
|
||
return cronosAsset; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { UserAsset } from '../models/UserAsset'; | ||
import { sessionState } from '../recoil/atom'; | ||
import { walletService } from '../service/WalletService'; | ||
|
||
export function useDefaultWalletAsset() { | ||
const currentSession = useRecoilValue(sessionState); | ||
const [defaultAsset, setDefaultAsset] = useState<UserAsset>(); | ||
|
||
useEffect(() => { | ||
const syncAssetData = async () => { | ||
const currentWalletAsset = await walletService.retrieveDefaultWalletAsset(currentSession); | ||
setDefaultAsset(currentWalletAsset); | ||
}; | ||
|
||
syncAssetData(); | ||
}, [currentSession]); | ||
|
||
return { defaultAsset }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { UserAsset, UserAssetType } from '../models/UserAsset'; | ||
import { LedgerConnectedApp, ledgerIsConnectedState } from '../recoil/atom'; | ||
|
||
interface Props { | ||
asset: UserAsset | undefined; | ||
} | ||
|
||
export const useLedgerStatus = (props: Props) => { | ||
const { asset } = props; | ||
|
||
const ledgerConnectedApp = useRecoilValue(ledgerIsConnectedState); | ||
const [isLedgerConnected, setIsLedgerConnected] = useState<boolean>(); | ||
|
||
useEffect(() => { | ||
const checkIsLedgerConnected = () => { | ||
if (asset?.assetType === UserAssetType.TENDERMINT || asset?.assetType === UserAssetType.IBC) { | ||
setIsLedgerConnected(ledgerConnectedApp === LedgerConnectedApp.CRYPTO_ORG); | ||
} else if ( | ||
asset?.assetType === UserAssetType.EVM || | ||
asset?.assetType === UserAssetType.CRC_20_TOKEN || | ||
asset?.assetType === UserAssetType.ERC_20_TOKEN | ||
) { | ||
setIsLedgerConnected(ledgerConnectedApp === LedgerConnectedApp.ETHEREUM); | ||
} else { | ||
setIsLedgerConnected(false); | ||
} | ||
}; | ||
|
||
checkIsLedgerConnected(); | ||
}, [ledgerConnectedApp]); | ||
|
||
return { isLedgerConnected }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.