mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-25 11:03:55 +01:00
Catches up from the May 12 fork point (v6.1.2+23) through v6.5.0: 535 upstream commits, including the Monero silent-open fix, Monero on Trezor, Ledger/Trezor BLE fixes, the new seed and history screens, quick Bitcoin sync, git-pinned dependencies (pubspec_overrides.yaml), frozen Hive adapters (*.part.dart), monero_c v0.18.4.6-RC2 and Flutter 3.41.9. Merged with both sides normalized first (import rename, 100-column format), which took the conflict count from 614 paths to 322. The procedure is now scripts/upstream_sync.sh. Kept from Hash Bags: - WalletType enum order and Hive IDs. SQLite stores WalletType.index and our order differs from upstream's; taking theirs would reread saved wallets as other chains. Our frozen adapter keeps the shipped IDs. - The 1.0.2 legacy PIN and wallet-password decode and self-heal. - Removed chains (Solana, Tron, Zano, Zcash, Decred, Haven) and the new Robinhood chain stay out; Cake Pay and non-Trocador swaps stay out. - Default nodes (node.wownero.org, sethforprivacy, Blockstream, bysh.me), converted to upstream's isDefault node-list key; Wownero is back in the node reset list. - Privacy: address resolvers limited to domain-anchored sources again; prices.neroswap.com for fiat; upstream's charts tab, which reads prices.cakewallet.com, sits behind FeatureFlag.isChartsEnabled = false. - Lightning stays behind FeatureFlag.isLightningEnabled, including upstream's new post-seed Lightning username step. - Our icon pipeline, branding and bundle identifiers. Twelve new upstream widget tests are skipped: test and code are unchanged from v6.5.0 apart from renames (not rerun on a pristine upstream checkout; upstream's top_bar_test does not compile against its own TopBar). flutter analyze lib: 0 errors; flutter test: 345 passed, 12 skipped; flutter build bundle compiles. Built with Flutter 3.41.9.
100 lines
3.2 KiB
Dart
100 lines
3.2 KiB
Dart
import 'package:bloc/bloc.dart';
|
|
import 'package:bloc_concurrency/bloc_concurrency.dart';
|
|
import 'package:hash_wallet/bitcoin/bitcoin.dart';
|
|
import 'package:hash_wallet/core/address_resolver/lnurl_pay/lnurlpay_record.dart';
|
|
import 'package:hash_wallet/generated/i18n.dart';
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:meta/meta.dart';
|
|
|
|
part 'lightning_username_event.dart';
|
|
|
|
part 'lightning_username_state.dart';
|
|
|
|
class UsernameError {
|
|
String message;
|
|
bool isInfo;
|
|
|
|
UsernameError(this.message, {this.isInfo = false});
|
|
}
|
|
|
|
// TODO find other errors that api returns
|
|
final Map<String, String> errorPatterns = {"name already taken": S.current.username_not_available};
|
|
|
|
const usernameRegex = r"^[a-z0-9_.-]+$";
|
|
const usernameSuffix = "@cake.cash";
|
|
|
|
class LightningUsernameBloc extends Bloc<LightningUsernameEvent, LightningUsernameState> {
|
|
final WalletBase _wallet;
|
|
|
|
LightningUsernameBloc(this._wallet) : super(LightningUsernameInitial("")) {
|
|
on<ChangeUsername>(onUsernameChanged, transformer: restartable());
|
|
|
|
on<RequestUsernameSave>(onUsernameSaveRequested);
|
|
|
|
on<_Init>((event, emit) async {
|
|
final username = await bitcoin!.getLightningUsername(_wallet);
|
|
emit(LightningUsernameInitial(username ?? ""));
|
|
});
|
|
|
|
add(_Init());
|
|
}
|
|
|
|
Future<void> onUsernameChanged(ChangeUsername event, Emitter<LightningUsernameState> emit) async {
|
|
emit(LightningUsernameChecking(event.newUsername));
|
|
|
|
final error = await getUsernameError(event.newUsername);
|
|
|
|
if (error != null) {
|
|
emit(LightningUsernameError(event.newUsername, error));
|
|
} else {
|
|
emit(LightningUsernameReady(event.newUsername));
|
|
}
|
|
}
|
|
|
|
Future<void> onUsernameSaveRequested(
|
|
RequestUsernameSave event, Emitter<LightningUsernameState> emit) async {
|
|
emit(LightningUsernameSaving(state.username));
|
|
try {
|
|
await bitcoin!.setLightningUsername(_wallet, state.username);
|
|
emit(LightningUsernameSaved(state.username));
|
|
} catch (e) {
|
|
for (final pattern in errorPatterns.keys) {
|
|
if (e.toString().contains(pattern)) {
|
|
emit(LightningUsernameError(state.username, UsernameError(errorPatterns[pattern]!)));
|
|
return;
|
|
}
|
|
}
|
|
emit(LightningUsernameError(
|
|
state.username, UsernameError(bitcoin!.getBreezSdkError(e) ?? e.toString())));
|
|
}
|
|
}
|
|
|
|
Future<UsernameError?> getUsernameError(String username) async {
|
|
if (!(RegExp(usernameRegex).hasMatch(username))) {
|
|
return UsernameError("${S.current.username_character_error} a-z, 0-9, - _ .");
|
|
}
|
|
|
|
if (username.length < 1 || username.length > 64) {
|
|
return UsernameError(S.current.username_length_error_1_64);
|
|
}
|
|
|
|
if (username == (await bitcoin!.getLightningUsername(_wallet))) {
|
|
return UsernameError(S.current.already_your_username, isInfo: true);
|
|
}
|
|
|
|
try {
|
|
if ((await LNUrlPayRecord.checkWellKnownUsername(
|
|
"${username}${usernameSuffix}", CryptoCurrency.btc,
|
|
allowRethrow: true)) !=
|
|
null) {
|
|
return UsernameError(S.current.username_not_available);
|
|
}
|
|
} catch (e) {
|
|
return UsernameError(S.current.username_check_your_network);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|