-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor project into different features, each feature having models, screens and controllers.
- Loading branch information
Showing
13 changed files
with
434 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:bitcoin_ui/bitcoin_ui.dart'; | ||
import 'package:donationwallet/features/wallet/screens/wallet_screen.dart'; | ||
import 'package:donationwallet/features/settings/screens/settings_screen.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class HomeScreen extends StatefulWidget { | ||
const HomeScreen({super.key}); | ||
|
||
@override | ||
HomeScreenState createState() => HomeScreenState(); | ||
} | ||
|
||
class HomeScreenState extends State<HomeScreen> { | ||
int _selectedIndex = 0; | ||
final List<Widget> _widgetOptions = [ | ||
const WalletScreen(), | ||
const SettingsScreen(), | ||
]; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
} | ||
|
||
void _onItemTapped(int index) { | ||
setState(() { | ||
_selectedIndex = index; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Silent Payments'), | ||
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | ||
), | ||
body: IndexedStack( | ||
index: _selectedIndex, | ||
children: _widgetOptions, | ||
), | ||
bottomNavigationBar: BottomNavigationBar( | ||
items: <BottomNavigationBarItem>[ | ||
BottomNavigationBarItem( | ||
icon: Image( | ||
image: | ||
const AssetImage("icons/wallet.png", package: "bitcoin_ui"), | ||
color: Bitcoin.neutral3Dark), | ||
label: 'Wallet', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Image( | ||
image: | ||
const AssetImage("icons/gear.png", package: "bitcoin_ui"), | ||
color: Bitcoin.neutral3Dark), | ||
label: 'Settings', | ||
), | ||
], | ||
currentIndex: _selectedIndex, | ||
selectedItemColor: Colors.green, | ||
onTap: _onItemTapped, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:bitcoin_ui/bitcoin_ui.dart'; | ||
import 'package:donationwallet/features/settings/controllers/settings_controller.dart'; | ||
import 'package:donationwallet/features/setup/screens/setup_wallet_screen.dart'; | ||
import 'package:donationwallet/utils/global_functions.dart'; | ||
import 'package:donationwallet/features/home/home_screen.dart'; | ||
import 'package:donationwallet/features/wallet/models/wallet_state.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class SettingsScreen extends StatelessWidget { | ||
final settingsController = const SettingsController(); | ||
|
||
const SettingsScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
children: [ | ||
BitcoinButtonOutlined( | ||
title: 'Show seed phrase', | ||
onPressed: () async { | ||
final walletState = | ||
Provider.of<WalletState>(context, listen: false); | ||
|
||
const title = 'Backup seed phrase'; | ||
final text = await settingsController.getSeedPhrase(walletState) ?? | ||
'Seed phrase unknown! Did you import from keys?'; | ||
|
||
showAlertDialog(title, text); | ||
}, | ||
), | ||
BitcoinButtonOutlined( | ||
title: 'Set wallet birthday', | ||
onPressed: () async { | ||
final controller = TextEditingController(); | ||
await settingsController.setBirthday(context, controller, | ||
(Exception? e) async { | ||
if (e != null) { | ||
throw e; | ||
} else { | ||
Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => const HomeScreen())); | ||
} | ||
}); | ||
}, | ||
), | ||
BitcoinButtonOutlined( | ||
title: 'Wipe wallet', | ||
onPressed: () async { | ||
final walletState = | ||
Provider.of<WalletState>(context, listen: false); | ||
await settingsController.removeWallet(walletState, | ||
(Exception? e) async { | ||
if (e != null) { | ||
throw e; | ||
} else { | ||
Navigator.pushAndRemoveUntil( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => const SetupWalletScreen()), | ||
(Route<dynamic> route) => false, | ||
); | ||
} | ||
}); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
lib/features/wallet/controllers/synchronization_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'dart:async'; | ||
import 'package:donationwallet/utils/global_functions.dart'; | ||
import 'package:donationwallet/rust/api/simple.dart'; | ||
|
||
class SynchronizationService { | ||
Timer? _timer; | ||
final Duration _interval = const Duration(minutes: 10); | ||
|
||
void startSyncTimer() { | ||
_scheduleNextTask(); | ||
} | ||
|
||
void _scheduleNextTask() async { | ||
_timer?.cancel(); | ||
await performSynchronizationTask(); | ||
_timer = Timer(_interval, () async { | ||
_scheduleNextTask(); | ||
}); | ||
} | ||
|
||
Future<void> performSynchronizationTask() async { | ||
try { | ||
await syncBlockchain(); | ||
} catch (e) { | ||
displayNotification(e.toString()); | ||
} | ||
} | ||
|
||
void stopSyncTimer() { | ||
_timer?.cancel(); | ||
} | ||
} |
Oops, something went wrong.