2024-11-09 18:59:47 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2023-04-21 18:36:47 +00:00
|
|
|
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
|
|
|
|
class RestoredWallet {
|
|
|
|
RestoredWallet(
|
|
|
|
{required this.restoreMode,
|
|
|
|
required this.type,
|
|
|
|
required this.address,
|
|
|
|
this.txId,
|
|
|
|
this.spendKey,
|
|
|
|
this.viewKey,
|
|
|
|
this.mnemonicSeed,
|
2024-09-24 03:40:33 +00:00
|
|
|
this.passphrase,
|
2023-04-21 18:36:47 +00:00
|
|
|
this.txAmount,
|
|
|
|
this.txDescription,
|
|
|
|
this.recipientName,
|
2023-08-23 12:33:20 +00:00
|
|
|
this.height,
|
|
|
|
this.privateKey});
|
2023-04-21 18:36:47 +00:00
|
|
|
|
|
|
|
final WalletRestoreMode restoreMode;
|
|
|
|
final WalletType type;
|
|
|
|
final String? address;
|
|
|
|
final String? txId;
|
|
|
|
final String? spendKey;
|
|
|
|
final String? viewKey;
|
|
|
|
final String? mnemonicSeed;
|
2024-09-24 03:40:33 +00:00
|
|
|
final String? passphrase;
|
2023-04-21 18:36:47 +00:00
|
|
|
final String? txAmount;
|
|
|
|
final String? txDescription;
|
|
|
|
final String? recipientName;
|
|
|
|
final int? height;
|
2023-08-23 12:33:20 +00:00
|
|
|
final String? privateKey;
|
2023-04-21 18:36:47 +00:00
|
|
|
|
|
|
|
factory RestoredWallet.fromKey(Map<String, dynamic> json) {
|
2024-11-09 18:59:47 +00:00
|
|
|
try {
|
|
|
|
final codeParsed = jsonDecode(json['raw_qr'].toString());
|
|
|
|
if (codeParsed["version"] == 0) {
|
|
|
|
json['address'] = codeParsed["primaryAddress"];
|
|
|
|
json['view_key'] = codeParsed["privateViewKey"];
|
|
|
|
json['height'] = codeParsed["restoreHeight"].toString();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// fine, we don't care, it is only for monero anyway
|
|
|
|
}
|
2023-04-21 18:36:47 +00:00
|
|
|
final height = json['height'] as String?;
|
|
|
|
return RestoredWallet(
|
|
|
|
restoreMode: json['mode'] as WalletRestoreMode,
|
|
|
|
type: json['type'] as WalletType,
|
|
|
|
address: json['address'] as String?,
|
|
|
|
spendKey: json['spend_key'] as String?,
|
|
|
|
viewKey: json['view_key'] as String?,
|
2024-11-09 18:59:47 +00:00
|
|
|
height: height != null ? int.tryParse(height)??0 : 0,
|
2023-08-23 12:33:20 +00:00
|
|
|
privateKey: json['private_key'] as String?,
|
2023-04-21 18:36:47 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
factory RestoredWallet.fromSeed(Map<String, dynamic> json) {
|
|
|
|
final height = json['height'] as String?;
|
|
|
|
final mnemonic_seed = json['mnemonic_seed'] as String?;
|
2023-11-24 23:35:00 +00:00
|
|
|
final seed = json['seed'] as String? ?? json['hexSeed'] as String?;
|
2024-09-24 03:40:33 +00:00
|
|
|
final passphrase = json['passphrase'] as String?;
|
2023-04-21 18:36:47 +00:00
|
|
|
return RestoredWallet(
|
|
|
|
restoreMode: json['mode'] as WalletRestoreMode,
|
|
|
|
type: json['type'] as WalletType,
|
|
|
|
address: json['address'] as String?,
|
|
|
|
mnemonicSeed: mnemonic_seed ?? seed,
|
2024-09-24 03:40:33 +00:00
|
|
|
passphrase: passphrase,
|
2023-04-21 18:36:47 +00:00
|
|
|
height: height != null ? int.parse(height) : 0,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
factory RestoredWallet.fromTxIds(Map<String, dynamic> json) {
|
|
|
|
return RestoredWallet(
|
|
|
|
restoreMode: json['mode'] as WalletRestoreMode,
|
|
|
|
type: json['type'] as WalletType,
|
|
|
|
address: json['address'] as String?,
|
|
|
|
txId: json['tx_payment_id'] as String,
|
|
|
|
txAmount: json['tx_amount'] as String,
|
|
|
|
txDescription: json['tx_description'] as String?,
|
|
|
|
recipientName: json['recipient_name'] as String?,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|