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 = () => {
-
+
- {isNotActivated ? (
-
- Activate
+ {hasUnreceivedTxs &&
+
+ Receive assets
+ }
+ {isNotActivated && !hasUnreceivedTxs &&
+
+ Activate
+ }
+
+ {!isNotActivated && !hasUnreceivedTxs &&
+ <>
+
+ Send
+
+
+ Receive
+
+
+ Exchange
- ) : (
- <>
-
- Send
-
-
- Receive
-
-
- Exchange
-
- >
- )}
+ >}
)
diff --git a/src/pages/Wallet/types.ts b/src/pages/Wallet/types.ts
index 54aa7e27..b4a5940b 100644
--- a/src/pages/Wallet/types.ts
+++ b/src/pages/Wallet/types.ts
@@ -19,7 +19,7 @@ export interface IState {
balance: null | number
estimated: null | number
txHistory: TAddressTxGroup[] | null
- activeDrawer: null | 'confirm' | 'privateKey' | 'renameWallet' | 'success'
+ activeDrawer: null | 'confirm' | 'privateKey' | 'renameWallet' | 'success' | 'txsReceivedSuccess'
isBalanceRefreshing: boolean
password: string
passwordErrorLabel: null | string
@@ -28,7 +28,7 @@ export interface IState {
isHiddenWallet: boolean
warning: null | string
confirmDrawerTitle: string
- confirmDrawerType: 'showPhrase' | 'showPrivateKey' | 'activateWallet' | null
+ confirmDrawerType: 'showPhrase' | 'showPrivateKey' | 'activateWallet' | 'receivePendingTxs' | null
isDrawerButtonLoading: boolean
isNotActivated: boolean
address: string
diff --git a/src/utils/api/index.ts b/src/utils/api/index.ts
index d417573d..5063fbd6 100644
--- a/src/utils/api/index.ts
+++ b/src/utils/api/index.ts
@@ -473,8 +473,7 @@ export const getFullTxHistoryInfo = async ( wallets: TFullTxWallet[], options: T
}
)
return data?.data || []
- } catch (err) {
- console.log(err)
+ } catch {
return []
}
}
diff --git a/src/utils/backup.ts b/src/utils/backup.ts
index 3a0cdca7..7d97714f 100644
--- a/src/utils/backup.ts
+++ b/src/utils/backup.ts
@@ -2,7 +2,6 @@ import { v4 } from 'uuid'
// Utils
import { validateWallet } from '@utils/validate'
-import { setXnoTempData } from '@utils/currencies/nano'
// Types
import { IWallet } from '@utils/wallet'
@@ -79,8 +78,4 @@ export const validate = (backup: string): string | null => {
}
}
return null
-}
-
-export const setTempData = (k: string): void => {
- setXnoTempData(k)
}
\ No newline at end of file
diff --git a/src/utils/currencies/nano/index.ts b/src/utils/currencies/nano/index.ts
index 52c550a0..80fe64d9 100644
--- a/src/utils/currencies/nano/index.ts
+++ b/src/utils/currencies/nano/index.ts
@@ -2,23 +2,22 @@ import * as nano from 'nanocurrency'
// Utils
import { activateAccount, getNanoPow, sendNanoRpcRequest } from '@utils/api'
-import { getItem, setItem } from '@utils/storage'
-import { decrypt, encrypt } from '@utils/crypto'
+import { setItem } from '@utils/storage'
import { getWallets } from '@utils/wallet'
-import { toLower } from '@utils/format'
-
-// Types
-import { BlockRepresentation, ConvertParams } from 'nanocurrency'
-import { IWallet } from '@utils/wallet'
import {
TAccountInfo,
TActivateData,
- TBlockInfo, TProcessBlock,
+ TBlockInfo,
+ TProcessBlock,
TReceivableResponse,
TReceiveBlock
} from '@utils/currencies/nano/types'
+import { IWallet } from '@utils/wallet'
+// Types
+import { BlockRepresentation, ConvertParams } from 'nanocurrency'
+
export const coins: string[] = ['xno']
export const generateWallet = async (): Promise => {
@@ -87,10 +86,8 @@ export const getPubKeyFromPriv = (privateKey: string): string | null => {
}
}
-export const receiveAllPendingTxs = async (address: string): Promise => {
+export const receiveAllPendingTxs = async (address: string, privKey: string): Promise => {
try {
- const privKey = await getXnoTempData(address)
- if (!privKey) return false
let isReceived = false
const pubKey = nano.derivePublicKey(privKey)
const response = await getReceivableBlocks(address)
@@ -106,8 +103,7 @@ export const receiveAllPendingTxs = async (address: string): Promise =>
}
}
return isReceived
- } catch (err) {
- console.error(err)
+ } catch {
return false
}
@@ -284,57 +280,6 @@ export const createTransaction = async (
return hash
}
return null
- } catch (err) {
- console.error(err)
- return null
- }
-}
-
-export const setXnoTempData = (key: string) => {
- const backup = getItem('backup')
- if (backup?.length) {
- const decryptBackup = decrypt(backup, key)
- if (!decryptBackup) return
- const parseBackup = JSON.parse(decryptBackup)
- const xnoWallets: IWallet[] = parseBackup?.wallets?.filter(
- (wallet: IWallet) => toLower(wallet.symbol) === 'xno'
- )
- if (xnoWallets?.length) {
- const arr = []
- const tempData = getItem('tempData')
- const parsedData = tempData ? JSON.parse(tempData) : []
- for (const wallet of xnoWallets) {
- const { privateKey: k, address } = wallet
- if (!k) return
- const a = address
- .toLowerCase()
- .replace('xrb_', 'nano_')
- const data = encrypt(k, a)
- arr.push(data)
- }
- const newData = JSON.stringify([...parsedData, ...arr])
- setItem('tempData', newData)
- }
- }
-}
-
-export const getXnoTempData = async (address: string): Promise => {
- const tempData = getItem('tempData')
- if (!tempData) return null
- const parsedData = JSON.parse(tempData)
- for (const item of parsedData) {
- const res = await getTempItem(address, item)
- if (res) return res
- }
- return null
-}
-
-const getTempItem = async (key: string, item: string): Promise => {
- try {
- const a = key
- .toLowerCase()
- .replace('xrb_', 'nano_')
- return decrypt(item, a)
} catch {
return null
}
diff --git a/src/utils/history.ts b/src/utils/history.ts
index 172630b5..8ae29e85 100644
--- a/src/utils/history.ts
+++ b/src/utils/history.ts
@@ -88,8 +88,7 @@ export const updateTxsHistory = async (
return !!(fullTxsInfo && fullTxsInfo.length)
}
return false
- } catch (err) {
- console.error(err)
+ } catch {
return false
} finally {
setIsLoadingFlag(false)
From 352260ab79310dd5a2bbc92ab704945892ebe331 Mon Sep 17 00:00:00 2001
From: Dylan-Simplehold <92319334+Dylan-Simplehold@users.noreply.github.com>
Date: Mon, 11 Apr 2022 15:18:13 +0300
Subject: [PATCH 3/7] minor fixes
---
src/pages/Wallet/Wallet.tsx | 5 ++---
src/utils/currencies/nano/index.ts | 2 --
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/pages/Wallet/Wallet.tsx b/src/pages/Wallet/Wallet.tsx
index 6ac47076..85dae227 100644
--- a/src/pages/Wallet/Wallet.tsx
+++ b/src/pages/Wallet/Wallet.tsx
@@ -19,10 +19,8 @@ import SuccessDrawer from '@drawers/Success'
// Utils
import {
- requestBalance,
getTxsInfo,
getWarning,
- activateAccount,
getTransactionHistory
} from '@utils/api'
import {
@@ -391,7 +389,8 @@ const WalletPage: React.FC = () => {
if (symbol.toLowerCase() === 'xno') {
const res = await receiveAllPendingTxs(state.address, privateKey)
if (res) {
- getTxHistory()
+ await getTxHistory()
+ setWalletPendingStatus(false)
return updateState({
isDrawerButtonLoading: false,
activeDrawer: 'txsReceivedSuccess',
diff --git a/src/utils/currencies/nano/index.ts b/src/utils/currencies/nano/index.ts
index 80fe64d9..837ab031 100644
--- a/src/utils/currencies/nano/index.ts
+++ b/src/utils/currencies/nano/index.ts
@@ -14,7 +14,6 @@ import {
} from '@utils/currencies/nano/types'
import { IWallet } from '@utils/wallet'
-
// Types
import { BlockRepresentation, ConvertParams } from 'nanocurrency'
@@ -39,7 +38,6 @@ export const generateWallet = async (): Promise => {
}
}
-
export const formatValue = (value: string | number, type: 'from' | 'to'): string => {
return nano.convert(`${value}`, {
from: type === 'from' ? 'raw' : 'Nano',
From e7862ed8f0acbbe57ce0396c60b6cc0691a5a528 Mon Sep 17 00:00:00 2001
From: Dylan-Simplehold <92319334+Dylan-Simplehold@users.noreply.github.com>
Date: Tue, 12 Apr 2022 16:22:40 +0300
Subject: [PATCH 4/7] fixes
---
src/utils/api/index.ts | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/utils/api/index.ts b/src/utils/api/index.ts
index 5063fbd6..546cc230 100644
--- a/src/utils/api/index.ts
+++ b/src/utils/api/index.ts
@@ -622,7 +622,7 @@ export const sendNanoRpcRequest = async (input: any): Promise => {
try {
const { data }: AxiosResponse = await axios.post(
`${config.serverUrl}/wallet/nano/rpc`,
- input,
+ { input },
{
headers: {
'Content-Type': 'application/json',
@@ -635,13 +635,12 @@ export const sendNanoRpcRequest = async (input: any): Promise => {
}
}
-
export const getNanoPow = async (hash: string, type: string): Promise => {
try {
const input = { hash, type }
const { data } = await axios.post(
`${config.serverUrl}/transaction/nano/pow`,
- input,
+ { input },
{
headers: {
'Content-Type': 'application/json',
From b163575c8a2cf294a846206604fa71faa696eb4d Mon Sep 17 00:00:00 2001
From: Dylan-Simplehold <92319334+Dylan-Simplehold@users.noreply.github.com>
Date: Thu, 14 Apr 2022 16:03:04 +0300
Subject: [PATCH 5/7] routes fix
---
src/utils/api/index.ts | 4 +--
src/utils/currencies/nano/index.ts | 50 ++++++++++++++++++++++++------
src/utils/currencies/nano/types.ts | 14 +++++++++
3 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/src/utils/api/index.ts b/src/utils/api/index.ts
index 546cc230..1e603bac 100644
--- a/src/utils/api/index.ts
+++ b/src/utils/api/index.ts
@@ -621,7 +621,7 @@ export const getTokens = async (): Promise => {
export const sendNanoRpcRequest = async (input: any): Promise => {
try {
const { data }: AxiosResponse = await axios.post(
- `${config.serverUrl}/wallet/nano/rpc`,
+ `${config.serverUrl}/rpc/nano`,
{ input },
{
headers: {
@@ -639,7 +639,7 @@ export const getNanoPow = async (hash: string, type: string): Promise {
+ resolver(result)
+ })
+ await new Promise(res => setTimeout(res, 200))
+ }
+ this._inProgress = false
+ }
+}
+
+export const sendThrottledRequest = async (input: any): Promise => {
+ const request: TRpcRequest = () => sendNanoRpcRequest(input)
+ return await new Promise(async (resolver) => {
+ requestHandler.add({request, resolver})
+ })
+}
+
export const generateWallet = async (): Promise => {
try {
const seed = await nano.generateSeed()
@@ -118,7 +150,7 @@ const processBlock = async (block: BlockRepresentation, subtype: string): Promis
subtype: subtype,
block: block
}
- return await sendNanoRpcRequest(input)
+ return await sendThrottledRequest(input)
}
@@ -128,7 +160,7 @@ const getBlockInfo = async (hash: string): Promise => {
json_block: true,
hash: hash
}
- return await sendNanoRpcRequest(input)
+ return await sendThrottledRequest(input)
}
const getAccountInfo = async (address: string, representative = true): Promise => {
@@ -137,7 +169,7 @@ const getAccountInfo = async (address: string, representative = true): Promise(input)
+ return await sendThrottledRequest(input)
}
const getReceivableBlocks = async (address: string, count = undefined, threshold = undefined): Promise => {
@@ -147,7 +179,7 @@ const getReceivableBlocks = async (address: string, count = undefined, threshold
count: count,
threshold: threshold
}
- return await sendNanoRpcRequest(input)
+ return await sendThrottledRequest(input)
}
export const activateWallet = async (chain: string, pubKey: string, privKey: string): Promise => {
diff --git a/src/utils/currencies/nano/types.ts b/src/utils/currencies/nano/types.ts
index 81b26169..afeb7d5d 100644
--- a/src/utils/currencies/nano/types.ts
+++ b/src/utils/currencies/nano/types.ts
@@ -55,4 +55,18 @@ export type TReceivableResponse = {
export type TProcessBlock = {
hash: string
+}
+
+export type TRpcRequest = () => Promise
+
+export type TQueueRequest = {
+ request: TRpcRequest
+ resolver: any //
+}
+
+export type TRequestHandler = {
+ _queue: TQueueRequest[]
+ _inProgress: boolean
+ add(request: TQueueRequest): void
+ run(): void
}
\ No newline at end of file
From 045f3734c53c9e479b634f073e1cc33a6264d066 Mon Sep 17 00:00:00 2001
From: Dylan-Simplehold <92319334+Dylan-Simplehold@users.noreply.github.com>
Date: Thu, 14 Apr 2022 21:28:31 +0300
Subject: [PATCH 6/7] refactor: code
---
src/components/WalletCard/WalletCard.tsx | 4 +-
.../TransactionHistory/TransactionHistory.tsx | 4 +-
.../components/WalletCard/WalletCard.tsx | 15 +--
src/utils/currencies/nano/index.ts | 92 ++++++++++++-------
4 files changed, 70 insertions(+), 45 deletions(-)
diff --git a/src/components/WalletCard/WalletCard.tsx b/src/components/WalletCard/WalletCard.tsx
index d1a85ecc..0771432e 100644
--- a/src/components/WalletCard/WalletCard.tsx
+++ b/src/components/WalletCard/WalletCard.tsx
@@ -7,6 +7,7 @@ import CurrencyLogo from '@components/CurrencyLogo'
import Skeleton from '@components/Skeleton'
// Utils
+import { updateWalletActivationStatus } from '@utils/currencies/nano'
import { getBalance } from '@utils/currencies'
import { toUpper, numberFriendly, formatEstimated, getFormatBalance } from '@utils/format'
import {
@@ -37,7 +38,6 @@ 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 {
@@ -214,7 +214,7 @@ const WalletCard: React.FC = React.memo((props) => {
{notActivatedStatus ? (
- Need activation
+ Activation is required
) : (
diff --git a/src/pages/Wallet/components/TransactionHistory/TransactionHistory.tsx b/src/pages/Wallet/components/TransactionHistory/TransactionHistory.tsx
index 416ed56b..e75e604c 100644
--- a/src/pages/Wallet/components/TransactionHistory/TransactionHistory.tsx
+++ b/src/pages/Wallet/components/TransactionHistory/TransactionHistory.tsx
@@ -57,11 +57,11 @@ const TransactionHistory: React.FC = (props) => {
{dayjs(date).format('MMM D')}
- {data.sort(sortByDate).map((tx: TAddressTx) => {
+ {data.sort(sortByDate).map((tx: TAddressTx, index) => {
const { type, date, hash, amount, estimated, isPending, disabled } = tx
return (
= (props) => {
- {hasUnreceivedTxs &&
-
- Receive assets
- }
- {isNotActivated && !hasUnreceivedTxs &&
+
+ {isNotActivated &&
Activate
}
+ {hasUnreceivedTxs && !isNotActivated &&
+
+ Receive assets
+ }
+
{!isNotActivated && !hasUnreceivedTxs &&
<>
diff --git a/src/utils/currencies/nano/index.ts b/src/utils/currencies/nano/index.ts
index 5c8bf73d..c5ab44d3 100644
--- a/src/utils/currencies/nano/index.ts
+++ b/src/utils/currencies/nano/index.ts
@@ -19,6 +19,8 @@ import { IWallet } from '@utils/wallet'
export const coins: string[] = ['xno']
+const RPC_CALL_DELAY = 200
+
const requestHandler: TRequestHandler = {
_queue: [],
_inProgress: false,
@@ -38,7 +40,7 @@ const requestHandler: TRequestHandler = {
request().then(result => {
resolver(result)
})
- await new Promise(res => setTimeout(res, 200))
+ await new Promise(res => setTimeout(res, RPC_CALL_DELAY))
}
this._inProgress = false
}
@@ -56,10 +58,11 @@ export const generateWallet = async (): Promise => {
const seed = await nano.generateSeed()
const privateKey = nano.deriveSecretKey(seed, 0)
const publicKey = nano.derivePublicKey(privateKey)
- const address = nano.deriveAddress(publicKey).replace('xrb_', 'nano_')
+ const address = nano.deriveAddress(publicKey)
+ const formatAddress = getFormatAddress(address)
if (address) {
return {
- address,
+ address: formatAddress,
privateKey,
isNotActivated: true
}
@@ -70,6 +73,13 @@ export const generateWallet = async (): Promise => {
}
}
+const getFormatAddress = (address: string) => {
+ if (address.slice(0, 3).toLowerCase() === 'xrb') {
+ return 'nano' + address.slice(3)
+ }
+ return address
+}
+
export const formatValue = (value: string | number, type: 'from' | 'to'): string => {
return nano.convert(`${value}`, {
from: type === 'from' ? 'raw' : 'Nano',
@@ -124,9 +134,9 @@ export const receiveAllPendingTxs = async (address: string, privKey: string): Pr
if (!response) return false
- const blocks_receivable = response.blocks
+ const receivableBlocks = response.blocks
- for (const link of blocks_receivable) {
+ for (const link of receivableBlocks) {
let response = await receiveBlock({ address, pubKey, privKey, blockHash: link })
if (response && response.hash !== undefined) {
isReceived = true
@@ -147,8 +157,8 @@ const processBlock = async (block: BlockRepresentation, subtype: string): Promis
const input = {
action: 'process',
json_block: true,
- subtype: subtype,
- block: block
+ subtype,
+ block
}
return await sendThrottledRequest(input)
}
@@ -158,7 +168,7 @@ const getBlockInfo = async (hash: string): Promise => {
const input = {
action: 'block_info',
json_block: true,
- hash: hash
+ hash
}
return await sendThrottledRequest(input)
}
@@ -166,8 +176,8 @@ const getBlockInfo = async (hash: string): Promise => {
const getAccountInfo = async (address: string, representative = true): Promise => {
const input = {
action: 'account_info',
- representative: representative,
- account: address
+ account: address,
+ representative
}
return await sendThrottledRequest(input)
}
@@ -176,8 +186,8 @@ const getReceivableBlocks = async (address: string, count = undefined, threshold
const input = {
action: 'receivable',
account: address,
- count: count,
- threshold: threshold
+ count,
+ threshold
}
return await sendThrottledRequest(input)
}
@@ -190,9 +200,10 @@ export const activateWallet = async (chain: string, pubKey: string, privKey: str
if (data) {
const { hash, representative } = data
- const address = nano.deriveAddress(pubKeyFromPriv).replace('xrb_', 'nano_')
+ const address = nano.deriveAddress(pubKeyFromPriv)
+ const formatAddress = getFormatAddress(address)
const result = await receiveBlock({
- address,
+ address: formatAddress,
pubKey: pubKeyFromPriv,
privKey,
blockHash: hash,
@@ -241,34 +252,47 @@ export const updateWalletActivationStatus = async (address: string): Promise {
+const receiveBlock = async ({ address, pubKey, privKey, blockHash, walletActivation }: TReceiveBlock): Promise => {
+ try {
const link = blockHash
const blockInfo = await getBlockInfo(link)
- const account = await getAccountInfo(address)
- if (!account || !blockInfo) return
let subtype = 'receive'
- let representative = account.representative
- let previous = account.frontier
- let old_balance = account.balance
- let work_input = account.frontier
-
- if (walletActivation) {
- old_balance = '0'
- previous = '0'.padStart(64, '0')
- representative = walletActivation.representative
- work_input = pubKey
- }
- const work = await getNanoPow(work_input, subtype)
- const new_balance = stringAdd(old_balance, blockInfo.amount)
+ if (!blockInfo) return null;
+
+ let representative: string
+ let previous: string
+ let oldBalance: string
+ let workInput: string
+
+ if (walletActivation) {
+ representative = walletActivation.representative
+ workInput = pubKey
+ oldBalance = '0';
+ previous = '0'.padStart(64, '0');
+ } else {
+ const account = await getAccountInfo(address)
+ if (!account) return null;
+ representative = account.representative
+ previous = account.frontier
+ oldBalance = account.balance
+ workInput = account.frontier
+ }
+
+ const work = await getNanoPow(workInput, subtype)
+ const balance = stringAdd(oldBalance, blockInfo.amount)
const block = nano.createBlock(privKey, {
work,
previous,
representative,
- balance: new_balance,
+ balance,
link
})
return await processBlock(block.block, subtype)
+ } catch {
+ return null
+ }
+
}
export const stringSub = (n1: string, n2: string, pad = 0) => {
@@ -292,15 +316,15 @@ export const createTransaction = async (
const link = toAddress
const representative = account.representative
const previous = account.frontier
- const old_balance = account.balance
+ const oldBalance = account.balance
const workInput = account.frontier
const work = await getNanoPow(workInput, subtype)
- const new_balance = stringSub(old_balance, amount)
+ const balance = stringSub(oldBalance, amount)
const block = nano.createBlock(privateKey, {
work,
previous,
representative,
- balance: new_balance,
+ balance,
link
})
From a739748eca502af57ff5cc2cf78e8ae268d1bd74 Mon Sep 17 00:00:00 2001
From: Dylan-Simplehold <92319334+Dylan-Simplehold@users.noreply.github.com>
Date: Fri, 15 Apr 2022 19:37:10 +0300
Subject: [PATCH 7/7] version updated
---
package.json | 2 +-
src/manifest.json | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index 5d8730fd..3a149969 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "extension",
- "version": "1.21.0",
+ "version": "1.22.0",
"description": "extension",
"private": false,
"repository": "https://github.com/SimpleHold/extension.git",
diff --git a/src/manifest.json b/src/manifest.json
index ba35932c..2d090eab 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "SimpleHold",
- "version": "1.21.0",
+ "version": "1.22.0",
"icons": {
"16": "assets/logo/favicon-16.png",
"32": "assets/logo/favicon-32.png",