REF: Extract Action keys and icons

This commit is contained in:
Marcos Rodriguez Velez 2024-07-04 14:45:07 -04:00
parent aeb4db00eb
commit 072b2eba9a
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7
4 changed files with 74 additions and 71 deletions

View File

@ -22,6 +22,7 @@ import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { DetailViewStackParamList } from '../navigation/DetailViewStackParamList';
import { useStorage } from '../hooks/context/useStorage';
import ToolTipMenu from './TooltipMenu';
import { CommonToolTipActions } from '../typings/CommonToolTipActions';
interface TransactionListItemProps {
itemPriceUnit: BitcoinUnit;
@ -261,17 +262,17 @@ export const TransactionListItem: React.FC<TransactionListItemProps> = React.mem
const onToolTipPress = useCallback(
(id: any) => {
if (id === actionKeys.CopyAmount) {
if (id === CommonToolTipActions.CopyAmount.id) {
handleOnCopyAmountTap();
} else if (id === actionKeys.CopyNote) {
} else if (id === CommonToolTipActions.CopyNote.id) {
handleOnCopyNote();
} else if (id === actionKeys.OpenInBlockExplorer) {
} else if (id === CommonToolTipActions.OpenInBlockExplorer.id) {
handleOnViewOnBlockExplorer();
} else if (id === actionKeys.ExpandNote) {
} else if (id === CommonToolTipActions.ExpandNote.id) {
handleOnExpandNote();
} else if (id === actionKeys.CopyBlockExplorerLink) {
} else if (id === CommonToolTipActions.CopyBlockExplorerLink.id) {
handleCopyOpenInBlockExplorerPress();
} else if (id === actionKeys.CopyTXID) {
} else if (id === CommonToolTipActions.CopyTXID.id) {
handleOnCopyTransactionID();
}
},
@ -288,51 +289,19 @@ export const TransactionListItem: React.FC<TransactionListItemProps> = React.mem
const actions: (Action | Action[])[] = [];
if (rowTitle !== loc.lnd.expired) {
actions.push({
id: actionKeys.CopyAmount,
text: loc.transactions.details_copy_amount,
icon: actionIcons.Clipboard,
});
actions.push(CommonToolTipActions.CopyAmount);
}
if (subtitle) {
actions.push({
id: actionKeys.CopyNote,
text: loc.transactions.details_copy_note,
icon: actionIcons.Clipboard,
});
actions.push(CommonToolTipActions.CopyNote);
}
if (item.hash) {
actions.push(
{
id: actionKeys.CopyTXID,
text: loc.transactions.details_copy_txid,
icon: actionIcons.Clipboard,
},
{
id: actionKeys.CopyBlockExplorerLink,
text: loc.transactions.details_copy_block_explorer_link,
icon: actionIcons.Clipboard,
},
[
{
id: actionKeys.OpenInBlockExplorer,
text: loc.transactions.details_show_in_block_explorer,
icon: actionIcons.Link,
},
],
);
actions.push(CommonToolTipActions.CopyTXID, CommonToolTipActions.CopyBlockExplorerLink, [CommonToolTipActions.OpenInBlockExplorer]);
}
if (subtitle && subtitleNumberOfLines === 1) {
actions.push([
{
id: actionKeys.ExpandNote,
text: loc.transactions.expand_note,
icon: actionIcons.Note,
},
]);
actions.push([CommonToolTipActions.ExpandNote]);
}
return actions as Action[] | Action[][];
@ -356,33 +325,6 @@ export const TransactionListItem: React.FC<TransactionListItemProps> = React.mem
);
});
const actionKeys = {
CopyTXID: 'copyTX_ID',
CopyBlockExplorerLink: 'copy_blockExplorer',
ExpandNote: 'expandNote',
OpenInBlockExplorer: 'open_in_blockExplorer',
CopyAmount: 'copyAmount',
CopyNote: 'copyNote',
};
const actionIcons = {
Eye: {
iconValue: 'eye',
},
EyeSlash: {
iconValue: 'eye.slash',
},
Clipboard: {
iconValue: 'doc.on.doc',
},
Link: {
iconValue: 'link',
},
Note: {
iconValue: 'note.text',
},
};
const styles = StyleSheet.create({
iconWidth: { width: 25 },
});

View File

@ -64,7 +64,7 @@
"e2e:release-build": "detox build -c android.release",
"e2e:release-test": "detox test -c android.release",
"tslint": "tsc",
"lint": " npm run tslint && node scripts/find-unused-loc.js && eslint --ext .js,.ts,.tsx '*.@(js|ts|tsx)' screen 'blue_modules/*.@(js|ts|tsx)' class models loc tests components navigation",
"lint": " npm run tslint && node scripts/find-unused-loc.js && eslint --ext .js,.ts,.tsx '*.@(js|ts|tsx)' screen 'blue_modules/*.@(js|ts|tsx)' class models loc tests components navigation typings",
"lint:fix": "npm run lint -- --fix",
"lint:quickfix": "git status --porcelain | grep -v '\\.json' | grep -E '\\.js|\\.ts' --color=never | awk '{print $2}' | xargs eslint --fix; exit 0",
"unit": "jest -b -i tests/unit/*"

View File

@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const mainLocFile = './loc/en.json';
const dirsToInterate = ['components', 'screen', 'blue_modules', 'class', 'hooks', 'helpers', 'navigation'];
const dirsToInterate = ['components', 'screen', 'blue_modules', 'class', 'hooks', 'helpers', 'navigation', 'typings'];
const addFiles = ['BlueComponents.js', 'App.tsx', 'navigation/index.tsx'];
const allowedLocPrefixes = ['loc.lnurl_auth', 'loc.units'];

View File

@ -0,0 +1,61 @@
import loc from '../loc';
const keys = {
CopyTXID: 'copyTX_ID',
CopyBlockExplorerLink: 'copy_blockExplorer',
ExpandNote: 'expandNote',
OpenInBlockExplorer: 'open_in_blockExplorer',
CopyAmount: 'copyAmount',
CopyNote: 'copyNote',
};
const icons = {
Eye: {
iconValue: 'eye',
},
EyeSlash: {
iconValue: 'eye.slash',
},
Clipboard: {
iconValue: 'doc.on.doc',
},
Link: {
iconValue: 'link',
},
Note: {
iconValue: 'note.text',
},
};
export const CommonToolTipActions = {
CopyTXID: {
id: keys.CopyTXID,
text: loc.transactions.details_copy_txid,
icon: icons.Clipboard,
},
CopyBlockExplorerLink: {
id: keys.CopyBlockExplorerLink,
text: loc.transactions.details_copy_block_explorer_link,
icon: icons.Clipboard,
},
OpenInBlockExplorer: {
id: keys.OpenInBlockExplorer,
text: loc.transactions.details_show_in_block_explorer,
icon: icons.Link,
},
ExpandNote: {
id: keys.ExpandNote,
text: loc.transactions.expand_note,
icon: icons.Note,
},
CopyAmount: {
id: keys.CopyAmount,
text: loc.transactions.details_copy_amount,
icon: icons.Clipboard,
},
CopyNote: {
id: keys.CopyNote,
text: loc.transactions.details_copy_note,
icon: icons.Clipboard,
},
};