Skip to content

Commit

Permalink
Merge pull request #18 from martinloesethjensen/feature/qr
Browse files Browse the repository at this point in the history
feature/qr
  • Loading branch information
martinloesethjensen authored Jun 10, 2021
2 parents 292947a + 065dd8b commit e8a147f
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 75 deletions.
2 changes: 1 addition & 1 deletion lib/screens/components/algorand/algorand_balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AlgorandBalance extends StatelessWidget {
SizedBox(
width: 16,
height: 16,
child: Image.asset("assets/images/algo_icon.png"),
child: Image.asset('assets/images/algo_icon.png'),
),
HorizontalSpacing(of: paddingSizeNormal),
Text(
Expand Down
51 changes: 51 additions & 0 deletions lib/screens/components/text_clip.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:flutter_algo_wallet/theme/theme.dart';

class TextClip extends StatelessWidget {
const TextClip({
Key? key,
required this.textToCopy,
this.snackBarText,
}) : super(key: key);

final String textToCopy;
final String? snackBarText;

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () async {
await FlutterClipboard.copy(textToCopy);

if (snackBarText != null) {
final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
content: Text(snackBarText!),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
},
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: textToCopy,
style: regularTextStyle.copyWith(fontSize: fontSizeSmall),
),
WidgetSpan(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(
Icons.copy,
size: 20,
),
),
),
],
),
),
);
}
}
6 changes: 2 additions & 4 deletions lib/screens/components/wallet/loaded_wallet_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:algorand_dart/algorand_dart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_algo_wallet/global_providers/account/account_provider.dart';
import 'package:flutter_algo_wallet/screens/components/algorand/algorand_balance.dart';
import 'package:flutter_algo_wallet/screens/components/wallet/recieve_widget.dart';
import 'package:flutter_algo_wallet/theme/theme.dart';
import 'package:flutter_algo_wallet/widgets/spacing.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -58,10 +59,7 @@ class LoadedWalletWidget extends StatelessWidget {
),
HorizontalSpacing(of: paddingSizeNormal),
Expanded(
child: ElevatedButton(
onPressed: () {},
child: Text('Recieve'),
),
child: RecieveWidget(account: account),
),
],
),
Expand Down
62 changes: 62 additions & 0 deletions lib/screens/components/wallet/recieve_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'package:algorand_dart/algorand_dart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_algo_wallet/screens/components/text_clip.dart';
import 'package:flutter_algo_wallet/theme/dimens.dart';
import 'package:flutter_algo_wallet/widgets/spacing.dart';
import 'package:qr_flutter/qr_flutter.dart';

class RecieveWidget extends StatelessWidget {
const RecieveWidget({
Key? key,
required this.account,
}) : super(key: key);

final Account account;

@override
Widget build(BuildContext context) {
return ElevatedButton(
child: Text('Recieve'),
onPressed: () {
showModalBottomSheet<void>(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(20),
),
),
context: context,
builder: (BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(paddingSizeDefault),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
QrImage(
data:
'https://testnet.algoexplorer.io/address/${account.publicAddress}',
version: QrVersions.auto,
size: 250,
gapless: false,
embeddedImage: AssetImage('assets/images/algo_icon.png'),
embeddedImageStyle: QrEmbeddedImageStyle(
size: Size(80, 80),
),
),
const VerticalSpacing(of: marginSizeDefault),
TextClip(textToCopy: account.publicAddress),
const VerticalSpacing(of: marginSizeDefault),
ElevatedButton(
child: const Text('Close'),
onPressed: () => Navigator.pop(context),
),
],
),
),
);
},
);
},
);
}
}
61 changes: 60 additions & 1 deletion lib/screens/components/wallet/wallet_widget.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:algorand_dart/algorand_dart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_algo_wallet/bottom_navbar/bottom_navbar_provider.dart';
import 'package:flutter_algo_wallet/global_providers/account/account_provider.dart';
import 'package:flutter_algo_wallet/screens/dashboard/dashboard_screen_provider.dart';
import 'package:flutter_algo_wallet/theme/theme.dart';
Expand All @@ -16,6 +17,7 @@ class WalletWidget extends StatelessWidget {
final algorand = context.watch<Algorand>();
final dashboardScreenMode = context.watch<DashboardScreenModeProvider>();
final account = context.watch<AccountProvider>();
final navBarProvider = context.watch<BottomNavigationBarProvider>();

return Padding(
padding: const EdgeInsets.all(paddingSizeDefault),
Expand All @@ -37,6 +39,11 @@ class WalletWidget extends StatelessWidget {
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);

// If we create a new wallet from the wallet tab (1) then we should navigate to the dashboard
if (navBarProvider.currentIndex != 0) {
navBarProvider.currentIndex = 0;
}
},
child: Text('Create a new wallet'),
style: ButtonStyle(
Expand All @@ -50,7 +57,25 @@ class WalletWidget extends StatelessWidget {
message: 'Currently unavailable!',
child: ElevatedButton(
key: Key('IMPORT_WALLET_BUTTON'),
onPressed: null, // TODO
onPressed: () async {
final restoredAccount =
await Account.fromSeedPhrase(seedPhrase);
account.account = restoredAccount;
dashboardScreenMode.currentWalletStatus =
DashboardScreenMode.LOADED_WALLET;

final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
content: Text('Imported test wallet.'),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);

// If we import a wallet from the wallet tab (1) then we should navigate to the dashboard
if (navBarProvider.currentIndex != 0) {
navBarProvider.currentIndex = 0;
}
},
child: Text('Import existing wallet'),
style: ButtonStyle(
fixedSize: MaterialStateProperty.all<Size>(
Expand All @@ -64,3 +89,37 @@ class WalletWidget extends StatelessWidget {
);
}
}

// TODO: Just for testing
// Random Algorand public address
final publicAddress =
'D3ZUVRXN2KN44O6Z335HI6SOY7WLQW3RNP7HPGTAXBKZWPWKKOZDKJJT5Q';

// Random Algorand seed phrase
final seedPhrase = <String>[
'certain',
'social',
'kidney',
'magic',
'special',
'replace',
'genuine',
'meadow',
'pulse',
'tennis',
'unable',
'obey',
'urban',
'clerk',
'domain',
'sock',
'belt',
'slam',
'hybrid',
'tank',
'lumber',
'reason',
'canvas',
'about',
'wink'
];
79 changes: 10 additions & 69 deletions lib/screens/profile/profile.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:flutter_algo_wallet/global_providers/account/account_provider.dart';
import 'package:flutter_algo_wallet/screens/components/text_clip.dart';
import 'package:flutter_algo_wallet/screens/components/wallet/wallet_widget.dart';
import 'package:flutter_algo_wallet/screens/dashboard/dashboard_screen_provider.dart';
import 'package:flutter_algo_wallet/widgets/spacing.dart';
import 'package:url_launcher/url_launcher.dart';
Expand All @@ -16,14 +17,10 @@ class ProfileScreen extends StatelessWidget {
Widget build(BuildContext context) {
final dashboardProvider = context.watch<DashboardScreenModeProvider>();

// If a wallet has not been loaded then we should show the wallet.
if (dashboardProvider.currentWalletStatus !=
DashboardScreenMode.LOADED_WALLET) {
// TODO: WIDGET TEST THIS
return Container(
child: Center(
child: Text('No account created or wallet'),
),
);
return WalletWidget();
}

final accountProvider = context.watch<AccountProvider>();
Expand All @@ -40,36 +37,9 @@ class ProfileScreen extends StatelessWidget {
style: boldTextStyle.copyWith(fontSize: fontSizeMedium),
),
const VerticalSpacing(of: marginSizeSmall),
GestureDetector(
onTap: () async {
await FlutterClipboard.copy(account.publicAddress);

final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
content: Text('Algorand address copied to clipboard'),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: account.publicAddress,
style: regularTextStyle.copyWith(fontSize: fontSizeSmall),
),
WidgetSpan(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(
Icons.copy,
size: 20,
),
),
),
],
),
),
TextClip(
textToCopy: account.publicAddress,
snackBarText: 'Algorand address copied to clipboard',
),

const VerticalSpacing(of: marginSizeDefault),
Expand All @@ -87,38 +57,9 @@ class ProfileScreen extends StatelessWidget {
if (!snapshot.hasData) return CircularProgressIndicator();

final seedPhrase = (snapshot.data ?? <String>[]).join(' ');
return GestureDetector(
onTap: () async {
await FlutterClipboard.copy(seedPhrase);

final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
content: Text('Word list copied to clipboard'),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: seedPhrase,
style: regularTextStyle.copyWith(
fontSize: fontSizeSmall),
),
WidgetSpan(
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(
Icons.copy,
size: 20,
),
),
),
],
),
),
return TextClip(
textToCopy: seedPhrase,
snackBarText: 'Word list copied to clipboard',
);
}),

Expand Down

0 comments on commit e8a147f

Please sign in to comment.