mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-18 05:51:34 +02:00
94 files changed, -5926 net lines. No stubs, no generators, no dead enum
values, no orphan switch branches. Removed for principled reasons (we
do not ship these chains) and to make the codebase smaller and friendlier
to contribute to.
What's gone:
- lib/{solana,tron,zano,decred,zcash,haven}/ directories
- lib/exchange/provider/jupiter_exchange_provider.dart (Solana-only)
- lib/entities/haven_seed_store.dart
- WalletType.{solana,tron,zano,decred,zcash,haven} enum values
(HiveField IDs are pinned: Wownero stays at 12, all surviving types
keep their IDs, so existing user-saved wallets deserialize unchanged)
- All ~70 lib/ files that imported the removed chain stubs or branched
on the removed WalletType values
- backupSeeds(Box<HavenSeedStore>) abstract method + Wownero implementation
- Jupiter exchange branches in send/exchange view models
- TronGrid usage settings, Zano alias lookups, Zcash transparent address
handling, Decred default-spv-nodes branches, Haven seed migration
What stays (intentional):
- CryptoCurrency.{xhv,sol,trx,dcr,zano,zec} enum entries in cw_core —
they're still used as exchange/swap currency identifiers in
address_validator.dart and elsewhere. The wallet types are gone but
the *currencies* are still tradeable through Trocador.
- cw_core/spl_token.dart and cw_core/tron_token.dart Hive adapters in
main.dart — the tokens still register as Hive types for backwards-
compat with any old box data.
- lib/buy/{moonpay,robinhood,onramper,dfx,kryptonim,meld}/ provider
source files (just stripped of solana/tron/etc references; providers
themselves remain dormant per provider_types.dart).
Pinned-ID note: WalletType enum now has gaps in @HiveField IDs (4, 10,
11, 13, 14, 18 removed). This is deliberate — re-using a freed ID later
would mis-deserialize old hive boxes. Don't renumber.
Bundled config / CI hasn't changed; configure.dart was already free of
these chains in commit 4eb7db0b7.
166 lines
4.8 KiB
Dart
166 lines
4.8 KiB
Dart
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'dart:math' as math;
|
|
|
|
class AddressFormatter {
|
|
static Widget buildSegmentedAddress({
|
|
required String address,
|
|
WalletType? walletType,
|
|
required TextStyle evenTextStyle,
|
|
TextStyle? oddTextStyle,
|
|
TextAlign? textAlign,
|
|
bool shouldTruncate = false,
|
|
}) {
|
|
|
|
final cleanAddress = address.replaceAll('bitcoincash:', '');
|
|
final isMWEB = address.startsWith('ltcmweb');
|
|
final chunkSize = walletType != null ? _getChunkSize(walletType) : 4;
|
|
final isHumanReadable = address.contains("@") || address.startsWith("Error:");
|
|
|
|
if (isHumanReadable) {
|
|
return Text(address, style: evenTextStyle, textAlign: textAlign ?? TextAlign.start);
|
|
}
|
|
|
|
if (shouldTruncate) {
|
|
return _buildTruncatedAddress(
|
|
address: cleanAddress,
|
|
isMWEB: isMWEB,
|
|
chunkSize: chunkSize,
|
|
evenTextStyle: evenTextStyle,
|
|
oddTextStyle: oddTextStyle ?? evenTextStyle.copyWith(color: evenTextStyle.color!.withAlpha(150)),
|
|
textAlign: textAlign,
|
|
);
|
|
} else {
|
|
return _buildFullSegmentedAddress(
|
|
address: cleanAddress,
|
|
isMWEB: isMWEB,
|
|
chunkSize: chunkSize,
|
|
evenTextStyle: evenTextStyle,
|
|
oddTextStyle: oddTextStyle ?? evenTextStyle.copyWith(color: evenTextStyle.color!.withAlpha(128)),
|
|
textAlign: textAlign,
|
|
);
|
|
}
|
|
}
|
|
|
|
static Widget _buildFullSegmentedAddress({
|
|
required String address,
|
|
required bool isMWEB,
|
|
required int chunkSize,
|
|
required TextStyle evenTextStyle,
|
|
required TextStyle oddTextStyle,
|
|
TextAlign? textAlign,
|
|
}) {
|
|
|
|
final chunks = <String>[];
|
|
|
|
if (isMWEB) {
|
|
const mwebDisplayPrefix = 'ltcmweb';
|
|
chunks.add(mwebDisplayPrefix);
|
|
final startIndex = mwebDisplayPrefix.length;
|
|
for (int i = startIndex; i < address.length; i += chunkSize) {
|
|
final chunk = address.substring(
|
|
i,
|
|
math.min(i + chunkSize, address.length),
|
|
);
|
|
chunks.add(chunk);
|
|
}
|
|
} else {
|
|
for (int i = 0; i < address.length; i += chunkSize) {
|
|
final chunk = address.substring(
|
|
i,
|
|
math.min(i + chunkSize, address.length),
|
|
);
|
|
chunks.add(chunk);
|
|
}
|
|
}
|
|
|
|
final spans = <TextSpan>[];
|
|
for (int i = 0; i < chunks.length; i++) {
|
|
final style = (i % 2 == 0) ? evenTextStyle : oddTextStyle;
|
|
spans.add(TextSpan(text: '${chunks[i]} ', style: style));
|
|
}
|
|
|
|
return RichText(
|
|
text: TextSpan(children: spans),
|
|
textAlign: textAlign ?? TextAlign.start,
|
|
overflow: TextOverflow.visible,
|
|
);
|
|
}
|
|
|
|
static Widget _buildTruncatedAddress({
|
|
required String address,
|
|
required bool isMWEB,
|
|
required int chunkSize,
|
|
required TextStyle evenTextStyle,
|
|
required TextStyle oddTextStyle,
|
|
TextAlign? textAlign,
|
|
}) {
|
|
|
|
if (isMWEB) {
|
|
const fixedPrefix = 'ltcmweb';
|
|
final secondChunkStart = fixedPrefix.length;
|
|
const chunkSize = 4;
|
|
final secondChunk = address.substring(
|
|
secondChunkStart,
|
|
math.min(secondChunkStart + chunkSize, address.length),
|
|
);
|
|
final lastChunk = address.substring(address.length - chunkSize);
|
|
|
|
final spans = <TextSpan>[
|
|
TextSpan(text: '$fixedPrefix ', style: evenTextStyle),
|
|
TextSpan(text: '$secondChunk ', style: oddTextStyle),
|
|
TextSpan(text: '... ', style: oddTextStyle),
|
|
TextSpan(text: lastChunk, style: evenTextStyle),
|
|
];
|
|
|
|
return RichText(
|
|
text: TextSpan(children: spans),
|
|
textAlign: textAlign ?? TextAlign.start,
|
|
overflow: TextOverflow.visible,
|
|
);
|
|
} else {
|
|
final int digitCount = chunkSize;
|
|
|
|
if (address.length <= 2 * digitCount) {
|
|
return _buildFullSegmentedAddress(
|
|
address: address,
|
|
isMWEB: isMWEB,
|
|
chunkSize: chunkSize,
|
|
evenTextStyle: evenTextStyle,
|
|
oddTextStyle: oddTextStyle,
|
|
textAlign: textAlign,
|
|
);
|
|
}
|
|
|
|
final String firstPart = address.substring(0, digitCount);
|
|
final String secondPart =
|
|
address.substring(digitCount, digitCount * 2);
|
|
final String lastPart =
|
|
address.substring(address.length - digitCount);
|
|
|
|
final spans = <TextSpan>[
|
|
TextSpan(text: '$firstPart ', style: evenTextStyle),
|
|
TextSpan(text: '$secondPart ', style: oddTextStyle),
|
|
TextSpan(text: '... ', style: oddTextStyle),
|
|
TextSpan(text: lastPart, style: evenTextStyle),
|
|
];
|
|
|
|
return RichText(
|
|
text: TextSpan(children: spans),
|
|
textAlign: textAlign ?? TextAlign.start,
|
|
overflow: TextOverflow.visible,
|
|
);
|
|
}
|
|
}
|
|
|
|
static int _getChunkSize(WalletType walletType) {
|
|
switch (walletType) {
|
|
case WalletType.monero:
|
|
case WalletType.wownero:
|
|
return 6;
|
|
default:
|
|
return 4;
|
|
}
|
|
}
|
|
}
|