Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show All 11 Lines | import { | ||||
loadStoredWallet, | loadStoredWallet, | ||||
isValidStoredWallet, | isValidStoredWallet, | ||||
} from '@utils/cashMethods'; | } from '@utils/cashMethods'; | ||||
import { isValidCashtabSettings } from '@utils/validation'; | import { isValidCashtabSettings } from '@utils/validation'; | ||||
import localforage from 'localforage'; | import localforage from 'localforage'; | ||||
import { currency } from '@components/Common/Ticker'; | import { currency } from '@components/Common/Ticker'; | ||||
import isEmpty from 'lodash.isempty'; | import isEmpty from 'lodash.isempty'; | ||||
import isEqual from 'lodash.isequal'; | import isEqual from 'lodash.isequal'; | ||||
import { | import { | ||||
bytesofman: Can remove these imports now that they are handled in a separate Notifications file | |||||
CashReceivedNotificationIcon, | CashReceivedNotificationIcon, | ||||
TokenReceivedNotificationIcon, | TokenReceivedNotificationIcon, | ||||
} from '@components/Common/CustomIcons'; | } from '@components/Common/CustomIcons'; | ||||
import { transactionReceivedNotification } from './Notifications'; | |||||
const useWallet = () => { | const useWallet = () => { | ||||
const [wallet, setWallet] = useState(false); | const [wallet, setWallet] = useState(false); | ||||
const [cashtabSettings, setCashtabSettings] = useState(false); | const [cashtabSettings, setCashtabSettings] = useState(false); | ||||
const [fiatPrice, setFiatPrice] = useState(null); | const [fiatPrice, setFiatPrice] = useState(null); | ||||
const [apiError, setApiError] = useState(false); | const [apiError, setApiError] = useState(false); | ||||
const [checkFiatInterval, setCheckFiatInterval] = useState(null); | const [checkFiatInterval, setCheckFiatInterval] = useState(null); | ||||
const { | const { | ||||
▲ Show 20 Lines • Show All 863 Lines • ▼ Show 20 Lines | if ( | ||||
previousBalances && | previousBalances && | ||||
balances && | balances && | ||||
'totalBalance' in previousBalances && | 'totalBalance' in previousBalances && | ||||
'totalBalance' in balances && | 'totalBalance' in balances && | ||||
new BigNumber(balances.totalBalance) | new BigNumber(balances.totalBalance) | ||||
.minus(previousBalances.totalBalance) | .minus(previousBalances.totalBalance) | ||||
.gt(0) | .gt(0) | ||||
) { | ) { | ||||
notification.success({ | transactionReceivedNotification(); | ||||
bytesofmanUnsubmitted Not Done Inline ActionsNeed to pass in the balances, previousBalances params here bytesofman: Need to pass in the `balances, previousBalances` params here | |||||
message: 'Transaction received', | |||||
description: ( | |||||
<Paragraph> | |||||
+{' '} | |||||
{parseFloat( | |||||
Number( | |||||
balances.totalBalance - | |||||
previousBalances.totalBalance, | |||||
).toFixed(currency.cashDecimals), | |||||
).toLocaleString()}{' '} | |||||
{currency.ticker}{' '} | |||||
{cashtabSettings && | |||||
cashtabSettings.fiatCurrency && | |||||
`(${ | |||||
currency.fiatCurrencies[ | |||||
cashtabSettings.fiatCurrency | |||||
].symbol | |||||
}${( | |||||
Number( | |||||
balances.totalBalance - | |||||
previousBalances.totalBalance, | |||||
) * fiatPrice | |||||
).toFixed( | |||||
currency.cashDecimals, | |||||
)} ${cashtabSettings.fiatCurrency.toUpperCase()})`} | |||||
</Paragraph> | |||||
), | |||||
duration: 3, | |||||
icon: <CashReceivedNotificationIcon />, | |||||
style: { width: '100%' }, | |||||
}); | |||||
} | } | ||||
// Parse for incoming eToken transactions | // Parse for incoming eToken transactions | ||||
if ( | if ( | ||||
tokens && | tokens && | ||||
tokens[0] && | tokens[0] && | ||||
tokens[0].balance && | tokens[0].balance && | ||||
previousTokens && | previousTokens && | ||||
Show All 29 Lines | ) { | ||||
// Find where the newTokenId is | // Find where the newTokenId is | ||||
const receivedTokenObjectIndex = tokens.findIndex( | const receivedTokenObjectIndex = tokens.findIndex( | ||||
x => x.tokenId === newTokenId, | x => x.tokenId === newTokenId, | ||||
); | ); | ||||
//console.log(`receivedTokenObjectIndex`, receivedTokenObjectIndex); | //console.log(`receivedTokenObjectIndex`, receivedTokenObjectIndex); | ||||
// Calculate amount received | // Calculate amount received | ||||
//console.log(`receivedTokenObject:`, tokens[receivedTokenObjectIndex]); | //console.log(`receivedTokenObject:`, tokens[receivedTokenObjectIndex]); | ||||
const receivedSlpQty = tokens[ | const receivedSlpQty = | ||||
receivedTokenObjectIndex | tokens[receivedTokenObjectIndex].balance.toString(); | ||||
].balance.toString(); | |||||
const receivedSlpTicker = | const receivedSlpTicker = | ||||
tokens[receivedTokenObjectIndex].info.tokenTicker; | tokens[receivedTokenObjectIndex].info.tokenTicker; | ||||
const receivedSlpName = | const receivedSlpName = | ||||
tokens[receivedTokenObjectIndex].info.tokenName; | tokens[receivedTokenObjectIndex].info.tokenName; | ||||
//console.log(`receivedSlpQty`, receivedSlpQty); | //console.log(`receivedSlpQty`, receivedSlpQty); | ||||
// Notification if you received SLP | // Notification if you received SLP | ||||
if (receivedSlpQty > 0) { | if (receivedSlpQty > 0) { | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |
Can remove these imports now that they are handled in a separate Notifications file