diff --git a/web/cashtab/src/components/App.js b/web/cashtab/src/components/App.js --- a/web/cashtab/src/components/App.js +++ b/web/cashtab/src/components/App.js @@ -23,6 +23,7 @@ import './App.css'; import { WalletContext } from '@utils/context'; import { checkForTokenById } from '@utils/tokenMethods.js'; +import { isValidStoredWallet } from '@utils/cashMethods'; import WalletLabel from '@components/Common/WalletLabel.js'; import { Route, @@ -203,13 +204,17 @@ const App = () => { const ContextValue = React.useContext(WalletContext); - const { wallet, loading, tokens } = ContextValue; + const { wallet, loading } = ContextValue; const [loadingUtxosAfterSend, setLoadingUtxosAfterSend] = useState(false); - - const hasTab = checkForTokenById( - tokens, - '50d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', - ); + // If wallet is unmigrated, do not show page until it has migrated + // An invalid wallet will be validated/populated after the next API call, ETA 10s + const validWallet = isValidStoredWallet(wallet); + const hasTab = validWallet + ? checkForTokenById( + wallet.state.tokens, + '50d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', + ) + : false; const location = useLocation(); const history = useHistory(); const selectedKey = @@ -219,7 +224,7 @@ diff --git a/web/cashtab/src/components/Send/Send.js b/web/cashtab/src/components/Send/Send.js --- a/web/cashtab/src/components/Send/Send.js +++ b/web/cashtab/src/components/Send/Send.js @@ -29,6 +29,7 @@ ConvertAmount, AlertMsg, } from '@components/Common/Atoms'; +import { getWalletState } from '@utils/cashMethods'; // Note jestBCH is only used for unit tests; BCHJS must be mocked for jest const SendBCH = ({ jestBCH, passLoadingStatus }) => { @@ -38,24 +39,9 @@ // If the wallet object from ContextValue has a `state key`, then check which keys are in the wallet object // Else set it as blank const ContextValue = React.useContext(WalletContext); - const { - wallet, - fiatPrice, - slpBalancesAndUtxos, - apiError, - cashtabSettings, - } = ContextValue; - let balances; - const paramsInWalletState = wallet.state ? Object.keys(wallet.state) : []; - // If wallet.state includes balances and parsedTxHistory params, use these - // These are saved in indexedDb in the latest version of the app, hence accessible more quickly - if (paramsInWalletState.includes('balances')) { - balances = wallet.state.balances; - } else { - // If balances and parsedTxHistory are not in the wallet.state object, load them from Context - // This is how the app used to work - balances = ContextValue.balances; - } + const { wallet, fiatPrice, apiError, cashtabSettings } = ContextValue; + const walletState = getWalletState(wallet); + const { balances, slpBalancesAndUtxos } = walletState; // Get device window width // If this is less than 769, the page will open with QR scanner open diff --git a/web/cashtab/src/components/Send/SendToken.js b/web/cashtab/src/components/Send/SendToken.js --- a/web/cashtab/src/components/Send/SendToken.js +++ b/web/cashtab/src/components/Send/SendToken.js @@ -33,23 +33,15 @@ } from '@components/Common/Ticker.js'; import { Event } from '@utils/GoogleAnalytics'; import { - isValidStoredWallet, + getWalletState, convertEtokenToSimpleledger, } from '@utils/cashMethods'; const SendToken = ({ tokenId, jestBCH, passLoadingStatus }) => { - const { wallet, tokens, slpBalancesAndUtxos, apiError } = React.useContext( - WalletContext, - ); - // If this wallet has migrated to latest storage structure, get token info from there - // If not, use the tokens object (unless it's undefined, in which case use an empty array) - const liveTokenState = - isValidStoredWallet(wallet) && wallet.state.tokens - ? wallet.state.tokens - : tokens - ? tokens - : []; - const token = liveTokenState.find(token => token.tokenId === tokenId); + const { wallet, apiError } = React.useContext(WalletContext); + const walletState = getWalletState(wallet); + const { tokens, slpBalancesAndUtxos } = walletState; + const token = tokens.find(token => token.tokenId === tokenId); const [tokenStats, setTokenStats] = useState(null); const [queryStringText, setQueryStringText] = useState(null); diff --git a/web/cashtab/src/components/Send/__tests__/Send.test.js b/web/cashtab/src/components/Send/__tests__/Send.test.js --- a/web/cashtab/src/components/Send/__tests__/Send.test.js +++ b/web/cashtab/src/components/Send/__tests__/Send.test.js @@ -9,7 +9,6 @@ walletWithBalancesMock, walletWithoutBalancesMock, walletWithBalancesAndTokensWithCorrectState, - walletWithBalancesAndTokensWithEmptyState, } from '../../Wallet/__mocks__/walletAndBalancesMock'; import { BrowserRouter as Router } from 'react-router-dom'; @@ -97,20 +96,6 @@ expect(tree).toMatchSnapshot(); }); -test('Wallet with BCH balances and tokens and state field, but no params in state', () => { - useContextMock.mockReturnValue(walletWithBalancesAndTokensWithEmptyState); - const testBCH = new BCHJS(); - const component = renderer.create( - - - - - , - ); - let tree = component.toJSON(); - expect(tree).toMatchSnapshot(); -}); - test('Without wallet defined', () => { useContextMock.mockReturnValue({ wallet: {}, diff --git a/web/cashtab/src/components/Send/__tests__/SendToken.test.js b/web/cashtab/src/components/Send/__tests__/SendToken.test.js --- a/web/cashtab/src/components/Send/__tests__/SendToken.test.js +++ b/web/cashtab/src/components/Send/__tests__/SendToken.test.js @@ -7,7 +7,6 @@ import { walletWithBalancesAndTokens, walletWithBalancesAndTokensWithCorrectState, - walletWithBalancesAndTokensWithEmptyState, } from '../../Wallet/__mocks__/walletAndBalancesMock'; import { BrowserRouter as Router } from 'react-router-dom'; @@ -77,25 +76,6 @@ expect(tree).toMatchSnapshot(); }); -test('Wallet with BCH balances and tokens and state field, but no params in state', () => { - const testBCH = new BCHJS(); - useContextMock.mockReturnValue(walletWithBalancesAndTokensWithEmptyState); - const component = renderer.create( - - - - - , - ); - let tree = component.toJSON(); - expect(tree).toMatchSnapshot(); -}); - test('Without wallet defined', () => { const testBCH = new BCHJS(); useContextMock.mockReturnValue({ diff --git a/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap b/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap --- a/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap +++ b/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap @@ -3,19 +3,12 @@ exports[`Wallet with BCH balances 1`] = ` Array [
- 0.06047469 - + You currently have 0 XEC -
, -
- $ - NaN - - USD +
+ Deposit some funds to use this feature
,
@@ -350,19 +342,12 @@ exports[`Wallet with BCH balances and tokens 1`] = ` Array [
- 0.06047469 - + You currently have 0 XEC -
, -
- $ - NaN - - USD +
+ Deposit some funds to use this feature
,
@@ -1041,353 +1025,6 @@ ] `; -exports[`Wallet with BCH balances and tokens and state field, but no params in state 1`] = ` -Array [ -
- 0.06047469 - - XEC -
, -
- $ - NaN - - USD -
, -
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - -
-
-
-
- -
-
-
-
-
-
-
-
-
-
- - - - - - - -
-
- - - - - XEC - -
- - - - - -
- - max - -
-
-
-
-
- -
-
-
-
-
-
- = - - $ NaN USD -
-
- -
-
-
-
, -] -`; - exports[`Wallet without BCH balance 1`] = ` Array [
- 6.001 - - TBS -
, -
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - -
-
-
-
- -
-
-
-
-
-
-
-
-
-
- - - - - identicon of tokenId bd1acc4c986de57af8d6d2a64aecad8c30ee80f37ae9d066d758923732ddc9ba - - - - TBS - - - - - max - - - - -
-
-
-
- -
-
-
-
-
-
- -
-
-
-
, -] -`; +exports[`Wallet with BCH balances and tokens 1`] = `null`; exports[`Wallet with BCH balances and tokens and state field 1`] = ` Array [ @@ -498,253 +251,4 @@ ] `; -exports[`Wallet with BCH balances and tokens and state field, but no params in state 1`] = ` -Array [ -
- 6.001 - - TBS -
, -
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - -
-
-
-
- -
-
-
-
-
-
-
-
-
-
- - - - - identicon of tokenId bd1acc4c986de57af8d6d2a64aecad8c30ee80f37ae9d066d758923732ddc9ba - - - - TBS - - - - - max - - - - -
-
-
-
- -
-
-
-
-
-
- -
-
-
-
, -] -`; - exports[`Without wallet defined 1`] = `null`; diff --git a/web/cashtab/src/components/Tokens/Tokens.js b/web/cashtab/src/components/Tokens/Tokens.js --- a/web/cashtab/src/components/Tokens/Tokens.js +++ b/web/cashtab/src/components/Tokens/Tokens.js @@ -1,22 +1,14 @@ import React from 'react'; -import { LoadingOutlined } from '@ant-design/icons'; import { CashLoader } from '@components/Common/CustomIcons'; import { WalletContext } from '@utils/context'; -import { - isValidStoredWallet, - fromSmallestDenomination, -} from '@utils/cashMethods'; +import { fromSmallestDenomination, getWalletState } from '@utils/cashMethods'; import CreateTokenForm from '@components/Tokens/CreateTokenForm'; import { currency } from '@components/Common/Ticker.js'; import TokenList from '@components/Wallet/TokenList'; import useBCH from '@hooks/useBCH'; import { BalanceHeader } from '@components/Common/BalanceHeader'; import { BalanceHeaderFiat } from '@components/Common/BalanceHeaderFiat'; -import { - LoadingCtn, - ZeroBalanceHeader, - AlertMsg, -} from '@components/Common/Atoms'; +import { ZeroBalanceHeader, AlertMsg } from '@components/Common/Atoms'; const Tokens = ({ jestBCH }) => { /* @@ -33,24 +25,11 @@ wallet state parameters not stored in the wallet object are deprecated */ - const { - loading, - wallet, - apiError, - fiatPrice, - cashtabSettings, - } = React.useContext(WalletContext); - - // If wallet is unmigrated, do not show page until it has migrated - // An invalid wallet will be validated/populated after the next API call, ETA 10s - let validWallet = isValidStoredWallet(wallet); - - // Get wallet state variables - let balances, tokens; - if (validWallet) { - balances = wallet.state.balances; - tokens = wallet.state.tokens; - } + const { wallet, apiError, fiatPrice, cashtabSettings } = React.useContext( + WalletContext, + ); + const walletState = getWalletState(wallet); + const { balances, tokens } = walletState; const { getBCH, getRestUrl, createToken } = useBCH(); @@ -58,100 +37,79 @@ const BCH = jestBCH ? jestBCH : getBCH(); return ( <> - {loading || !validWallet ? ( - - - + {!balances.totalBalance ? ( + <> + + You need some {currency.ticker} in your wallet to create + tokens. + + + ) : ( <> - {!balances.totalBalance ? ( - <> - - You need some {currency.ticker} in your wallet - to create tokens. - - - - ) : ( - <> - - {fiatPrice !== null && - !isNaN(balances.totalBalance) && ( - - )} - - )} - {apiError && ( - <> -

- An error occurred on our end. -

Re-establishing connection... -

- - - )} - - {balances.totalBalanceInSatoshis < currency.dustSats && ( - - You need at least{' '} - {fromSmallestDenomination( - currency.dustSats, - ).toString()}{' '} - {currency.ticker} ( - {cashtabSettings - ? `${ - currency.fiatCurrencies[ - cashtabSettings.fiatCurrency - ].symbol - } ` - : '$ '} - {( - fromSmallestDenomination( - currency.dustSats, - ).toString() * fiatPrice - ).toFixed(4)}{' '} - {cashtabSettings - ? `${currency.fiatCurrencies[ - cashtabSettings.fiatCurrency - ].slug.toUpperCase()} ` - : 'USD'} - ) to create a token - + {fiatPrice !== null && !isNaN(balances.totalBalance) && ( + )} + + )} + {apiError && ( + <> +

+ An error occurred on our end. +

Re-establishing connection... +

+ + + )} + + {balances.totalBalanceInSatoshis < currency.dustSats && ( + + You need at least{' '} + {fromSmallestDenomination(currency.dustSats).toString()}{' '} + {currency.ticker} ( + {cashtabSettings + ? `${ + currency.fiatCurrencies[ + cashtabSettings.fiatCurrency + ].symbol + } ` + : '$ '} + {( + fromSmallestDenomination(currency.dustSats).toString() * + fiatPrice + ).toFixed(4)}{' '} + {cashtabSettings + ? `${currency.fiatCurrencies[ + cashtabSettings.fiatCurrency + ].slug.toUpperCase()} ` + : 'USD'} + ) to create a token + + )} - {tokens && tokens.length > 0 ? ( - <> - - - ) : ( - <>No {currency.tokenTicker} tokens in this wallet - )} + {tokens && tokens.length > 0 ? ( + <> + + ) : ( + <>No {currency.tokenTicker} tokens in this wallet )} ); diff --git a/web/cashtab/src/components/Tokens/__tests__/Tokens.test.js b/web/cashtab/src/components/Tokens/__tests__/Tokens.test.js --- a/web/cashtab/src/components/Tokens/__tests__/Tokens.test.js +++ b/web/cashtab/src/components/Tokens/__tests__/Tokens.test.js @@ -9,7 +9,6 @@ walletWithBalancesMock, walletWithoutBalancesMock, walletWithBalancesAndTokensWithCorrectState, - walletWithBalancesAndTokensWithEmptyState, } from '../../Wallet/__mocks__/walletAndBalancesMock'; import { BrowserRouter as Router } from 'react-router-dom'; @@ -97,20 +96,6 @@ expect(tree).toMatchSnapshot(); }); -test('Wallet with BCH balances and tokens and state field, but no params in state', () => { - useContextMock.mockReturnValue(walletWithBalancesAndTokensWithEmptyState); - const testBCH = new BCHJS(); - const component = renderer.create( - - - - - , - ); - let tree = component.toJSON(); - expect(tree).toMatchSnapshot(); -}); - test('Without wallet defined', () => { useContextMock.mockReturnValue({ wallet: {}, diff --git a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap --- a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap +++ b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap @@ -1,157 +1,459 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://goo.gl/fbAQLP @generated exports[`Wallet with BCH balances 1`] = ` -
- -
, +
+ 0 + + XEC +
, +
+
- - - -
+
+
+
+ + + + Create Token +
+
+
+
+
, +

+ You need at least + + 5.5 + + XEC + ( + $ + NaN + + USD + ) to create a token +

, + "No ", + "eToken", + " tokens in this wallet", +] `; exports[`Wallet with BCH balances and tokens 1`] = ` -
- -
, +
+ 0 + + XEC +
, +
+
- - - -
+
+
+
+ + + + Create Token +
+
+
+
+
, +

+ You need at least + + 5.5 + + XEC + ( + $ + NaN + + USD + ) to create a token +

, + "No ", + "eToken", + " tokens in this wallet", +] `; exports[`Wallet with BCH balances and tokens and state field 1`] = ` -
- -
, +
+ $ + NaN + + USD +
, +
+
- - - -
-`; - -exports[`Wallet with BCH balances and tokens and state field, but no params in state 1`] = ` -
- -
+
+ + + + Create Token +
+
+
+
+ , +
+ - - - -
+
+
+ identicon of tokenId bd1acc4c986de57af8d6d2a64aecad8c30ee80f37ae9d066d758923732ddc9ba +
+
+ 6.001 + + + TBS + +
+
+
+ , +] `; exports[`Wallet without BCH balance 1`] = ` -
- -
, +
+ 0 + + XEC +
, +
+
- - - -
+
+
+
+ + + + Create Token +
+
+
+
+ , +

+ You need at least + + 5.5 + + XEC + ( + $ + NaN + + USD + ) to create a token +

, + "No ", + "eToken", + " tokens in this wallet", +] `; exports[`Without wallet defined 1`] = ` -
- -
, +
+ 0 + + XEC +
, +
+
- - - -
+
+
+
+ + + + Create Token +
+
+
+
+ , +

+ You need at least + + 5.5 + + XEC + ( + $ + NaN + + USD + ) to create a token +

, + "No ", + "eToken", + " tokens in this wallet", +] `; diff --git a/web/cashtab/src/components/Wallet/Wallet.js b/web/cashtab/src/components/Wallet/Wallet.js --- a/web/cashtab/src/components/Wallet/Wallet.js +++ b/web/cashtab/src/components/Wallet/Wallet.js @@ -13,6 +13,7 @@ import { BalanceHeader } from '@components/Common/BalanceHeader'; import { BalanceHeaderFiat } from '@components/Common/BalanceHeaderFiat'; import { LoadingCtn, ZeroBalanceHeader } from '@components/Common/Atoms'; +import { getWalletState } from '@utils/cashMethods'; export const Tabs = styled.div` margin: auto; @@ -169,32 +170,9 @@ const WalletInfo = () => { const ContextValue = React.useContext(WalletContext); const { wallet, fiatPrice, apiError, cashtabSettings } = ContextValue; - let balances; - let parsedTxHistory; - let tokens; - // use parameters from wallet.state object and not legacy separate parameters, if they are in state - // handle edge case of user with old wallet who has not opened latest Cashtab version yet + const walletState = getWalletState(wallet); + const { balances, parsedTxHistory, tokens } = walletState; - // If the wallet object from ContextValue has a `state key`, then check which keys are in the wallet object - // Else set it as blank - const paramsInWalletState = wallet.state ? Object.keys(wallet.state) : []; - // If wallet.state includes balances and parsedTxHistory params, use these - // These are saved in indexedDb in the latest version of the app, hence accessible more quickly - if ( - paramsInWalletState.includes('balances') && - paramsInWalletState.includes('parsedTxHistory') && - paramsInWalletState.includes('tokens') - ) { - balances = wallet.state.balances; - parsedTxHistory = wallet.state.parsedTxHistory; - tokens = wallet.state.tokens; - } else { - // If balances and parsedTxHistory are not in the wallet.state object, load them from Context - // This is how the app used to work - balances = ContextValue.balances; - parsedTxHistory = ContextValue.parsedTxHistory; - tokens = ContextValue.tokens; - } const [address, setAddress] = React.useState('cashAddress'); const [addressPrefix, setAddressPrefix] = React.useState('eCash'); const [activeTab, setActiveTab] = React.useState('txHistory'); @@ -349,14 +327,21 @@ const Wallet = () => { const ContextValue = React.useContext(WalletContext); - const { wallet, loading } = ContextValue; + const { wallet, previousWallet, loading } = ContextValue; return ( <> {loading ? ( ) : ( - <>{wallet.Path1899 ? : } + <> + {(wallet && wallet.Path1899) || + (previousWallet && previousWallet.path1899) ? ( + + ) : ( + + )} + )} ); diff --git a/web/cashtab/src/components/Wallet/__mocks__/walletAndBalancesMock.js b/web/cashtab/src/components/Wallet/__mocks__/walletAndBalancesMock.js --- a/web/cashtab/src/components/Wallet/__mocks__/walletAndBalancesMock.js +++ b/web/cashtab/src/components/Wallet/__mocks__/walletAndBalancesMock.js @@ -269,78 +269,3 @@ ], loading: false, }; - -export const walletWithBalancesAndTokensWithEmptyState = { - wallet: { - name: 'MigrationTestAlpha', - Path245: { - cashAddress: - 'bitcoincash:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy54hkry298', - slpAddress: - 'simpleledger:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5evac32me', - fundingWif: 'KwgNkyijAaxFr5XQdnaYyNMXVSZobgHzSoKKfWiC3Q7Xr4n7iYMG', - fundingAddress: - 'simpleledger:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5evac32me', - legacyAddress: '1EgPUfBgU7ekho3EjtGze87dRADnUE8ojP', - }, - Path145: { - cashAddress: - 'bitcoincash:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9v0lgx569z', - slpAddress: - 'simpleledger:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vryrap6mu', - fundingWif: 'L2xvTe6CdNxroR6pbdpGWNjAa55AZX5Wm59W5TXMuH31ihNJdDjt', - fundingAddress: - 'simpleledger:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vryrap6mu', - legacyAddress: '1511T3ynXKgCwXhFijCUWKuTfqbPxFV1AF', - }, - Path1899: { - cashAddress: - 'bitcoincash:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7cptzgcqy6', - slpAddress: - 'simpleledger:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7cdsfndq6y', - fundingWif: 'Kx4FiBMvKK1iXjFk5QTaAK6E4mDGPjmwDZ2HDKGUZpE4gCXMaPe9', - fundingAddress: - 'simpleledger:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7cdsfndq6y', - legacyAddress: '1J1Aq5tAAYxZgSDRo8soKM2Rb41z3xrYpm', - }, - state: {}, - }, - balances: { - totalBalanceInSatoshis: 6047469, - totalBalance: 0.06047469, - }, - tokens: [ - { - info: { - height: 666987, - tx_hash: - 'e7d554c317db71fd5b50fcf0b2cb4cbdce54a09f1732cfaade0820659318e30a', - tx_pos: 2, - value: 546, - satoshis: 546, - txid: - 'e7d554c317db71fd5b50fcf0b2cb4cbdce54a09f1732cfaade0820659318e30a', - vout: 2, - utxoType: 'token', - transactionType: 'send', - tokenId: - 'bd1acc4c986de57af8d6d2a64aecad8c30ee80f37ae9d066d758923732ddc9ba', - tokenTicker: 'TBS', - tokenName: 'TestBits', - tokenDocumentUrl: 'https://thecryptoguy.com/', - tokenDocumentHash: '', - decimals: 9, - tokenType: 1, - tokenQty: '6.001', - isValid: true, - address: - 'bitcoincash:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy54hkry298', - }, - tokenId: - 'bd1acc4c986de57af8d6d2a64aecad8c30ee80f37ae9d066d758923732ddc9ba', - balance: '6.001', - hasBaton: false, - }, - ], - loading: false, -}; diff --git a/web/cashtab/src/components/Wallet/__tests__/Wallet.test.js b/web/cashtab/src/components/Wallet/__tests__/Wallet.test.js --- a/web/cashtab/src/components/Wallet/__tests__/Wallet.test.js +++ b/web/cashtab/src/components/Wallet/__tests__/Wallet.test.js @@ -8,7 +8,6 @@ walletWithBalancesMock, walletWithoutBalancesMock, walletWithBalancesAndTokensWithCorrectState, - walletWithBalancesAndTokensWithEmptyState, } from '../__mocks__/walletAndBalancesMock'; import { BrowserRouter as Router } from 'react-router-dom'; @@ -76,19 +75,6 @@ expect(tree).toMatchSnapshot(); }); -test('Wallet with BCH balances and tokens and state field, but no params in state', () => { - useContextMock.mockReturnValue(walletWithBalancesAndTokensWithEmptyState); - const component = renderer.create( - - - - - , - ); - let tree = component.toJSON(); - expect(tree).toMatchSnapshot(); -}); - test('Without wallet defined', () => { useContextMock.mockReturnValue({ wallet: {}, diff --git a/web/cashtab/src/components/Wallet/__tests__/__snapshots__/Wallet.test.js.snap b/web/cashtab/src/components/Wallet/__tests__/__snapshots__/Wallet.test.js.snap --- a/web/cashtab/src/components/Wallet/__tests__/__snapshots__/Wallet.test.js.snap +++ b/web/cashtab/src/components/Wallet/__tests__/__snapshots__/Wallet.test.js.snap @@ -3,19 +3,37 @@ exports[`Wallet with BCH balances 1`] = ` Array [
- 0.06047469 + + 🎉 + + Congratulations on your new wallet! + + + 🎉 + +
+ Start using the wallet immediately to receive + + XEC + payments, or load it up with XEC + to send to others
,
- $ - NaN + 0 - USD + XEC
,
- 0.06047469 + + 🎉 + + Congratulations on your new wallet! + + + 🎉 + +
+ Start using the wallet immediately to receive XEC -
, -
- $ - NaN + payments, or load it up with - USD -
, -
-
- Copied -
- - ecash:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7ccxkrr6zd - -
- - - - - -
- - - ecash: - - - qzagy47m - - agy47mvh6qxkvcn3acjnz73rkhkc6y7c - - cxkrr6zd - -
-
, -
-
- XEC -
-
- eToken -
+ XEC + to send to others
, -] -`; - -exports[`Wallet with BCH balances and tokens and state field 1`] = ` -Array [
- 0.06047469 + 0 XEC
, -
- $ - NaN - - USD -
,
{ + if (!wallet || !wallet.state) { + return { + balances: { totalBalance: 0, totalBalanceInSatoshis: 0 }, + hydratedUtxoDetails: {}, + tokens: [], + slpBalancesAndUtxos: {}, + parsedTxHistory: [], + utxos: [], + }; + } + + return wallet.state; +}; + export function convertToEcashPrefix(bitcoincashPrefixedAddress) { // Prefix-less addresses may be valid, but the cashaddr.decode function used below // will throw an error without a prefix. Hence, must ensure prefix to use that function.