|
1 | 1 | import 'package:flutter/foundation.dart'; |
2 | 2 |
|
| 3 | +enum AccountType { local, keystone } |
| 4 | + |
3 | 5 | @immutable |
4 | 6 | class Account { |
| 7 | + final int walletIndex; |
5 | 8 | final int index; // derivation index |
6 | 9 | final String name; |
7 | 10 | final String accountId; // address |
8 | | - const Account({required this.index, required this.name, required this.accountId}); |
| 11 | + final AccountType accountType; |
| 12 | + const Account({ |
| 13 | + required this.walletIndex, |
| 14 | + required this.index, |
| 15 | + required this.name, |
| 16 | + required this.accountId, |
| 17 | + this.accountType = AccountType.local, |
| 18 | + }); |
9 | 19 |
|
10 | 20 | factory Account.fromJson(Map<String, dynamic> json) { |
11 | | - return Account(index: json['index'] as int, name: json['name'] as String, accountId: json['accountId'] as String); |
| 21 | + return Account( |
| 22 | + walletIndex: (json['walletIndex'] ?? 0) as int, |
| 23 | + index: json['index'] as int, |
| 24 | + name: json['name'] as String, |
| 25 | + accountId: json['accountId'] as String, |
| 26 | + accountType: AccountType.values.byName(json['accountType'] as String? ?? AccountType.local.name), |
| 27 | + ); |
12 | 28 | } |
13 | 29 |
|
14 | 30 | Map<String, dynamic> toJson() { |
15 | | - return {'index': index, 'name': name, 'accountId': accountId}; |
| 31 | + return { |
| 32 | + 'walletIndex': walletIndex, |
| 33 | + 'index': index, |
| 34 | + 'name': name, |
| 35 | + 'accountId': accountId, |
| 36 | + 'accountType': accountType.name, |
| 37 | + }; |
16 | 38 | } |
17 | 39 |
|
18 | | - Account copyWith({int? index, String? name, String? accountId, int? uiPosition}) { |
19 | | - return Account(index: index ?? this.index, name: name ?? this.name, accountId: accountId ?? this.accountId); |
| 40 | + Account copyWith({int? walletIndex, int? index, String? name, String? accountId, AccountType? accountType}) { |
| 41 | + return Account( |
| 42 | + walletIndex: walletIndex ?? this.walletIndex, |
| 43 | + index: index ?? this.index, |
| 44 | + name: name ?? this.name, |
| 45 | + accountId: accountId ?? this.accountId, |
| 46 | + accountType: accountType ?? this.accountType, |
| 47 | + ); |
20 | 48 | } |
21 | 49 | } |
0 commit comments