Skip to content

Commit 308f29e

Browse files
feat: improve UI/UX for nano state detail and tx data with new custom types (#654)
1 parent 270d7f6 commit 308f29e

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

package-lock.json

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"private": true,
3131
"dependencies": {
32-
"@hathor/wallet-lib": "1.8.0",
32+
"@hathor/wallet-lib": "1.10.0",
3333
"@ledgerhq/hw-transport-node-hid": "6.28.1",
3434
"@reduxjs/toolkit": "2.2.3",
3535
"@sentry/electron": "3.0.7",

src/components/TxData.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class TxData extends React.Component {
106106

107107
const network = hathorLib.config.getNetwork();
108108
const ncData = this.props.transaction;
109-
const deserializer = new hathorLib.NanoContractTransactionParser(ncData.nc_blueprint_id, ncData.nc_method, ncData.nc_pubkey, ncData.nc_args);
110-
deserializer.parseAddress(network);
109+
const deserializer = new hathorLib.NanoContractTransactionParser(ncData.nc_blueprint_id, ncData.nc_method, ncData.nc_pubkey, network, ncData.nc_args);
110+
deserializer.parseAddress();
111111
await deserializer.parseArguments();
112112
this.setState({ ncDeserializer: deserializer, ncLoading: false });
113113
}
@@ -952,10 +952,19 @@ class TxData extends React.Component {
952952
}
953953

954954
const renderArgValue = (arg) => {
955-
if (arg.type === 'bytes') {
955+
const typeBytesOrigin = ['bytes', 'TxOutputScript', 'TokenUid', 'VertexId', 'ContractId'];
956+
if (typeBytesOrigin.includes(arg.type)) {
956957
return arg.parsed.toString('hex');
957958
}
958959

960+
if (arg.type === 'Timestamp') {
961+
return hathorLib.dateFormatter.parseTimestamp(arg.parsed);
962+
}
963+
964+
if (arg.type === 'Amount') {
965+
return numberUtils.prettyValue(arg.parsed, this.props.decimalPlaces);
966+
}
967+
959968
return arg.parsed;
960969
}
961970

src/screens/nano/NanoContractDetail.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ function NanoContractDetail() {
3232
const context = useContext(GlobalModalContext);
3333
const wallet = getGlobalWallet();
3434

35-
const { nanoContracts, blueprintsData, tokenMetadata, decimalPlaces } = useSelector((state) => {
35+
const {
36+
nanoContracts,
37+
blueprintsData,
38+
tokenMetadata,
39+
decimalPlaces,
40+
} = useSelector((state) => {
3641
return {
3742
nanoContracts: state.nanoContracts,
3843
blueprintsData: state.blueprintsData,
@@ -170,12 +175,23 @@ function NanoContractDetail() {
170175
return get(blueprintInformation.attributes, field);
171176
}
172177

173-
// Some fields should be better parsed, e.g., timestamp, address
174-
// however we don't have a simple and generic way to knowing it
175-
// this was discussed and we will have this in the future, so
176-
// for now we keep this UI and when we have this feature in the
177-
// hathor-core, we can improve the user UI
178-
return value === null ? ' - ' : value;
178+
if (value == null) {
179+
// If value is null or undefined, we show empty string
180+
return null;
181+
}
182+
183+
// Get type of value but removing possible optional mark (?) to format the value correctly
184+
const type = blueprintInformation.attributes[field].replace('?', '');
185+
186+
if (type === 'Timestamp') {
187+
return hathorLib.dateUtils.parseTimestamp(value);
188+
}
189+
190+
if (type === 'Amount') {
191+
return hathorLib.numberUtils.prettyValue(value, decimalPlaces);
192+
}
193+
194+
return value;
179195
}
180196

181197
/**

0 commit comments

Comments
 (0)