Skip to content

Commit 4886e43

Browse files
committed
Merge branch 'dev' into pr
2 parents a67bc6b + 8193ddb commit 4886e43

Some content is hidden

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

58 files changed

+1059
-573
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ lib/**/*.freezed.dart
5757

5858
# Wallet precomputed table
5959
precomputed_tables_26.bin
60+
61+
# Web wallet wasm
62+
web/pkg

Diff for: .metadata

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: "ba393198430278b6595976de84fe170f553cc728"
7+
revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49"
88
channel: "stable"
99

1010
project_type: app
@@ -13,11 +13,11 @@ project_type: app
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: ba393198430278b6595976de84fe170f553cc728
17-
base_revision: ba393198430278b6595976de84fe170f553cc728
18-
- platform: macos
19-
create_revision: ba393198430278b6595976de84fe170f553cc728
20-
base_revision: ba393198430278b6595976de84fe170f553cc728
16+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
17+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
18+
- platform: web
19+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
20+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
2121

2222
# User provided section
2323

Diff for: assets/bg_dots.png

-365 KB
Loading

Diff for: assets/bg_dots_original.png

762 KB
Loading

Diff for: justfile

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ rust:
2424
prep:
2525
cargo install 'flutter_rust_bridge_codegen@^2.0.0-dev'
2626
cd rust && cargo update
27+
28+
serve_web:
29+
flutter_rust_bridge_serve --crate rust --features="network_handler" --no-default-features

Diff for: lib/features/authentication/application/authentication_service.dart

+54-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:io';
22

3+
import 'package:flutter/foundation.dart';
34
import 'package:genesix/rust_bridge/api/table_generation.dart';
4-
import 'package:path_provider/path_provider.dart';
55
import 'package:riverpod_annotation/riverpod_annotation.dart';
66
import 'package:genesix/features/authentication/application/wallets_state_provider.dart';
77
import 'package:genesix/features/router/route_utils.dart';
@@ -11,6 +11,8 @@ import 'package:genesix/features/settings/application/settings_state_provider.da
1111
import 'package:genesix/features/wallet/application/wallet_provider.dart';
1212
import 'package:genesix/features/wallet/data/native_wallet_repository.dart';
1313
import 'package:genesix/shared/utils/utils.dart';
14+
import 'package:localstorage/localstorage.dart';
15+
import 'package:genesix/shared/logger.dart';
1416

1517
part 'authentication_service.g.dart';
1618

@@ -29,33 +31,55 @@ class Authentication extends _$Authentication {
2931
final precomputedTablesPath = await _getPrecomputedTablesPath();
3032
final settings = ref.read(settingsProvider);
3133
var walletPath = await getWalletPath(settings.network, name);
32-
var walletExists = await Directory(walletPath).exists();
34+
35+
var walletExists = false;
36+
if (kIsWeb) {
37+
var path = localStorage.getItem(walletPath);
38+
walletExists = path != null;
39+
} else {
40+
walletExists = await Directory(walletPath).exists();
41+
}
3342

3443
if (walletExists) {
3544
throw Exception('This wallet already exists: $name');
3645
} else {
3746
NativeWalletRepository walletRepository;
3847

48+
// remove prefix for rust call because it's already appended
49+
var dbName = walletPath.replaceFirst(localStorageDBPrefix, "");
3950
if (seed != null) {
4051
walletRepository = await NativeWalletRepository.recover(
41-
walletPath, password, settings.network,
52+
dbName, password, settings.network,
4253
seed: seed, precomputeTablesPath: precomputedTablesPath);
4354
} else {
4455
walletRepository = await NativeWalletRepository.create(
45-
walletPath, password, settings.network,
56+
dbName, password, settings.network,
4657
precomputeTablesPath: precomputedTablesPath);
4758
}
4859

4960
ref
5061
.read(walletsProvider.notifier)
5162
.setWalletAddress(name, walletRepository.address);
5263

53-
ref.read(routerProvider).go(AppScreen.wallet.toPath);
54-
5564
state = AuthenticationState.signedIn(
5665
name: name, nativeWallet: walletRepository);
5766

58-
ref.read(walletStateProvider.notifier).connect();
67+
ref.read(routerProvider).go(AuthAppScreen.wallet.toPath);
68+
69+
try {
70+
ref.read(walletStateProvider.notifier).connect();
71+
} finally {
72+
// continue... it's ok if we can't connect
73+
// the connect() func displays an error message
74+
}
75+
76+
if (seed == null) {
77+
final seed = await walletRepository.getSeed();
78+
79+
ref
80+
.read(routerProvider)
81+
.push(AuthAppScreen.walletSeedDialog.toPath, extra: seed);
82+
}
5983
}
6084
}
6185

@@ -64,13 +88,21 @@ class Authentication extends _$Authentication {
6488
final precomputedTablesPath = await _getPrecomputedTablesPath();
6589

6690
var walletPath = await getWalletPath(settings.network, name);
67-
var walletExists = await Directory(walletPath).exists();
91+
92+
var walletExists = false;
93+
if (kIsWeb) {
94+
var path = localStorage.getItem(walletPath);
95+
walletExists = path != null;
96+
} else {
97+
walletExists = await Directory(walletPath).exists();
98+
}
6899

69100
if (walletExists) {
70101
NativeWalletRepository walletRepository;
102+
var dbName = walletPath.replaceFirst(localStorageDBPrefix, "");
71103
try {
72104
walletRepository = await NativeWalletRepository.open(
73-
walletPath, password, settings.network,
105+
dbName, password, settings.network,
74106
precomputeTablesPath: precomputedTablesPath);
75107
} catch (e) {
76108
rethrow;
@@ -83,7 +115,7 @@ class Authentication extends _$Authentication {
83115
state = AuthenticationState.signedIn(
84116
name: name, nativeWallet: walletRepository);
85117

86-
ref.read(routerProvider).go(AppScreen.wallet.toPath);
118+
ref.read(routerProvider).go(AuthAppScreen.wallet.toPath);
87119

88120
ref.read(walletStateProvider.notifier).connect();
89121
} else {
@@ -106,12 +138,20 @@ class Authentication extends _$Authentication {
106138
}
107139

108140
Future<String> _getPrecomputedTablesPath() async {
109-
final dir = await getApplicationCacheDirectory();
110-
return "${dir.path}/";
141+
if (kIsWeb) {
142+
return "";
143+
} else {
144+
final dir = await getAppCacheDirPath();
145+
return "$dir/";
146+
}
111147
}
112148

113149
Future<bool> isPrecomputedTablesExists() async {
114-
return precomputedTablesExist(
115-
precomputedTablesPath: await _getPrecomputedTablesPath());
150+
if (kIsWeb) {
151+
return true;
152+
} else {
153+
return precomputedTablesExist(
154+
precomputedTablesPath: await _getPrecomputedTablesPath());
155+
}
116156
}
117157
}

0 commit comments

Comments
 (0)