fix payments
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:auth/src/features/device_setup/presentation/device_setup_screen.dart';
|
||||
import 'package:auth/src/features/device_setup/presentation/state/device_setup_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:navigation/navigation.dart';
|
||||
@@ -8,6 +10,9 @@ class DeviceSetupBuilder {
|
||||
const DeviceSetupBuilder();
|
||||
|
||||
Page<void> buildPage(BuildContext context, GoRouterState state) {
|
||||
final container = ProviderScope.containerOf(context);
|
||||
container.invalidate(deviceSetupViewModelProvider);
|
||||
|
||||
final NavigationContract navigationContract = GetIt.I<NavigationContract>();
|
||||
|
||||
return MaterialPage<void>(
|
||||
|
||||
@@ -198,6 +198,8 @@ class DeviceSetupViewModel extends Notifier<DeviceSetupViewState> {
|
||||
|
||||
if (!ref.mounted) return false;
|
||||
|
||||
ref.invalidate(childProfilesProvider);
|
||||
ref.read(walletRefreshProvider.notifier).refresh();
|
||||
state = state.copyWith(isLoading: false, isSuccess: true);
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -391,6 +393,9 @@ class DeviceSetupViewModel extends Notifier<DeviceSetupViewState> {
|
||||
// utf8.encode(jsonEncode({'url': url, 'body': {}})),
|
||||
// );
|
||||
|
||||
final connectionService = GetIt.I<TreezorWalletConnectionService>();
|
||||
await connectionService.connectWithPin(loginPin: state.pin);
|
||||
|
||||
final jws = await _signatureService.generateJwsWithPin(
|
||||
message: '',
|
||||
input: jsonEncode({'url': url, 'body': {}}),
|
||||
|
||||
@@ -57,29 +57,13 @@ class SCATreezorViewModel extends Notifier<SCATreezorViewState> {
|
||||
}
|
||||
|
||||
Future<void> _bootstrap() async {
|
||||
final alreadyProvisioned = await _sessionLocal.isProvisioned();
|
||||
final firstConnectionDone = await _sessionLocal.isFirstConnectionDone();
|
||||
|
||||
final needsProvisioning = await _checkBackendWalletStatus();
|
||||
if (!ref.mounted) return;
|
||||
|
||||
if (alreadyProvisioned) {
|
||||
final needsReprovisioning = await _checkBackendWalletStatus();
|
||||
if (!needsProvisioning) {
|
||||
final firstConnectionDone = await _sessionLocal.isFirstConnectionDone();
|
||||
if (!ref.mounted) return;
|
||||
|
||||
if (needsReprovisioning) {
|
||||
await _loadActivationCode();
|
||||
if (!ref.mounted) return;
|
||||
|
||||
final code = state.activationCode.trim();
|
||||
if (code.isEmpty) {
|
||||
state = state.copyWith(process: ScaProcess.idle);
|
||||
return;
|
||||
}
|
||||
|
||||
await _provisionWallet();
|
||||
return;
|
||||
}
|
||||
|
||||
state = state.copyWith(
|
||||
process: ScaProcess.idle,
|
||||
isProvisioned: true,
|
||||
@@ -89,6 +73,11 @@ class SCATreezorViewModel extends Notifier<SCATreezorViewState> {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await _connectionService.deleteResidualWallet();
|
||||
} catch (_) {}
|
||||
if (!ref.mounted) return;
|
||||
|
||||
await _loadActivationCode();
|
||||
if (!ref.mounted) return;
|
||||
|
||||
@@ -109,7 +98,11 @@ class SCATreezorViewModel extends Notifier<SCATreezorViewState> {
|
||||
|
||||
final hasActiveWallet = wallets.any((w) => w.status == 'ACTIVE');
|
||||
final nonDeleted = wallets.where((w) => w.status != 'DELETED').toList();
|
||||
if (hasActiveWallet) return false;
|
||||
if (hasActiveWallet) {
|
||||
await _sessionLocal.setProvisioned(true);
|
||||
await _sessionLocal.setFirstConnectionDone(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// No active wallet — delete non-deleted ones and re-provision
|
||||
for (final wallet in nonDeleted) {
|
||||
|
||||
@@ -65,5 +65,17 @@ class TreezorWalletConnectionService {
|
||||
Future<void> logout() async {
|
||||
final walletManager = _bridge.getWalletManagerModule();
|
||||
await walletManager.logout();
|
||||
await walletManager.delete();
|
||||
await walletManager.clean();
|
||||
}
|
||||
|
||||
Future<void> deleteResidualWallet() async {
|
||||
final walletManager = _bridge.getWalletManagerModule();
|
||||
await walletManager.initialize(WalletManagerCallbacks());
|
||||
try {
|
||||
await walletManager.delete();
|
||||
} finally {
|
||||
await walletManager.clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user