Skip to content

Commit

Permalink
Added more wallet information and Peek seed for Primary wallet. Also …
Browse files Browse the repository at this point in the history
…updated derived wallet kind to Primary.
  • Loading branch information
i5hi committed Oct 29, 2022
1 parent 09bcb12 commit 1ca990e
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 60 deletions.
2 changes: 1 addition & 1 deletion lib/cubit/new-wallet/from-master-key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MasterDeriveWalletCubit extends Cubit<MasterDeriveWalletState> {

static const invalidLabelError = 'Invalid Label (must be 3-20 chars)';
static const internalError = 'Internal Error';
static const signerWalletType = 'DERIVED';
static const signerWalletType = 'PRIMARY';
static const trScript = 'tr';
static const taprootPurpose = '86';
static const segwitScript = 'wpkh';
Expand Down
4 changes: 2 additions & 2 deletions lib/cubit/pin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ class PinCubit extends Cubit<PinState> {
);
}
} else {
final timePassed = ((now - state.lastFailure) / (1000)).round();
final timeLeft = 60 - ((now - state.lastFailure) / (1000)).round();
emit(
state.copyWith(
error: 'Locked! $timePassed seconds passed.',
error: 'Locked! $timeLeft seconds left.',
setValue: emptyString,
confirmedValue: emptyString,
hiddenValue: emptyString,
Expand Down
42 changes: 0 additions & 42 deletions lib/ui/component/Landing/Loader.dart

This file was deleted.

6 changes: 4 additions & 2 deletions lib/ui/component/NewWallet/MasterKeyDerive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class MasterDerivePurpose extends StatelessWidget {
var hasSegwit = false;
var hasTaproot = false;
for (final wallet in wallets) {
if (wallet.descriptor.startsWith('tr')) hasTaproot = true;
if (wallet.descriptor.startsWith('wpkh')) hasSegwit = true;
if (wallet.walletType == 'PRIMARY' && wallet.descriptor.startsWith('tr'))
hasTaproot = true;
if (wallet.walletType == 'PRIMARY' &&
wallet.descriptor.startsWith('wpkh')) hasSegwit = true;
}
final selectedPurpose =
c.select((MasterDeriveWalletCubit mdw) => mdw.state.purpose);
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/component/Send/Amount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class _AmountRowState extends State<AmountRow> {
state.errAmount,
)
}
else if (state.errFees != '')
{
handleError(
context,
state.errAmount,
)
}
},
child: BlocBuilder<SendCubit, SendState>(
builder: (context, state) {
Expand Down
127 changes: 126 additions & 1 deletion lib/ui/component/Wallet/KeyInfo.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,75 @@
import 'package:flutter/material.dart';
import 'package:sats/cubit/master.dart';
import 'package:sats/cubit/wallets.dart';
import 'package:sats/model/master.dart';
import 'package:sats/pkg/extensions.dart';
import 'package:sats/pkg/validation.dart';

class KeyInfo extends StatelessWidget {
const KeyInfo({Key? key}) : super(key: key);

@override
Widget build(BuildContext c) {
final wallet = c.select((WalletsCubit wc) => wc.state.selectedWallet!);
final masterKey = c.select((MasterKeyCubit mk) => mk.state.key);

return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'KEY INFORMATION',
'WALLET INFORMATION',
style: c.fonts.overline!.copyWith(
color: c.colours.onBackground,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 24),
Text(
'Kind',
style: c.fonts.overline!.copyWith(
color: c.colours.onBackground,
),
),
const SizedBox(height: 8),
Text(
wallet.walletType,
style: c.fonts.caption!.copyWith(
color: c.colours.onBackground,
),
),
const SizedBox(height: 24),
Text(
'Script Type',
style: c.fonts.overline!.copyWith(
color: c.colours.onBackground,
),
),
const SizedBox(height: 8),
Text(
wallet.descriptor.startsWith('w') ? 'SEGWIT' : 'TAPROOT',
style: c.fonts.caption!.copyWith(
color: c.colours.onBackground,
),
),
const SizedBox(height: 24),
Text(
'Fingerprint',
style: c.fonts.overline!.copyWith(
color: c.colours.onBackground,
),
),
const SizedBox(height: 8),
Text(
Validation.fingerPrintFromXKey(
wallet.policyElements[0].split(':')[1],
),
style: c.fonts.caption!.copyWith(
color: c.colours.onBackground,
),
),
const SizedBox(height: 24),
Text(
'Extended Public Key',
style: c.fonts.overline!.copyWith(
Expand All @@ -48,8 +96,85 @@ class KeyInfo extends StatelessWidget {
child: const Text('COPY'),
),
const SizedBox(height: 24),
if (wallet.walletType == 'PRIMARY')
SizedBox(
height: 52,
width: c.width,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
primary: c.colours.error,
onSurface: c.colours.background.withOpacity(0.38),
),
onPressed: () {
peekSeed(c, masterKey!);
},
child: Text('PEEK SEED'.toUpperCase()),
),
),
],
),
);
}
}

Future<void> peekSeed(BuildContext context, MasterKey key) async {
// final masterKey = context.select((MasterKeyCubit mk) => mk.state);

return showDialog<void>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
contentPadding: const EdgeInsets.all(24.0),
insetPadding: const EdgeInsets.all(24.0),
backgroundColor: context.colours.onPrimaryContainer,
elevation: 2.0,
title: Text(
'MNEMONIC\nSEED',
style: context.fonts.headline5!.copyWith(
fontWeight: FontWeight.bold,
color: context.colours.onPrimary,
),
),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(
key.seed!,
style: context.fonts.bodyMedium!.copyWith(
fontWeight: FontWeight.bold,
color: context.colours.onPrimary,
),
),
const SizedBox(height: 12),
if (key.hasPassphrase!) ...[
Text(
'This wallet also needs a passphrase to be recovered.',
style: context.fonts.bodyMedium!.copyWith(
fontWeight: FontWeight.bold,
color: context.colours.error,
),
),
const SizedBox(height: 12),
],
],
),
),
actions: <Widget>[
TextButton(
child: Text(
'Got it!',
style: context.fonts.bodyMedium!.copyWith(
fontWeight: FontWeight.bold,
color: context.colours.primary,
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
2 changes: 0 additions & 2 deletions lib/ui/screen/Landing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:sats/cubit/master.dart';
import 'package:sats/cubit/pin.dart';
import 'package:sats/pkg/extensions.dart';
import 'package:sats/ui/component/Landing/Keypad.dart';
import 'package:sats/ui/component/Landing/Loader.dart';
import 'package:sats/ui/component/Landing/Logo.dart';
import 'package:sats/ui/component/Landing/PinButton.dart';
import 'package:sats/ui/component/Landing/PinValue.dart';
Expand Down Expand Up @@ -53,7 +52,6 @@ class _Landing extends StatelessWidget {
background: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: const [
LandingLoader(),
SizedBox(height: 36),
LandingLogo(),
SizedBox(height: 12),
Expand Down
10 changes: 0 additions & 10 deletions lib/ui/screen/NewWallet/MasterKeyDerive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class _MasterDerive extends StatelessWidget {
builder: (context, state) {
return WillPopScope(
onWillPop: () async {
// if (!state.canGoBack()) {
// c.read<MasterDeriveWalletCubit>().backClicked();
// return false;
// }

return true;
},
child: Scaffold(
Expand All @@ -55,11 +50,6 @@ class _MasterDerive extends StatelessWidget {
children: [
Back(
onPressed: () {
// if (!state.canGoBack()) {
// c.read<MasterDeriveWalletCubit>().backClicked();
// return;
// }

Navigator.pop(c);
},
),
Expand Down

0 comments on commit 1ca990e

Please sign in to comment.