Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
/* eslint-disable react-hooks/exhaustive-deps */ | /* eslint-disable react-hooks/exhaustive-deps */ | ||||
import React, { useState, useEffect } from 'react'; | import React, { useState, useEffect } from 'react'; | ||||
import Paragraph from 'antd/lib/typography/Paragraph'; | import Paragraph from 'antd/lib/typography/Paragraph'; | ||||
import { notification } from 'antd'; | import { notification } from 'antd'; | ||||
import useAsyncTimeout from '@hooks/useAsyncTimeout'; | import useAsyncTimeout from '@hooks/useAsyncTimeout'; | ||||
import usePrevious from '@hooks/usePrevious'; | import usePrevious from '@hooks/usePrevious'; | ||||
import useBCH from '@hooks/useBCH'; | import useBCH from '@hooks/useBCH'; | ||||
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
import { fromSmallestDenomination } from '@utils/cashMethods'; | |||||
import localforage from 'localforage'; | import localforage from 'localforage'; | ||||
import { currency } from '@components/Common/Ticker'; | import { currency } from '@components/Common/Ticker'; | ||||
import _ from 'lodash'; | import _ from 'lodash'; | ||||
const useWallet = () => { | const useWallet = () => { | ||||
const [wallet, setWallet] = useState(false); | const [wallet, setWallet] = useState(false); | ||||
const [fiatPrice, setFiatPrice] = useState(null); | const [fiatPrice, setFiatPrice] = useState(null); | ||||
const [ws, setWs] = useState(null); | const [ws, setWs] = useState(null); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | const useWallet = () => { | ||||
const normalizeBalance = slpBalancesAndUtxos => { | const normalizeBalance = slpBalancesAndUtxos => { | ||||
const totalBalanceInSatoshis = slpBalancesAndUtxos.nonSlpUtxos.reduce( | const totalBalanceInSatoshis = slpBalancesAndUtxos.nonSlpUtxos.reduce( | ||||
(previousBalance, utxo) => previousBalance + utxo.value, | (previousBalance, utxo) => previousBalance + utxo.value, | ||||
0, | 0, | ||||
); | ); | ||||
return { | return { | ||||
totalBalanceInSatoshis, | totalBalanceInSatoshis, | ||||
totalBalance: BCH.BitcoinCash.toBitcoinCash(totalBalanceInSatoshis), | totalBalance: fromSmallestDenomination(totalBalanceInSatoshis), | ||||
}; | }; | ||||
}; | }; | ||||
const deriveAccount = async (BCH, { masterHDNode, path }) => { | const deriveAccount = async (BCH, { masterHDNode, path }) => { | ||||
const node = BCH.HDNode.derivePath(masterHDNode, path); | const node = BCH.HDNode.derivePath(masterHDNode, path); | ||||
const cashAddress = BCH.HDNode.toCashAddress(node); | const cashAddress = BCH.HDNode.toCashAddress(node); | ||||
const slpAddress = BCH.SLP.Address.toSLPAddress(cashAddress); | const slpAddress = BCH.SLP.Address.toSLPAddress(cashAddress); | ||||
▲ Show 20 Lines • Show All 1,135 Lines • Show Last 20 Lines |