Skip to content

Commit 2a4bcd6

Browse files
feat: improve UI/UX for nano state detail and tx data with new custom types
1 parent 88edc14 commit 2a4bcd6

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

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
}
@@ -929,10 +929,19 @@ class TxData extends React.Component {
929929
}
930930

931931
const renderArgValue = (arg) => {
932-
if (arg.type === 'bytes') {
932+
const typeBytesOrigin = ['bytes', 'TxOutputScript', 'TokenUid', 'VertexId'];
933+
if (typeBytesOrigin.includes(arg.type)) {
933934
return arg.parsed.toString('hex');
934935
}
935936

937+
if (arg.type === 'Timestamp') {
938+
return hathorLib.dateFormatter.parseTimestamp(arg.parsed);
939+
}
940+
941+
if (arg.type === 'Amount') {
942+
return numberUtils.prettyValue(arg.parsed, this.props.decimalPlaces);
943+
}
944+
936945
return arg.parsed;
937946
}
938947

src/screens/nano/NanoContractDetail.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ function NanoContractDetail() {
3131
const context = useContext(GlobalModalContext);
3232
const wallet = getGlobalWallet();
3333

34-
const { nanoContracts, blueprintsData, tokenMetadata } = useSelector((state) => {
34+
const {
35+
nanoContracts,
36+
blueprintsData,
37+
tokenMetadata,
38+
decimalPlaces,
39+
} = useSelector((state) => {
3540
return {
3641
nanoContracts: state.nanoContracts,
3742
blueprintsData: state.blueprintsData,
38-
tokenMetadata: state.tokenMetadata
43+
tokenMetadata: state.tokenMetadata,
44+
decimalPlaces: state.serverInfo.decimalPlaces,
3945
}
4046
});
4147

@@ -168,12 +174,23 @@ function NanoContractDetail() {
168174
return get(blueprintInformation.attributes, field);
169175
}
170176

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

179196
const renderNanoAttributes = () => {

0 commit comments

Comments
 (0)