Skip to content

Commit 5e4d291

Browse files
authored
fix: pass coin as parameter (#682)
1 parent 62a041d commit 5e4d291

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4371
-2516
lines changed

lib/chart.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,17 @@ class ChartPageState extends ConsumerState<ChartPage> with SingleTickerProviderS
9292
}
9393
}
9494

95-
class SpendingChart extends StatefulWidget {
95+
class SpendingChart extends ConsumerStatefulWidget {
9696
final DateTime? from;
9797
final DateTime? to;
9898
const SpendingChart({super.key, this.from, this.to});
9999

100100
@override
101-
State<StatefulWidget> createState() => SpendingChartState();
101+
ConsumerState<SpendingChart> createState() => SpendingChartState();
102102
}
103103

104-
class SpendingChartState extends State<SpendingChart> with AutomaticKeepAliveClientMixin {
104+
class SpendingChartState extends ConsumerState<SpendingChart> with AutomaticKeepAliveClientMixin {
105+
late final c = ref.read(coinContextProvider);
105106
final List<Map<String, dynamic>> income = [];
106107
final List<Map<String, dynamic>> spending = [];
107108
bool isIncome = false;
@@ -124,7 +125,7 @@ class SpendingChartState extends State<SpendingChart> with AutomaticKeepAliveCli
124125
Future<void> refresh() async {
125126
final f = widget.from?.let((dt) => dt.millisecondsSinceEpoch ~/ 1000);
126127
final t = widget.to?.let((dt) => dt.millisecondsSinceEpoch ~/ 1000);
127-
final amounts = await fetchCategoryAmounts(from: f, to: t);
128+
final amounts = await fetchCategoryAmounts(from: f, to: t, c: c);
128129
income.clear();
129130
spending.clear();
130131
for (var (c, a, i) in amounts) {
@@ -261,6 +262,7 @@ class CategoryChart extends ConsumerStatefulWidget {
261262
}
262263

263264
class CategoryChartState extends ConsumerState<CategoryChart> with AutomaticKeepAliveClientMixin {
265+
late final c = ref.read(coinContextProvider);
264266
late final List<DropdownMenuItem<int>> categoriesMenu;
265267
int? category = 1;
266268
bool cumulative = false;
@@ -296,7 +298,7 @@ class CategoryChartState extends ConsumerState<CategoryChart> with AutomaticKeep
296298
Future<void> refresh() async {
297299
final f = widget.from?.let((dt) => dt.millisecondsSinceEpoch ~/ 1000);
298300
final t = widget.to?.let((dt) => dt.millisecondsSinceEpoch ~/ 1000);
299-
amounts = await fetchAmounts(from: f, to: t, category: category!);
301+
amounts = await fetchAmounts(from: f, to: t, category: category!, c: c);
300302
setState(() {
301303
epoch += 1;
302304
});

lib/pages/account.dart

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import 'package:showcaseview/showcaseview.dart';
1717
import 'package:zkool/main.dart';
1818
import 'package:zkool/pages/tx.dart';
1919
import 'package:zkool/router.dart';
20-
import 'package:zkool/src/rust/account.dart';
2120
import 'package:zkool/src/rust/api/account.dart';
2221
import 'package:zkool/src/rust/api/sync.dart';
2322
import 'package:zkool/src/rust/api/transaction.dart';
@@ -41,6 +40,7 @@ class AccountViewPageState extends ConsumerState<AccountViewPage> {
4140

4241
final List<String> tabNames = ["Transactions", "Memos", "Notes"];
4342

43+
late final c = ref.read(coinContextProvider);
4444
StreamSubscription<SyncProgress>? progressSubscription;
4545

4646
void tutorial() async {
@@ -195,11 +195,11 @@ class AccountViewPageState extends ConsumerState<AccountViewPage> {
195195
void onUpdateAllTxPrices() async {
196196
final confirmed =
197197
await confirmDialog(context, title: "Fetch Tx Market Price", message: "Do you want to retrieve historical ZEC prices for your past transactions?");
198-
if (confirmed) await fillMissingTxPrices();
198+
if (confirmed) await fillMissingTxPrices(c: c);
199199
}
200200

201201
void onExport(int index) async {
202-
final data = await getExportedData(type: index);
202+
final data = await getExportedData(type: index, c: c);
203203
final filename = await saveFile(data: utf8.encode(data));
204204
if (!mounted) return;
205205
if (filename != null) await showMessage(context, "$filename Saved");
@@ -230,6 +230,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
230230
final resetID = GlobalKey(debugLabel: "resetID");
231231
final folderID = GlobalKey(debugLabel: "folderID");
232232

233+
late final c = ref.read(coinContextProvider);
233234
late List<Account> accounts = widget.accounts;
234235
final formKey = GlobalKey<FormBuilderState>(debugLabel: "formKey");
235236
List<Folder>? folders;
@@ -404,6 +405,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
404405
name: name,
405406
folder: accounts[0].folder.id,
406407
),
408+
c: c,
407409
);
408410
ref.invalidate(getAccountsProvider);
409411
ref.invalidate(accountProvider(accounts[0].id));
@@ -434,6 +436,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
434436
icon: bytes,
435437
folder: accounts[0].folder.id,
436438
),
439+
c: c,
437440
);
438441
ref.invalidate(accountProvider(accounts[0].id));
439442
setState(() {});
@@ -450,6 +453,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
450453
birth: int.parse(birth),
451454
folder: accounts[0].folder.id,
452455
),
456+
c: c,
453457
);
454458
ref.invalidate(accountProvider(accounts[0].id));
455459
setState(() {});
@@ -467,6 +471,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
467471
enabled: v,
468472
folder: accounts[i].folder.id,
469473
),
474+
c: c,
470475
);
471476
ref.invalidate(accountProvider(accounts[i].id));
472477
}
@@ -484,6 +489,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
484489
hidden: v,
485490
folder: accounts[i].folder.id,
486491
),
492+
c: c,
487493
);
488494
ref.invalidate(accountProvider(accounts[i].id));
489495
}
@@ -501,6 +507,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
501507
id: accounts[i].id,
502508
folder: v,
503509
),
510+
c: c,
504511
);
505512
ref.invalidate(accountProvider(accounts[i].id));
506513
}
@@ -511,7 +518,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
511518
final account = accounts.first;
512519
final password = await inputPassword(context, title: "Export Account", message: "File Password", repeated: true, required: true);
513520
if (password != null) {
514-
final res = await exportAccount(id: account.id, passphrase: password);
521+
final res = await exportAccount(id: account.id, passphrase: password, c: c);
515522
await saveFile(title: "Please select an output file for the encrypted account:", fileName: "${account.name}.bin", data: res);
516523
}
517524
}
@@ -525,9 +532,9 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
525532
"Are you sure you want to rewind this account? This will rollback the account to a previous height. You will not lose any funds, but you will need to resync the account",
526533
);
527534
if (!confirmed) return;
528-
final dbHeight = await getDbHeight();
529-
await rewindSync(height: dbHeight.height - 60, account: account.id);
530-
final h = await getDbHeight();
535+
final dbHeight = await getDbHeight(c: c);
536+
await rewindSync(height: dbHeight.height - 60, account: account.id, c: c);
537+
final h = await getDbHeight(c: c);
531538
final ss = ref.read(syncStateAccountProvider(account.id).notifier);
532539
ss.updateHeight(h.height, h.time);
533540
}
@@ -541,7 +548,7 @@ class AccountEditPageState extends ConsumerState<AccountEditPage> with RouteAwar
541548
);
542549
if (!confirmed) return;
543550
for (var account in accounts) {
544-
await resetSync(id: account.id);
551+
await resetSync(id: account.id, c: c);
545552
ref.invalidate(accountProvider(account.id));
546553
}
547554
}
@@ -705,29 +712,33 @@ Widget showNotes(WidgetRef ref, List<TxNote> notes) {
705712

706713
void onLockRecent(WidgetRef ref, BuildContext context, int? currentHeight) async {
707714
if (currentHeight == null) return;
715+
final c = ref.read(coinContextProvider);
708716
final s = await inputText(context, title: "Enter confirmation threshold");
709717
final threshold = s?.let((v) => int.tryParse(v));
710718
if (threshold != null) {
711719
await lockRecentNotes(
712720
height: currentHeight,
713721
threshold: threshold,
722+
c: c,
714723
);
715724
final selectedAccount = ref.read(selectedAccountProvider).requireValue!;
716725
ref.invalidate(accountProvider(selectedAccount.id));
717726
}
718727
}
719728

720729
void onUnlockAll(WidgetRef ref, BuildContext context) async {
730+
final c = ref.read(coinContextProvider);
721731
final confirmed = await confirmDialog(context, title: "Unlock All", message: "Do you want to unlock every note?");
722732
if (confirmed) {
723-
await unlockAllNotes();
733+
await unlockAllNotes(c: c);
724734
final selectedAccount = ref.read(selectedAccountProvider).requireValue!;
725735
ref.invalidate(accountProvider(selectedAccount.id));
726736
}
727737
}
728738

729739
void toggleLock(WidgetRef ref, BuildContext context, int id, bool locked) async {
730-
await lockNote(id: id, locked: locked);
740+
final c = ref.read(coinContextProvider);
741+
await lockNote(id: id, locked: locked, c: c);
731742
final selectedAccount = ref.read(selectedAccountProvider).requireValue!;
732743
ref.invalidate(accountProvider(selectedAccount.id));
733744
}
@@ -775,6 +786,7 @@ class ViewingKeysPage extends ConsumerStatefulWidget {
775786
}
776787

777788
class ViewingKeysPageState extends ConsumerState<ViewingKeysPage> {
789+
late final c = ref.read(coinContextProvider);
778790
int pools = 7;
779791
String? uvk;
780792
String? fingerprint;
@@ -786,9 +798,9 @@ class ViewingKeysPageState extends ConsumerState<ViewingKeysPage> {
786798
void initState() {
787799
super.initState();
788800
Future(() async {
789-
fingerprint = await getAccountFingerprint(account: widget.account);
790-
seed = await getAccountSeed(account: widget.account);
791-
accountPools = await getAccountPools(account: widget.account);
801+
fingerprint = await getAccountFingerprint(account: widget.account, c: c);
802+
seed = await getAccountSeed(account: widget.account, c: c);
803+
accountPools = await getAccountPools(account: widget.account, c: c);
792804
setState(() {});
793805
});
794806
Future(() => onPoolChanged(pools));
@@ -835,7 +847,7 @@ class ViewingKeysPageState extends ConsumerState<ViewingKeysPage> {
835847
onPoolChanged(int? v) async {
836848
if (v == null) return;
837849
try {
838-
final uuvk = await getAccountUfvk(account: widget.account, pools: v);
850+
final uuvk = await getAccountUfvk(account: widget.account, pools: v, c: c);
839851
setState(() {
840852
pools = v;
841853
uvk = uuvk;

lib/pages/accounts.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class AccountListPage extends ConsumerStatefulWidget {
3131
}
3232

3333
class AccountListPageState extends ConsumerState<AccountListPage> with RouteAware {
34+
late final c = ref.read(coinContextProvider);
3435
var includeHidden = false;
3536
final listKey = GlobalKey<EditableListState<Account>>();
3637
double? price;
@@ -61,8 +62,8 @@ class AccountListPageState extends ConsumerState<AccountListPage> with RouteAwar
6162
@override
6263
void didPopNext() {
6364
WidgetsBinding.instance.addPostFrameCallback((_) {
64-
final selectedAccount = ref.read(selectedAccountProvider.notifier);
65-
selectedAccount.unselect();
65+
final c = ref.read(coinContextProvider.notifier);
66+
c.setAccount(account: 0);
6667
});
6768
super.didPopNext();
6869
}
@@ -71,7 +72,7 @@ class AccountListPageState extends ConsumerState<AccountListPage> with RouteAwar
7172
final settings = ref.read(appSettingsProvider).requireValue;
7273
if (settings.offline) return;
7374
try {
74-
final height = await getCurrentHeight();
75+
final height = await getCurrentHeight(c: c);
7576
final currentHeight = ref.read(currentHeightProvider.notifier);
7677
currentHeight.setHeight(height);
7778
if (fetchPrice) {
@@ -107,6 +108,7 @@ class AccountListPageState extends ConsumerState<AccountListPage> with RouteAwar
107108
final tt = Theme.of(context).textTheme;
108109
final t = tt.bodyMedium!.copyWith(fontFamily: "monospace");
109110

111+
final c = ref.read(coinContextProvider);
110112
final accounts = ref.watch(getAccountsProvider);
111113
final selectedFolder = ref.watch(selectedFolderProvider);
112114

@@ -168,7 +170,7 @@ class AccountListPageState extends ConsumerState<AccountListPage> with RouteAwar
168170
final confirmed = await confirmDialog(context, title: "Delete Account(s)", message: "Are you sure you want to delete these accounts?");
169171
if (confirmed) {
170172
for (var a in accounts) {
171-
await deleteAccount(account: a.id);
173+
await deleteAccount(account: a.id, c: c);
172174
}
173175
ref.invalidate(getAccountsProvider);
174176
}
@@ -262,15 +264,19 @@ class AccountListPageState extends ConsumerState<AccountListPage> with RouteAwar
262264
}
263265

264266
void onOpen(BuildContext context, Account account) async {
265-
final selectAccount = ref.read(selectedAccountProvider.notifier);
266-
selectAccount.selectAccount(account);
267+
final c = ref.read(coinContextProvider.notifier);
268+
await c.setAccount(account: account.id);
267269
if (!context.mounted) return;
268270
await GoRouter.of(context).push('/account', extra: account);
269271
}
270272

271273
void onReorder(int oldIndex, int newIndex) async {
272274
final listState = listKey.currentState!;
273-
await reorderAccount(oldPosition: listState.items[oldIndex].position, newPosition: listState.items[newIndex].position);
275+
await reorderAccount(
276+
oldPosition: listState.items[oldIndex].position,
277+
newPosition: listState.items[newIndex].position,
278+
c: c,
279+
);
274280
ref.invalidate(getAccountsProvider);
275281
}
276282

lib/pages/category.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class CategoryPage extends ConsumerStatefulWidget {
1414
}
1515

1616
class CategoryPageState extends ConsumerState<CategoryPage> {
17+
late final c = ref.read(coinContextProvider);
1718
List<(Category, bool)> categories = [];
1819

1920
@override
@@ -63,15 +64,15 @@ class CategoryPageState extends ConsumerState<CategoryPage> {
6364
void onNew() async {
6465
final category = await categoryForm(Category(id: 0, name: "", isIncome: false), title: "New Category");
6566
if (category != null) {
66-
await createNewCategory(category: category);
67+
await createNewCategory(category: category, c: c);
6768
await refresh();
6869
}
6970
}
7071

7172
void onEdit() async {
7273
final category = await categoryForm(selection.first, title: "Edit Category");
7374
if (category != null) {
74-
await renameCategory(category: category);
75+
await renameCategory(category: category, c: c);
7576
await refresh();
7677
}
7778
}
@@ -80,7 +81,7 @@ class CategoryPageState extends ConsumerState<CategoryPage> {
8081
final confirmed =
8182
await confirmDialog(context, title: "Do you want to delete these categories?", message: "Transactions assigned to these categories will be kept.");
8283
if (confirmed) {
83-
await deleteCategories(ids: selection.map((f) => f.id).toList());
84+
await deleteCategories(ids: selection.map((f) => f.id).toList(), c: c);
8485
await refresh();
8586
ref.invalidate(getCategoriesProvider);
8687
}

lib/pages/db.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ class DatabaseManagerState extends ConsumerState<DatabaseManagerPage> {
130130
if (res != null) {
131131
final (name, password) = res;
132132
final dbFilepath = await getFullDatabasePath(name);
133-
await openDatabase(dbFilepath: dbFilepath, password: password);
133+
final c = ref.read(coinContextProvider);
134+
final c2 = await c.openDatabase(dbFilepath: dbFilepath, password: password);
135+
ref.read(coinContextProvider.notifier).set(coin: c2);
134136
await refresh();
135137
}
136138
}

0 commit comments

Comments
 (0)