-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/local_storage_811
- Loading branch information
Showing
10 changed files
with
743 additions
and
70 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
aapt | ||
aarch | ||
abnf | ||
addr | ||
addrr | ||
adminer | ||
afinet | ||
|
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,253 @@ | ||
import 'package:catalyst_voices/widgets/widgets.dart'; | ||
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart'; | ||
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
class AccountPopup extends StatelessWidget { | ||
final String avatarLetter; | ||
final VoidCallback? onProfileKeychainTap; | ||
final VoidCallback? onLockAccountTap; | ||
|
||
const AccountPopup({ | ||
super.key, | ||
required this.avatarLetter, | ||
this.onProfileKeychainTap, | ||
this.onLockAccountTap, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PopupMenuButton<_MenuItemValue>( | ||
color: Theme.of(context).colors.elevationsOnSurfaceNeutralLv1White, | ||
onSelected: (_MenuItemValue value) { | ||
switch (value) { | ||
case _MenuItemValue.profileAndKeychain: | ||
onProfileKeychainTap?.call(); | ||
break; | ||
case _MenuItemValue.lock: | ||
onLockAccountTap?.call(); | ||
break; | ||
} | ||
}, | ||
itemBuilder: (BuildContext bc) { | ||
return [ | ||
PopupMenuItem( | ||
padding: EdgeInsets.zero, | ||
enabled: false, | ||
value: null, | ||
child: _Header( | ||
accountLetter: avatarLetter, | ||
walletName: 'Wallet name', | ||
walletBalance: '₳ 1,750,000', | ||
accountType: 'Basis', | ||
walletAddress: 'addr1_H4543...45GH', | ||
), | ||
), | ||
const PopupMenuItem( | ||
height: 48, | ||
padding: EdgeInsets.zero, | ||
enabled: false, | ||
value: null, | ||
child: _Section('My account'), | ||
), | ||
PopupMenuItem( | ||
padding: EdgeInsets.zero, | ||
value: _MenuItemValue.profileAndKeychain, | ||
child: _MenuItem( | ||
'Profile & Keychain', | ||
VoicesAssets.icons.userCircle, | ||
), | ||
), | ||
PopupMenuItem( | ||
padding: EdgeInsets.zero, | ||
value: _MenuItemValue.lock, | ||
child: _MenuItem( | ||
'Lock account', | ||
VoicesAssets.icons.lockClosed, | ||
showDivider: false, | ||
), | ||
), | ||
]; | ||
}, | ||
offset: const Offset(0, kToolbarHeight), | ||
child: IgnorePointer( | ||
child: VoicesAvatar( | ||
icon: Text(avatarLetter), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _Header extends StatelessWidget { | ||
final String accountLetter; | ||
final String walletName; | ||
final String walletBalance; | ||
final String accountType; | ||
final String walletAddress; | ||
|
||
const _Header({ | ||
required this.accountLetter, | ||
required this.walletName, | ||
required this.walletBalance, | ||
required this.accountType, | ||
required this.walletAddress, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: _padding), | ||
child: Row( | ||
children: [ | ||
VoicesAvatar( | ||
icon: Text(accountLetter), | ||
), | ||
Expanded( | ||
child: Padding( | ||
padding: const EdgeInsets.all(_padding), | ||
child: Wrap( | ||
children: [ | ||
Text( | ||
walletName, | ||
style: Theme.of(context).textTheme.bodyLarge, | ||
), | ||
Text( | ||
walletBalance, | ||
style: Theme.of(context).textTheme.bodyMedium, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
VoicesChip.rectangular( | ||
content: Text( | ||
accountType, | ||
style: TextStyle( | ||
color: Theme.of(context).colors.successContainer, | ||
), | ||
), | ||
backgroundColor: Theme.of(context).colors.success, | ||
), | ||
], | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only( | ||
left: _padding, | ||
right: _padding, | ||
bottom: _padding, | ||
top: 8, | ||
), | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
child: Text( | ||
walletAddress, | ||
style: Theme.of(context).textTheme.bodyLarge, | ||
), | ||
), | ||
InkWell( | ||
onTap: () async { | ||
await Clipboard.setData( | ||
ClipboardData(text: walletAddress), | ||
); | ||
}, | ||
child: VoicesAssets.icons.clipboardCopy.buildIcon(), | ||
), | ||
], | ||
), | ||
), | ||
VoicesDivider( | ||
height: 1, | ||
color: Theme.of(context).colors.outlineBorder, | ||
indent: 0, | ||
endIndent: 0, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class _MenuItem extends StatelessWidget { | ||
final String text; | ||
final SvgGenImage icon; | ||
final bool showDivider; | ||
|
||
const _MenuItem( | ||
this.text, | ||
this.icon, { | ||
this.showDivider = true, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Container( | ||
height: 47, | ||
alignment: Alignment.centerLeft, | ||
padding: const EdgeInsets.symmetric(horizontal: _padding), | ||
child: Row( | ||
children: [ | ||
icon.buildIcon(), | ||
const SizedBox(width: _padding), | ||
Text( | ||
text, | ||
style: Theme.of(context).textTheme.bodyLarge, | ||
), | ||
], | ||
), | ||
), | ||
if (showDivider) | ||
VoicesDivider( | ||
height: 1, | ||
color: Theme.of(context).colors.outlineBorderVariant, | ||
indent: 0, | ||
endIndent: 0, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class _Section extends StatelessWidget { | ||
final String text; | ||
|
||
const _Section( | ||
this.text, | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Container( | ||
height: 47, | ||
alignment: Alignment.centerLeft, | ||
padding: const EdgeInsets.symmetric(horizontal: _padding), | ||
child: Text( | ||
text, | ||
style: Theme.of(context).textTheme.titleSmall, | ||
), | ||
), | ||
VoicesDivider( | ||
height: 1, | ||
color: Theme.of(context).colors.outlineBorderVariant, | ||
indent: 0, | ||
endIndent: 0, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
const _padding = 12.0; | ||
|
||
enum _MenuItemValue { | ||
profileAndKeychain, | ||
lock, | ||
} |
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
70 changes: 70 additions & 0 deletions
70
catalyst_voices/packages/catalyst_voices_models/lib/src/seed_phrase.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,70 @@ | ||
// cspell: words wordlists WORDLIST | ||
// ignore_for_file: implementation_imports | ||
|
||
import 'dart:typed_data'; | ||
import 'package:bip39/bip39.dart' as bip39; | ||
import 'package:bip39/src/wordlists/english.dart'; | ||
import 'package:convert/convert.dart'; | ||
|
||
/// Represents a seed phrase consisting of a mnemonic and provides methods for | ||
/// generating and deriving cryptographic data from the mnemonic. | ||
/// | ||
/// The `SeedPhrase` class allows creation of a seed phrase either randomly, | ||
/// from a given mnemonic, or from entropy data. It supports converting between | ||
/// different formats, including Uint8List and hex strings. | ||
class SeedPhrase { | ||
/// The mnemonic phrase | ||
final String mnemonic; | ||
|
||
/// Generates a new seed phrase with a random mnemonic. | ||
/// | ||
/// Throws an [ArgumentError] if the word count is invalid. | ||
/// | ||
/// [wordCount]: The number of words in the mnemonic. | ||
/// The default word count is 12, but can specify 12, 15, 18, 21, or 24 words. | ||
/// with a higher word count providing greater entropy and security. | ||
SeedPhrase({int wordCount = 12}) | ||
: this.fromMnemonic( | ||
bip39.generateMnemonic( | ||
strength: (wordCount * 32) ~/ 3, | ||
), | ||
); | ||
|
||
/// Creates a SeedPhrase from an existing [Uint8List] entropy. | ||
/// | ||
/// [encodedData]: The entropy data as a Uint8List. | ||
SeedPhrase.fromUint8ListEntropy(Uint8List encodedData) | ||
: this.fromHexEntropy(hex.encode(encodedData)); | ||
|
||
/// Creates a SeedPhrase from an existing hex-encoded entropy. | ||
/// | ||
/// [encodedData]: The entropy data as a hex string. | ||
SeedPhrase.fromHexEntropy(String encodedData) | ||
: this.fromMnemonic(bip39.entropyToMnemonic(encodedData)); | ||
|
||
/// Creates a SeedPhrase from an existing [mnemonic]. | ||
/// | ||
/// Throws an [ArgumentError] if the mnemonic is invalid. | ||
/// | ||
/// [mnemonic]: The mnemonic to derive the seed from. | ||
SeedPhrase.fromMnemonic(this.mnemonic) | ||
: assert(bip39.validateMnemonic(mnemonic), 'Invalid mnemonic phrase'); | ||
|
||
/// The seed derived from the mnemonic as a Uint8List. | ||
Uint8List get uint8ListSeed => bip39.mnemonicToSeed(mnemonic); | ||
|
||
/// The seed derived from the mnemonic as a hex-encoded string. | ||
String get hexSeed => bip39.mnemonicToSeedHex(mnemonic); | ||
|
||
/// The entropy derived from the mnemonic as a Uint8List. | ||
Uint8List get uint8ListEntropy => Uint8List.fromList(hex.decode(hexEntropy)); | ||
|
||
/// The entropy derived from the mnemonic as a hex-encoded string. | ||
String get hexEntropy => bip39.mnemonicToEntropy(mnemonic); | ||
|
||
/// The mnemonic phrase as a list of individual words. | ||
List<String> get mnemonicWords => mnemonic.split(' '); | ||
|
||
/// The full list of BIP-39 mnemonic words in English. | ||
static List<String> get wordList => WORDLIST; | ||
} |
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
Oops, something went wrong.