From a92167c4792f46f2664c88e8820d905a51987f58 Mon Sep 17 00:00:00 2001 From: Dylan-Simplehold <92319334+Dylan-Simplehold@users.noreply.github.com> Date: Fri, 8 Apr 2022 17:25:25 +0300 Subject: [PATCH 1/7] xno/nano support --- package.json | 1 + src/assets/currencies/xno.svg | 4 + .../CurrencyAddress/CurrencyAddress.tsx | 4 +- src/components/CurrencyLogo/CurrencyLogo.tsx | 8 +- src/components/WalletCard/WalletCard.tsx | 31 +- src/config/currencies.ts | 10 + .../Wallets/components/Wallet/Wallet.tsx | 3 +- .../RestoreBackup/RestoreBackup.tsx | 33 +- src/externalPages/Send/Send.tsx | 4 +- .../ImportPrivateKey/ImportPrivateKey.tsx | 6 +- src/pages/NewWallet/NewWallet.tsx | 10 +- src/pages/Send/Send.tsx | 4 +- .../SendConfirmation/SendConfirmation.tsx | 7 +- src/pages/Wallet/Wallet.tsx | 39 +- src/utils/api/index.ts | 43 ++- src/utils/backup.ts | 10 +- src/utils/currencies/hedera/index.ts | 8 +- src/utils/currencies/index.ts | 50 ++- src/utils/currencies/nano/index.ts | 341 ++++++++++++++++++ src/utils/currencies/nano/types.ts | 58 +++ src/utils/currencies/types.ts | 2 +- src/utils/currencies/vechain/index.ts | 4 +- src/utils/format.ts | 2 +- src/utils/history.ts | 40 +- src/utils/txs.ts | 22 +- yarn.lock | 8 + 26 files changed, 673 insertions(+), 79 deletions(-) create mode 100644 src/assets/currencies/xno.svg create mode 100644 src/utils/currencies/nano/index.ts create mode 100644 src/utils/currencies/nano/types.ts diff --git a/package.json b/package.json index 4ea16de6..5d8730fd 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "detect-browser": "^5.2.0", "digibyte-lib": "https://github.com/DigiByte-Core/digibyte-lib", "lodash": "^4.17.21", + "nanocurrency": "^2.5.0", "neblio-lib": "https://github.com/NeblioTeam/bitcore-lib#neblcore-lib", "nerve-sdk-js": "^1.0.8", "nuls-sdk-js": "^2.5.0", diff --git a/src/assets/currencies/xno.svg b/src/assets/currencies/xno.svg new file mode 100644 index 00000000..9c7a0d6a --- /dev/null +++ b/src/assets/currencies/xno.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/components/CurrencyAddress/CurrencyAddress.tsx b/src/components/CurrencyAddress/CurrencyAddress.tsx index d8ddb5ef..04d5976a 100644 --- a/src/components/CurrencyAddress/CurrencyAddress.tsx +++ b/src/components/CurrencyAddress/CurrencyAddress.tsx @@ -7,7 +7,7 @@ import CheckBox from '@components/CheckBox' // Utils import { short, toUpper } from '@utils/format' -import { getBalance } from '@utils/api' +import { getBalance } from '@utils/currencies' import { getCurrency } from '@config/currencies' // Styles @@ -33,7 +33,7 @@ const CurrencyAddress: React.FC = (props) => { const currency = getCurrency(symbol) const onGetBalance = async (): Promise => { - const request = await getBalance(address, currency?.chain) + const request = await getBalance(symbol, address, currency?.chain) setBalance(request.balance) } diff --git a/src/components/CurrencyLogo/CurrencyLogo.tsx b/src/components/CurrencyLogo/CurrencyLogo.tsx index 806cd0e9..70752a18 100644 --- a/src/components/CurrencyLogo/CurrencyLogo.tsx +++ b/src/components/CurrencyLogo/CurrencyLogo.tsx @@ -25,7 +25,7 @@ const CurrencyLogo: React.FC = (props) => { const [logo, setLogo] = React.useState(null) - const getChainogo = chain ? getCurrencyByChain(chain) : null + const getChainLogo = chain ? getCurrencyByChain(chain) : null const currency = chain ? getToken(symbol, chain) : getCurrency(symbol) React.useEffect(() => { @@ -47,7 +47,7 @@ const CurrencyLogo: React.FC = (props) => { {currency || logo ? ( @@ -57,9 +57,9 @@ const CurrencyLogo: React.FC = (props) => { {toUpper(name[0])} ) : null} - {getChainogo ? ( + {getChainLogo ? ( - + ) : null} diff --git a/src/components/WalletCard/WalletCard.tsx b/src/components/WalletCard/WalletCard.tsx index f47b4eb4..d1a8d444 100644 --- a/src/components/WalletCard/WalletCard.tsx +++ b/src/components/WalletCard/WalletCard.tsx @@ -7,7 +7,7 @@ import CurrencyLogo from '@components/CurrencyLogo' import Skeleton from '@components/Skeleton' // Utils -import { getBalance } from '@utils/api' +import { getBalance } from '@utils/currencies' import { toUpper, numberFriendly, formatEstimated, getFormatBalance } from '@utils/format' import { updateBalance, @@ -37,6 +37,7 @@ import Styles from './styles' import { TWalletAmountData } from '@pages/Wallets/types' import { TTxWallet } from '@utils/api/types' import { THardware } from '@utils/wallet' +import { receiveAllPendingTxs, updateWalletActivationStatus } from 'utils/currencies/nano' interface Props { @@ -94,6 +95,7 @@ const WalletCard: React.FC = React.memo((props) => { const [balance, setBalance] = React.useState(null) const [estimated, setEstimated] = React.useState(null) const [pendingBalance, setPendingBalance] = React.useState(0) + const [notActivatedStatus, setActivationStatus] = React.useState(!!isNotActivated) const walletData: TTxWallet = { chain: getWalletChain(symbol, chain), @@ -104,23 +106,34 @@ const WalletCard: React.FC = React.memo((props) => { } React.useEffect(() => { + checkActivatedStatus() loadBalance() }, []) + const checkActivatedStatus = () => { + if (symbol === 'xno') { + updateWalletActivationStatus(address).then(res => { + if (res) { + setActivationStatus(true) + } + }) + } + } + const loadBalance = async (): Promise => { const savedData = getLatestBalance(address, chain, symbol) const isFetchReady = checkIfTimePassed(savedData.lastBalanceCheck || 0, { seconds: 20 }) const isFullData = !Object.entries(savedData).find(v => v[1] === null) - let data = isNotActivated ? emptyData : savedData + let data = notActivatedStatus ? emptyData : savedData - const isFetchRequired = !isNotActivated && (isFetchReady || !isFullData) + const isFetchRequired = !notActivatedStatus && (isFetchReady || !isFullData) if (isFetchRequired) { updateLast('lastBalanceCheck', address, chain) - const fetchedData = await getBalance(address, currency?.chain || chain, tokenSymbol, contractAddress) + const fetchedData = await getBalance(symbol, address, currency?.chain || chain, tokenSymbol, contractAddress) data = { ...data, ...fetchedData } } @@ -148,6 +161,10 @@ const WalletCard: React.FC = React.memo((props) => { } }) + if (symbol === 'xno') { + await receiveAllPendingTxs(address) + } + await updateTxsHistory({ updateSingleWallet: walletData }) updateBalance({ address, symbol, balance, balance_btc, pending: pending, balance_usd, pending_btc: pending_btc }) updateLast('lastActive', address, chain) @@ -185,7 +202,7 @@ const WalletCard: React.FC = React.memo((props) => { - + {hardware ? ( @@ -199,7 +216,7 @@ const WalletCard: React.FC = React.memo((props) => { ) : null} {walletName} - {isNotActivated ? ( + {notActivatedStatus ? ( Need activation @@ -209,7 +226,7 @@ const WalletCard: React.FC = React.memo((props) => { )} - {!isNotActivated ? ( + {!notActivatedStatus ? ( diff --git a/src/config/currencies.ts b/src/config/currencies.ts index 30d62c06..4a164d27 100644 --- a/src/config/currencies.ts +++ b/src/config/currencies.ts @@ -30,6 +30,7 @@ import toncoinLogo from '@assets/currencies/toncoin.svg' import ravencoinLogo from '@assets/currencies/rvn.svg' import digibyteLogo from '@assets/currencies/dgb.svg' import ftmLogo from '@assets/currencies/ftm.svg' +import xnoLogo from '@assets/currencies/xno.svg' // Utils import { toLower } from '@utils/format' @@ -314,6 +315,15 @@ const currencies: ICurrency[] = [ chain: 'ftm', minSendAmount: 1000, isCustomFee: true, + }, + { + name: 'Nano', + symbol: 'xno', + logo: xnoLogo, + background: '#209CE9', + chain: 'xno', + minSendAmount: 1000000000000000, + isCustomFee: false, } ] diff --git a/src/drawers/Wallets/components/Wallet/Wallet.tsx b/src/drawers/Wallets/components/Wallet/Wallet.tsx index fbacb8ff..bfff1fff 100644 --- a/src/drawers/Wallets/components/Wallet/Wallet.tsx +++ b/src/drawers/Wallets/components/Wallet/Wallet.tsx @@ -7,7 +7,7 @@ import CurrencyLogo from '@components/CurrencyLogo' import Skeleton from '@components/Skeleton' // Utils -import { getBalance } from '@utils/api' +import { getBalance } from '@utils/currencies' import { toUpper, numberFriendly, short, formatEstimated } from '@utils/format' import { updateBalance, THardware } from '@utils/wallet' @@ -58,6 +58,7 @@ const Wallet: React.FC = (props) => { const fetchBalance = async (): Promise => { const { balance, balance_usd, balance_btc, pending } = await getBalance( + symbol, address, currency?.chain || chain, chain ? symbol : undefined, diff --git a/src/externalPages/RestoreBackup/RestoreBackup.tsx b/src/externalPages/RestoreBackup/RestoreBackup.tsx index 1a6c50ed..52d5e24d 100644 --- a/src/externalPages/RestoreBackup/RestoreBackup.tsx +++ b/src/externalPages/RestoreBackup/RestoreBackup.tsx @@ -21,7 +21,7 @@ import SuccessDrawer from '@drawers/Success' import { logEvent } from '@utils/amplitude' import { validatePassword } from '@utils/validate' import { decrypt } from '@utils/crypto' -import { validate as validateBackup } from '@utils/backup' +import { setTempData, validate as validateBackup } from '@utils/backup' import { setBadgeBackgroundColor, setBadgeText } from '@utils/extension' import { getItem, setItem, removeItem } from '@utils/storage' @@ -47,7 +47,7 @@ const initialState: IState = { activeDrawer: null, password: '', passwordErrorLabel: null, - isPageActive: false, + isPageActive: false } const RestoreBackup: React.FC = () => { @@ -77,7 +77,7 @@ const RestoreBackup: React.FC = () => { const onConfirm = (): void => { logEvent({ - name: START_RESTORE_CONFIRM, + name: START_RESTORE_CONFIRM }) updateState({ activeDrawer: 'confirm' }) @@ -85,7 +85,7 @@ const RestoreBackup: React.FC = () => { const onConfirmRestore = (): void => { logEvent({ - name: START_RESTORE_PASSWORD, + name: START_RESTORE_PASSWORD }) if (state.passwordErrorLabel) { @@ -108,6 +108,7 @@ const RestoreBackup: React.FC = () => { setItem('backup', state.backupData) setItem('wallets', getWalletsList) removeItem('manualRestoreBackup') + setTempData(state.password) setBadgeBackgroundColor('#EB5757') setBadgeText('1') @@ -137,7 +138,7 @@ const RestoreBackup: React.FC = () => { } return ( - + <> Restore @@ -151,9 +152,9 @@ const RestoreBackup: React.FC = () => { -