dev
dart 66 lines 1.22 KB
Raw
1 import 'package:cw_core/hive_type_ids.dart';
2 import 'package:hive/hive.dart';
3
4 part 'payjoin_session.part.dart';
5
6 // @HiveType(typeId: PAYJOIN_SESSION_TYPE_ID)
7 class PayjoinSession extends HiveObject {
8 PayjoinSession({
9 required this.walletId,
10 this.receiver,
11 this.sender,
12 this.pjUri,
13 this.status = "created",
14 this.inProgressSince,
15 this.rawAmount,
16 }) {
17 if (receiver == null) {
18 assert(sender != null);
19 assert(pjUri != null);
20 } else {
21 assert(receiver != null);
22 }
23 }
24
25 static const typeId = PAYJOIN_SESSION_TYPE_ID;
26 static const boxName = 'PayjoinSessions';
27
28 // @HiveField(0)
29 final String walletId;
30
31 // @HiveField(1)
32 final String? sender;
33
34 // @HiveField(2)
35 final String? receiver;
36
37 // @HiveField(3)
38 final String? pjUri;
39
40 // @HiveField(4)
41 String status;
42
43 // @HiveField(5)
44 DateTime? inProgressSince;
45
46 // @HiveField(6)
47 String? txId;
48
49 // @HiveField(7)
50 String? rawAmount;
51
52 // @HiveField(8)
53 String? error;
54
55 bool get isSenderSession => sender != null;
56
57 BigInt get amount => BigInt.parse(rawAmount ?? "0");
58 set amount(BigInt amount) => rawAmount = amount.toString();
59 }
60
61 enum PayjoinSessionStatus {
62 created,
63 inProgress,
64 success,
65 unrecoverable,
66 }