-
Notifications
You must be signed in to change notification settings - Fork 12
Birthday #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Birthday #243
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
46fcde1
feat: Replace default birthday in block height with Date
Sosthene00 0d40544
feat: new mempool api methods for blocks
Sosthene00 76c8b76
feat: Add `getBlockHeightFromDate` in `chain_state`
Sosthene00 fd7afb6
feat: Add extensions for `DateTime` and `int`
Sosthene00 0c08ce9
feat: store wallet birthday as timestamp instead of block height
Sosthene00 28da5cd
feat: make lastScan nullable with lazy resolution from birthday
Sosthene00 d3ed651
feat: Ask user for birthday on wallet restoration
Sosthene00 5c6062c
dependencies: Add `intl` package for Date formatting
Sosthene00 8a3b437
feat: Display wallet birthday as human readable date on seed phrase s…
Sosthene00 2c55de4
feat: add a minimum allowed birthday
cygnet3 b6a19b5
refactor(walletState): make birthday non-nullable
cygnet3 df68083
refactor: set lastScan to current block height on wallet creation
cygnet3 45ca77b
fix: add `_isLoading` bool to display a spinner on `seed_phrase` whil…
Sosthene00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,20 @@ | ||
| /// Response from mempool.space `/v1/mining/blocks/timestamp/{timestamp}` API. | ||
| class MempoolBlockTimestampResponse { | ||
| final int height; | ||
| final String hash; | ||
| final String timestamp; | ||
|
|
||
| const MempoolBlockTimestampResponse({ | ||
| required this.height, | ||
| required this.hash, | ||
| required this.timestamp, | ||
| }); | ||
|
|
||
| factory MempoolBlockTimestampResponse.fromJson(Map<String, dynamic> json) { | ||
| return MempoolBlockTimestampResponse( | ||
| height: json['height'] as int, | ||
| hash: json['hash'] as String, | ||
| timestamp: json['timestamp'] as String, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,49 @@ | ||
| class MempoolGetBlockResponse { | ||
| final String id; | ||
| final int height; | ||
| final int version; | ||
| final int timestamp; | ||
| final int txCount; | ||
| final int size; | ||
| final int weight; | ||
| final String merkleRoot; | ||
| final String previousblockhash; | ||
| final int mediantime; | ||
| final int nonce; | ||
| final int bits; | ||
| final double difficulty; | ||
|
|
||
| const MempoolGetBlockResponse({ | ||
| required this.id, | ||
| required this.height, | ||
| required this.version, | ||
| required this.timestamp, | ||
| required this.txCount, | ||
| required this.size, | ||
| required this.weight, | ||
| required this.merkleRoot, | ||
| required this.previousblockhash, | ||
| required this.mediantime, | ||
| required this.nonce, | ||
| required this.bits, | ||
| required this.difficulty, | ||
| }); | ||
|
|
||
| factory MempoolGetBlockResponse.fromJson(Map<String, dynamic> json) { | ||
| return MempoolGetBlockResponse( | ||
| id: json['id'] as String, | ||
| height: json['height'] as int, | ||
| version: json['version'] as int, | ||
| timestamp: json['timestamp'] as int, | ||
| txCount: json['tx_count'] as int, | ||
| size: json['size'] as int, | ||
| weight: json['weight'] as int, | ||
| merkleRoot: json['merkle_root'] as String, | ||
| previousblockhash: json['previousblockhash'] as String, | ||
| mediantime: json['mediantime'] as int, | ||
| nonce: json['nonce'] as int, | ||
| bits: json['bits'] as int, | ||
| difficulty: (json['difficulty'] as num).toDouble(), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| extension DateTimeExtension on DateTime { | ||
| int toSeconds() => millisecondsSinceEpoch ~/ 1000; | ||
| } | ||
|
|
||
| extension TimestampExtension on int { | ||
| DateTime toDate() { | ||
| const max32BitUnsigned = 4294967295; // 2^32 - 1 | ||
|
|
||
| if (this < 0) { | ||
| throw ArgumentError( | ||
| 'Timestamp cannot be negative: $this', | ||
| ); | ||
| } | ||
|
|
||
| if (this > max32BitUnsigned) { | ||
| throw ArgumentError( | ||
| 'Timestamp exceeds 32-bit unsigned int range: $this. Maximum value is $max32BitUnsigned', | ||
| ); | ||
| } | ||
|
|
||
| return DateTime.fromMillisecondsSinceEpoch(this * 1000, isUtc: true); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
74 changes: 74 additions & 0 deletions
74
lib/screens/onboarding/recovery/birthday_picker_screen.dart
This file contains hidden or 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,74 @@ | ||
| import 'package:auto_size_text/auto_size_text.dart'; | ||
| import 'package:bitcoin_ui/bitcoin_ui.dart'; | ||
| import 'package:danawallet/constants.dart'; | ||
| import 'package:danawallet/widgets/buttons/footer/footer_button.dart'; | ||
| import 'package:danawallet/widgets/skeletons/screen_skeleton.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// Screen for selecting the wallet creation date (birthday). | ||
| /// Returns the selected [DateTime] when user confirms, or null if user goes back. | ||
| class BirthdayPickerScreen extends StatefulWidget { | ||
| const BirthdayPickerScreen({super.key}); | ||
|
|
||
| @override | ||
| State<BirthdayPickerScreen> createState() => _BirthdayPickerScreenState(); | ||
| } | ||
|
|
||
| class _BirthdayPickerScreenState extends State<BirthdayPickerScreen> { | ||
| late DateTime _selectedDate; | ||
|
|
||
| @override | ||
| void initState() { | ||
| super.initState(); | ||
| // Use UTC to avoid timezone issues with calendar dates | ||
| final now = DateTime.now().toUtc(); | ||
| _selectedDate = DateTime.utc(now.year, now.month, now.day); | ||
| } | ||
|
|
||
| void _onConfirm() { | ||
| Navigator.of(context).pop(_selectedDate); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final subtitle = AutoSizeText( | ||
| "Choose the date when your wallet was created. This will make restoration faster.", | ||
| style: BitcoinTextStyle.body3(Bitcoin.neutral7).copyWith( | ||
| fontFamily: 'Inter', | ||
| ), | ||
| textAlign: TextAlign.center, | ||
| maxLines: 3, | ||
| ); | ||
|
|
||
| final body = Column( | ||
| children: [ | ||
| Padding( | ||
| padding: const EdgeInsets.only(bottom: 16), | ||
| child: subtitle, | ||
| ), | ||
| Expanded( | ||
| child: SingleChildScrollView( | ||
| child: CalendarDatePicker( | ||
| initialDate: _selectedDate, | ||
| firstDate: minimumAllowedBirthday, | ||
| lastDate: DateTime.now().toUtc(), | ||
| currentDate: DateTime.now().toUtc(), | ||
| onDateChanged: (date) { | ||
| setState(() { | ||
| _selectedDate = date; | ||
| }); | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ); | ||
|
|
||
| return ScreenSkeleton( | ||
| title: "Select wallet birthday", | ||
| showBackButton: true, | ||
| body: body, | ||
| footer: FooterButton(title: "Continue", onPressed: _onConfirm), | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.