Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/packages/service/transaction_history_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ extension ToEpiAddress on String {
String get asHexEip55 => EthereumAddress.fromHex(this).hexEip55;

String get asShortTxId {
// A txid shorter than the elided form (10 + "..." + 10 = 23) is returned
// whole: slicing it would throw a RangeError for length < 10 and overlap
// the head/tail for length < 20 (issue #657 P9 L1).
if (length <= 23) return this;
return '${substring(0, 10)}...${substring(length - 10)}';
}
}
10 changes: 10 additions & 0 deletions test/packages/service/transaction_history_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,15 @@ void main() {
expect(txid.asShortTxId.contains('...'), isTrue);
expect(txid.asShortTxId.length, 23); // 10 + 3 + 10
});

test('asShortTxId returns a short id whole without a RangeError '
'(issue #657 P9 L1 regression)', () {
// Anything not longer than the elided form is shown whole; the old code
// crashed with a RangeError on substring(0, 10) / substring(length - 10)
// for these inputs.
expect('0xabc'.asShortTxId, '0xabc');
expect(''.asShortTxId, '');
expect('0x12345678'.asShortTxId, '0x12345678'); // length 10, would overlap
});
});
}
Loading