diff --git a/web/cashtab/src/components/Airdrop/Airdrop.js b/web/cashtab/src/components/Airdrop/Airdrop.js --- a/web/cashtab/src/components/Airdrop/Airdrop.js +++ b/web/cashtab/src/components/Airdrop/Airdrop.js @@ -84,10 +84,9 @@ } `; // Note jestBCH is only used for unit tests; BCHJS must be mocked for jest -const Airdrop = ({ jestBCH, passLoadingStatus }) => { +const Airdrop = ({ passLoadingStatus }) => { const ContextValue = React.useContext(WalletContext); const { - BCH, wallet, fiatPrice, cashtabSettings, @@ -97,20 +96,10 @@ const location = useLocation(); const walletState = getWalletState(wallet); const { balances } = walletState; - - const [bchObj, setBchObj] = useState(false); const [isAirdropCalcModalVisible, setIsAirdropCalcModalVisible] = useState(false); const [airdropCalcModalProgress, setAirdropCalcModalProgress] = useState(0); // the dynamic % progress bar - useEffect(() => { - // jestBCH is only ever specified for unit tests, otherwise app will use getBCH(); - const activeBCH = jestBCH ? jestBCH : BCH; - - // set the BCH instance to state, for other functions to reference - setBchObj(activeBCH); - }, [BCH]); - useEffect(() => { if (location && location.state && location.state.airdropEtokenId) { setFormData({ @@ -265,7 +254,6 @@ try { mintEtokenAddress = await getMintAddress( chronik, - bchObj, formData.tokenId, ); } catch (err) { diff --git a/web/cashtab/src/components/Airdrop/__tests__/Airdrop.test.js b/web/cashtab/src/components/Airdrop/__tests__/Airdrop.test.js --- a/web/cashtab/src/components/Airdrop/__tests__/Airdrop.test.js +++ b/web/cashtab/src/components/Airdrop/__tests__/Airdrop.test.js @@ -3,7 +3,6 @@ import { ThemeProvider } from 'styled-components'; import { theme } from 'assets/styles/theme'; import Airdrop from 'components/Airdrop/Airdrop'; -import BCHJS from '@psf/bch-js'; import { walletWithBalancesAndTokens, walletWithBalancesMock, @@ -32,12 +31,11 @@ }); test('Wallet without BCH balance', () => { - const testBCH = new BCHJS(); const component = renderer.create( - + , @@ -47,12 +45,11 @@ }); test('Wallet with BCH balances', () => { - const testBCH = new BCHJS(); const component = renderer.create( - + , @@ -62,12 +59,11 @@ }); test('Wallet with BCH balances and tokens', () => { - const testBCH = new BCHJS(); const component = renderer.create( - + , @@ -77,14 +73,13 @@ }); test('Wallet with BCH balances and tokens and state field', () => { - const testBCH = new BCHJS(); const component = renderer.create( - + , @@ -99,12 +94,11 @@ balances: { totalBalance: 0 }, loading: false, }; - const testBCH = new BCHJS(); const component = renderer.create( - + , diff --git a/web/cashtab/src/utils/__tests__/chronik.test.js b/web/cashtab/src/utils/__tests__/chronik.test.js --- a/web/cashtab/src/utils/__tests__/chronik.test.js +++ b/web/cashtab/src/utils/__tests__/chronik.test.js @@ -784,9 +784,6 @@ const chronik = new ChronikClient( 'https://FakeChronikUrlToEnsureMocksOnly.com', ); - const BCH = new BCHJS({ - restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', - }); /* Mock the API response from chronik.tx('tokenId') called in returnGetTokenInfoChronikPromise -- for each tokenId used @@ -797,19 +794,9 @@ .calledWith(mintingTxTabCash.txid) .mockResolvedValue(mintingTxTabCash); - // This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment - BCH.Address.hash160ToCash = jest - .fn() - .mockReturnValue(mintingAddressBchFormatTabCash); - - expect(await getMintAddress(chronik, BCH, mintingTxTabCash.txid)).toBe( + expect(await getMintAddress(chronik, mintingTxTabCash.txid)).toBe( mintingAddressTabCash, ); - - // spy on mintingHash160 - expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith( - mintingHash160TabCash, - ); }); it(`getMintAddress successfully parses chronik.tx response to determine mint address for PoW token`, async () => { @@ -817,9 +804,6 @@ const chronik = new ChronikClient( 'https://FakeChronikUrlToEnsureMocksOnly.com', ); - const BCH = new BCHJS({ - restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', - }); /* Mock the API response from chronik.tx('tokenId') called in returnGetTokenInfoChronikPromise -- for each tokenId used @@ -830,17 +814,9 @@ .calledWith(mintingTxPoW.txid) .mockResolvedValue(mintingTxPoW); - // This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment - BCH.Address.hash160ToCash = jest - .fn() - .mockReturnValue(mintingAddressBchFormatPoW); - - expect(await getMintAddress(chronik, BCH, mintingTxPoW.txid)).toBe( + expect(await getMintAddress(chronik, mintingTxPoW.txid)).toBe( mintingAddressPoW, ); - - // spy on mintingHash160 - expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith(mintingHash160PoW); }); it(`getMintAddress successfully parses chronik.tx response to determine mint address for Alita token`, async () => { @@ -848,9 +824,7 @@ const chronik = new ChronikClient( 'https://FakeChronikUrlToEnsureMocksOnly.com', ); - const BCH = new BCHJS({ - restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', - }); + /* Mock the API response from chronik.tx('tokenId') called in returnGetTokenInfoChronikPromise -- for each tokenId used @@ -861,17 +835,9 @@ .calledWith(mintingTxAlita.txid) .mockResolvedValue(mintingTxAlita); - // This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment - BCH.Address.hash160ToCash = jest - .fn() - .mockReturnValue(mintingAddressBchFormatAlita); - - expect(await getMintAddress(chronik, BCH, mintingTxAlita.txid)).toBe( + expect(await getMintAddress(chronik, mintingTxAlita.txid)).toBe( mintingAddressAlita, ); - - // spy on mintingHash160 - expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith(mintingHash160Alita); }); it(`getMintAddress successfully parses chronik.tx response to determine mint address for a BUX self minted token`, async () => { @@ -879,9 +845,7 @@ const chronik = new ChronikClient( 'https://FakeChronikUrlToEnsureMocksOnly.com', ); - const BCH = new BCHJS({ - restURL: 'https://FakeBchApiUrlToEnsureMocksOnly.com', - }); + /* Mock the API response from chronik.tx('tokenId') called in returnGetTokenInfoChronikPromise -- for each tokenId used @@ -892,17 +856,7 @@ .calledWith(mintingTxBuxSelfMint.txid) .mockResolvedValue(mintingTxBuxSelfMint); - // This function needs to be mocked as bch-js functions that require Buffer types do not work in jest environment - BCH.Address.hash160ToCash = jest - .fn() - .mockReturnValue(mintingAddressBchFormatBuxSelfMint); - - expect(await getMintAddress(chronik, BCH, mintingTxBuxSelfMint.txid)).toBe( + expect(await getMintAddress(chronik, mintingTxBuxSelfMint.txid)).toBe( mintingAddressBuxSelfMint, ); - - // spy on mintingHash160 - expect(BCH.Address.hash160ToCash).toHaveBeenCalledWith( - mintingHash160BuxSelfMint, - ); }); diff --git a/web/cashtab/src/utils/chronik.js b/web/cashtab/src/utils/chronik.js --- a/web/cashtab/src/utils/chronik.js +++ b/web/cashtab/src/utils/chronik.js @@ -7,7 +7,7 @@ getHashArrayFromWallet, getUtxoWif, convertEcashtoEtokenAddr, - convertToEcashPrefix, + hash160ToAddress, } from 'utils/cashMethods'; import ecies from 'ecies-lite'; import wif from 'wif'; @@ -913,7 +913,7 @@ }; }; -export const getMintAddress = async (chronik, BCH, tokenId) => { +export const getMintAddress = async (chronik, tokenId) => { let genesisTx; let mintingHash160; try { @@ -939,15 +939,8 @@ ); } } - const mintingAdressBchFormat = - BCH.Address.hash160ToCash(mintingHash160); - const mintEcashAddressChronik = convertToEcashPrefix( - mintingAdressBchFormat, - ); - const mintEtokenAddressChronik = convertEcashtoEtokenAddr( - mintEcashAddressChronik, - ); - return mintEtokenAddressChronik; + + return convertEcashtoEtokenAddr(hash160ToAddress(mintingHash160)); } catch (err) { console.log(`Error in getMintAddress`, err); return err;