Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14362731
D15498.id45438.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
18 KB
Subscribers
None
D15498.id45438.diff
View Options
diff --git a/cashtab/package-lock.json b/cashtab/package-lock.json
--- a/cashtab/package-lock.json
+++ b/cashtab/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "cashtab",
- "version": "1.1.30",
+ "version": "1.1.31",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cashtab",
- "version": "1.1.30",
+ "version": "1.1.31",
"dependencies": {
"@ant-design/icons": "^5.3.0",
"@bitgo/utxo-lib": "^9.33.0",
diff --git a/cashtab/package.json b/cashtab/package.json
--- a/cashtab/package.json
+++ b/cashtab/package.json
@@ -1,6 +1,6 @@
{
"name": "cashtab",
- "version": "1.1.30",
+ "version": "1.1.31",
"private": true,
"scripts": {
"start": "node scripts/start.js",
diff --git a/cashtab/src/components/Home/Tx.js b/cashtab/src/components/Home/Tx.js
--- a/cashtab/src/components/Home/Tx.js
+++ b/cashtab/src/components/Home/Tx.js
@@ -421,7 +421,6 @@
data,
fiatPrice,
fiatCurrency,
- addressesInContactList,
contactList,
cashtabSettings,
cashtabCache,
@@ -453,6 +452,11 @@
).toLocaleTimeString();
}
+ const knownContact = contactList.find(
+ contact => contact.address === data.parsed.replyAddress,
+ );
+ const fromKnownSender = typeof knownContact !== 'undefined';
+
// A wallet migrating from bch-api tx history to chronik will get caught here for one update cycle
let unparsedTx = false;
if (!Object.keys(data).includes('parsed')) {
@@ -561,46 +565,11 @@
: 'Received'}
</ReceivedHeader>
- {addressesInContactList.includes(
- data.parsed
- .replyAddress,
- ) && (
- <>
- <h4>from</h4>
- {contactList.map(
- (
- contact,
- index,
- ) => {
- let result;
- const contactAddress =
- contact.address;
- const dataAddress =
- data
- .parsed
- .replyAddress;
- if (
- contactAddress ===
- dataAddress
- ) {
- result =
- contact.name;
- } else {
- result =
- '';
- }
- return (
- <h4
- key={`${data.txid}${index}`}
- >
- {
- result
- }
- </h4>
- );
- },
- )}
- </>
+ {fromKnownSender && (
+ <h4>
+ from{' '}
+ {knownContact.name}
+ </h4>
)}
</ReceivedFromCtn>
)}
@@ -845,10 +814,7 @@
}
>
{data.parsed.incoming &&
- !addressesInContactList.includes(
- data.parsed
- .replyAddress,
- ) && (
+ !fromKnownSender && (
<NotInContactsAlert>
Warning: This
sender is not in
@@ -893,11 +859,7 @@
data
.parsed
.incoming &&
- !addressesInContactList.includes(
- data
- .parsed
- .replyAddress,
- ) ? (
+ !fromKnownSender ? (
<ShowHideMessageButton
onClick={e => {
e.stopPropagation();
@@ -916,11 +878,7 @@
.opReturnMessage
}
</p>
- {!addressesInContactList.includes(
- data
- .parsed
- .replyAddress,
- ) &&
+ {!fromKnownSender &&
data
.parsed
.incoming && (
@@ -946,11 +904,7 @@
data
.parsed
.incoming &&
- !addressesInContactList.includes(
- data
- .parsed
- .replyAddress,
- ) ? (
+ !fromKnownSender ? (
<ShowHideMessageButton
onClick={e => {
e.stopPropagation();
@@ -998,10 +952,7 @@
.replyAddress) ||
(cashtabSettings.hideMessagesFromUnknownSenders &&
displayedMessage) ||
- (addressesInContactList.includes(
- data.parsed
- .replyAddress,
- ) &&
+ (fromKnownSender &&
data.parsed.incoming &&
data.parsed
.replyAddress) ? (
@@ -1088,9 +1039,7 @@
</TxLink>
{!!data.parsed.incoming &&
data.parsed.replyAddress &&
- !addressesInContactList.includes(
- data.parsed.replyAddress,
- ) && (
+ !fromKnownSender && (
<AddToContacts>
<DropdownButton>
<Link
@@ -1125,7 +1074,6 @@
data: PropTypes.object,
fiatPrice: PropTypes.number,
fiatCurrency: PropTypes.string,
- addressesInContactList: PropTypes.arrayOf(PropTypes.string),
contactList: PropTypes.arrayOf(
PropTypes.shape({
address: PropTypes.string,
diff --git a/cashtab/src/components/Home/TxHistory.js b/cashtab/src/components/Home/TxHistory.js
--- a/cashtab/src/components/Home/TxHistory.js
+++ b/cashtab/src/components/Home/TxHistory.js
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import Tx from './Tx';
-import { flattenContactList } from 'utils/cashMethods';
const TxHistory = ({
txs,
@@ -11,8 +10,6 @@
cashtabSettings,
cashtabCache,
}) => {
- // Convert contactList array of objects to an array of addresses
- const addressesInContactList = flattenContactList(contactList);
return (
<div>
{txs.map(tx => (
@@ -21,7 +18,6 @@
data={tx}
fiatPrice={fiatPrice}
fiatCurrency={fiatCurrency}
- addressesInContactList={addressesInContactList}
contactList={contactList}
cashtabSettings={cashtabSettings}
cashtabCache={cashtabCache}
diff --git a/cashtab/src/components/Home/__tests__/Tx.test.js b/cashtab/src/components/Home/__tests__/Tx.test.js
--- a/cashtab/src/components/Home/__tests__/Tx.test.js
+++ b/cashtab/src/components/Home/__tests__/Tx.test.js
@@ -43,8 +43,7 @@
data={mockReceivedTxData}
fiatPrice={0.00003}
fiatCurrency="usd"
- addressesInContactList={[]}
- contactList={[{}]}
+ contactList={[]}
cashtabSettings={cashtabSettings}
cashtabCache={cashtabCache}
/>
@@ -72,8 +71,7 @@
data={noTimeFirstSeenMock}
fiatPrice={0.00003}
fiatCurrency="usd"
- addressesInContactList={[]}
- contactList={[{}]}
+ contactList={[]}
cashtabSettings={cashtabSettings}
cashtabCache={cashtabCache}
/>
@@ -101,8 +99,7 @@
data={noTimeFirstSeenUnconfirmedMock}
fiatPrice={0.00003}
fiatCurrency="usd"
- addressesInContactList={[]}
- contactList={[{}]}
+ contactList={[]}
cashtabSettings={cashtabSettings}
cashtabCache={cashtabCache}
/>
@@ -116,4 +113,50 @@
// No timestamp is rendered as we have no timestamp to go off of in this case
expect(leftTxtCtn).toHaveTextContent('Received');
});
+ it('Renders from contact name if a tx is from an address in contact list', async () => {
+ render(
+ <ThemeProvider theme={theme}>
+ <Tx
+ data={mockReceivedTxData}
+ fiatPrice={0.00003}
+ fiatCurrency="usd"
+ contactList={[
+ {
+ name: 'inTheList',
+ address:
+ 'ecash:qp89xgjhcqdnzzemts0aj378nfe2mhu9yvxj9nhgg6',
+ },
+ ]}
+ cashtabSettings={cashtabSettings}
+ cashtabCache={cashtabCache}
+ />
+ ,
+ </ThemeProvider>,
+ );
+
+ expect(screen.getByText('from inTheList')).toBeInTheDocument();
+ });
+ it('Does not render from contact name if a tx is not from an address in contact list', async () => {
+ render(
+ <ThemeProvider theme={theme}>
+ <Tx
+ data={mockReceivedTxData}
+ fiatPrice={0.00003}
+ fiatCurrency="usd"
+ contactList={[
+ {
+ name: 'inTheList',
+ address:
+ 'ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07',
+ },
+ ]}
+ cashtabSettings={cashtabSettings}
+ cashtabCache={cashtabCache}
+ />
+ ,
+ </ThemeProvider>,
+ );
+
+ expect(screen.queryByText('from inTheList')).not.toBeInTheDocument();
+ });
});
diff --git a/cashtab/src/utils/__tests__/cashMethods.test.js b/cashtab/src/utils/__tests__/cashMethods.test.js
--- a/cashtab/src/utils/__tests__/cashMethods.test.js
+++ b/cashtab/src/utils/__tests__/cashMethods.test.js
@@ -2,7 +2,6 @@
import * as utxolib from '@bitgo/utxo-lib';
import cashaddr from 'ecashaddrjs';
import {
- flattenContactList,
isValidStoredWallet,
fromLegacyDecimals,
convertToEcashPrefix,
@@ -1154,42 +1153,6 @@
);
});
- it(`flattenContactList flattens contactList array by returning an array of addresses`, () => {
- expect(
- flattenContactList([
- {
- address: 'ecash:qpdkc5p7f25hwkxsr69m3evlj4h7wqq9xcgmjc8sxr',
- name: 'Alpha',
- },
- {
- address: 'ecash:qpq235n3l3u6ampc8slapapnatwfy446auuv64ylt2',
- name: 'Beta',
- },
- {
- address: 'ecash:qz50e58nkeg2ej2f34z6mhwylp6ven8emy8pp52r82',
- name: 'Gamma',
- },
- ]),
- ).toStrictEqual([
- 'ecash:qpdkc5p7f25hwkxsr69m3evlj4h7wqq9xcgmjc8sxr',
- 'ecash:qpq235n3l3u6ampc8slapapnatwfy446auuv64ylt2',
- 'ecash:qz50e58nkeg2ej2f34z6mhwylp6ven8emy8pp52r82',
- ]);
- });
-
- it(`flattenContactList flattens contactList array of length 1 by returning an array of 1 address`, () => {
- expect(
- flattenContactList([
- {
- address: 'ecash:qpdkc5p7f25hwkxsr69m3evlj4h7wqq9xcgmjc8sxr',
- name: 'Alpha',
- },
- ]),
- ).toStrictEqual(['ecash:qpdkc5p7f25hwkxsr69m3evlj4h7wqq9xcgmjc8sxr']);
- });
- it(`flattenContactList returns an empty array for invalid input`, () => {
- expect(flattenContactList(false)).toStrictEqual([]);
- });
it(`getHashArrayFromWallet returns false for a legacy wallet`, () => {
expect(
getHashArrayFromWallet(mockLegacyWallets.legacyAlphaMainnet),
diff --git a/cashtab/src/utils/cashMethods.js b/cashtab/src/utils/cashMethods.js
--- a/cashtab/src/utils/cashMethods.js
+++ b/cashtab/src/utils/cashMethods.js
@@ -1,4 +1,3 @@
-import { isValidContactList } from 'validation';
import { BN, TokenType1 } from 'slp-mdm';
import cashaddr from 'ecashaddrjs';
import * as utxolib from '@bitgo/utxo-lib';
@@ -614,23 +613,6 @@
return amountSmallestDenomination;
};
-export const flattenContactList = contactList => {
- /*
- Converts contactList from array of objects of type {address: <valid XEC address>, name: <string>} to array of addresses only
-
- If contact list is invalid, returns and empty array
- */
- if (!isValidContactList(contactList)) {
- return [];
- }
- let flattenedContactList = [];
- for (let i = 0; i < contactList.length; i += 1) {
- const thisAddress = contactList[i].address;
- flattenedContactList.push(thisAddress);
- }
- return flattenedContactList;
-};
-
export const getWalletBalanceFromUtxos = nonSlpUtxos => {
const totalBalanceInSatoshis = nonSlpUtxos.reduce(
(previousBalance, utxo) => previousBalance.plus(new BN(utxo.value)),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, May 12, 01:43 (21 h, 26 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5777051
Default Alt Text
D15498.id45438.diff (18 KB)
Attached To
D15498: [Cashtab] Improve rendering of from contact name in tx history
Event Timeline
Log In to Comment