2021-12-23 12:36:09 +01:00
|
|
|
import 'dart:async';
|
2022-05-28 19:13:30 +02:00
|
|
|
import 'dart:io';
|
2022-06-17 01:13:14 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-01-28 15:26:26 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-03-21 23:04:11 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2022-08-23 00:25:16 +02:00
|
|
|
import 'package:gecko/models/widgets_keys.dart';
|
2022-06-14 21:55:33 +02:00
|
|
|
import 'package:gecko/providers/duniter_indexer.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
2021-11-14 19:21:20 +01:00
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
2022-05-27 08:54:29 +02:00
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/wallet_options.dart';
|
|
|
|
import 'package:gecko/providers/wallets_profiles.dart';
|
2022-12-02 06:58:18 +01:00
|
|
|
import 'package:gecko/screens/certifications.dart';
|
2022-06-12 18:03:17 +02:00
|
|
|
import 'package:gecko/screens/common_elements.dart';
|
2022-06-16 02:43:30 +02:00
|
|
|
import 'package:gecko/screens/activity.dart';
|
2022-06-05 02:22:22 +02:00
|
|
|
import 'package:gecko/screens/myWallets/manage_membership.dart';
|
|
|
|
import 'package:gecko/screens/qrcode_fullscreen.dart';
|
2022-12-06 04:33:10 +01:00
|
|
|
import 'package:gecko/widgets/balance.dart';
|
2022-12-07 23:10:28 +01:00
|
|
|
import 'package:gecko/widgets/bottom_app_bar.dart';
|
2022-12-06 04:33:10 +01:00
|
|
|
import 'package:gecko/widgets/certifications.dart';
|
2022-12-06 03:35:35 +01:00
|
|
|
import 'package:gecko/widgets/idty_status.dart';
|
2022-12-06 22:33:42 +01:00
|
|
|
import 'package:gecko/widgets/name_by_address.dart';
|
2022-12-02 06:58:18 +01:00
|
|
|
import 'package:gecko/widgets/page_route_no_transition.dart';
|
2021-01-28 15:26:26 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2021-12-20 21:33:03 +01:00
|
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
2021-01-28 15:26:26 +01:00
|
|
|
|
2021-03-28 21:37:12 +02:00
|
|
|
class WalletOptions extends StatelessWidget {
|
2021-12-23 21:44:24 +01:00
|
|
|
const WalletOptions({Key? keyMyWallets, required this.wallet})
|
2021-01-28 15:26:26 +01:00
|
|
|
: super(key: keyMyWallets);
|
2021-12-23 21:44:24 +01:00
|
|
|
final WalletData wallet;
|
2021-01-28 15:26:26 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final walletOptions =
|
2021-12-01 08:14:07 +01:00
|
|
|
Provider.of<WalletOptionsProvider>(context, listen: false);
|
2022-08-06 02:22:41 +02:00
|
|
|
WalletsProfilesProvider historyProvider =
|
2021-12-02 07:57:05 +01:00
|
|
|
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
2022-11-30 05:42:08 +01:00
|
|
|
final myWalletProvider =
|
2022-06-05 02:22:22 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
2022-11-30 05:42:08 +01:00
|
|
|
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
2022-12-07 23:10:28 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2021-03-08 02:20:48 +01:00
|
|
|
|
2022-11-30 05:42:08 +01:00
|
|
|
// final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2022-08-28 05:08:41 +02:00
|
|
|
// sub.spawnBlock();
|
2022-08-29 20:51:45 +02:00
|
|
|
// sub.spawnBlock(0, 20);
|
2022-08-28 05:08:41 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
log.d(walletOptions.address.text);
|
2021-12-20 21:33:03 +01:00
|
|
|
|
2022-12-02 10:23:21 +01:00
|
|
|
final currentChest = myWalletProvider.getCurrentChest();
|
2022-12-07 23:10:28 +01:00
|
|
|
bool isWalletNameIndexed =
|
|
|
|
duniterIndexer.walletNameIndexer[walletOptions.address.text] != null;
|
2021-02-09 22:11:57 +01:00
|
|
|
|
2022-05-26 02:19:29 +02:00
|
|
|
// final currentWallet = _myWalletProvider.getDefaultWallet();
|
2022-05-19 13:44:22 +02:00
|
|
|
// log.d(_walletOptions.getAddress(_currentChest, 3));
|
2022-08-06 02:22:41 +02:00
|
|
|
log.d("Wallet options: $currentChest:${wallet.derivation}");
|
2021-03-21 00:35:32 +01:00
|
|
|
|
2021-01-28 15:26:26 +01:00
|
|
|
return WillPopScope(
|
2021-11-29 04:05:08 +01:00
|
|
|
onWillPop: () {
|
2022-08-06 02:22:41 +02:00
|
|
|
walletOptions.isEditing = false;
|
|
|
|
walletOptions.isBalanceBlur = false;
|
2022-09-09 01:12:17 +02:00
|
|
|
myWalletProvider.reload();
|
2021-12-24 15:27:38 +01:00
|
|
|
Navigator.pop(context);
|
2021-11-29 04:05:08 +01:00
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
2022-05-29 00:00:57 +02:00
|
|
|
backgroundColor: backgroundColor,
|
2021-11-29 04:05:08 +01:00
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
|
appBar: AppBar(
|
2021-12-01 08:14:07 +01:00
|
|
|
toolbarHeight: 60 * ratio,
|
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
onPressed: () {
|
2022-08-06 02:22:41 +02:00
|
|
|
walletOptions.isEditing = false;
|
|
|
|
walletOptions.isBalanceBlur = false;
|
2022-09-09 01:12:17 +02:00
|
|
|
myWalletProvider.reload();
|
2021-12-24 15:27:38 +01:00
|
|
|
Navigator.pop(context);
|
2021-12-01 08:14:07 +01:00
|
|
|
}),
|
|
|
|
title: SizedBox(
|
|
|
|
height: 22,
|
|
|
|
child: Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletProvider, _) {
|
2022-12-07 23:10:28 +01:00
|
|
|
return Text(isWalletNameIndexed
|
|
|
|
? duniterIndexer
|
|
|
|
.walletNameIndexer[walletOptions.address.text]!
|
|
|
|
: wallet.name!);
|
2021-12-01 08:14:07 +01:00
|
|
|
}),
|
|
|
|
),
|
2022-07-22 22:18:03 +02:00
|
|
|
actions: [
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return QrCodeFullscreen(
|
2022-08-06 02:22:41 +02:00
|
|
|
walletOptions.address.text,
|
2022-07-22 22:18:03 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: QrImageWidget(
|
2022-08-06 02:22:41 +02:00
|
|
|
data: walletOptions.address.text,
|
2022-07-22 22:18:03 +02:00
|
|
|
version: QrVersions.auto,
|
|
|
|
size: 80,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2021-12-01 08:14:07 +01:00
|
|
|
),
|
2022-12-07 23:10:28 +01:00
|
|
|
bottomNavigationBar: const GeckoBottomAppBar(),
|
2022-06-12 18:03:17 +02:00
|
|
|
body: Stack(children: [
|
|
|
|
Builder(
|
|
|
|
builder: (ctx) => SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
Container(
|
|
|
|
height: isTall ? 5 : 0,
|
|
|
|
color: yellowC,
|
|
|
|
),
|
|
|
|
Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletProvider, _) {
|
|
|
|
return Container(
|
2022-09-12 12:38:32 +02:00
|
|
|
decoration: const BoxDecoration(
|
2022-06-12 18:03:17 +02:00
|
|
|
gradient: LinearGradient(
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
colors: [
|
|
|
|
yellowC,
|
|
|
|
backgroundColor,
|
|
|
|
],
|
|
|
|
)),
|
2022-12-07 23:10:28 +01:00
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const Spacer(flex: 1),
|
|
|
|
avatar(walletProvider),
|
|
|
|
const Spacer(flex: 1),
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Stack(children: [
|
|
|
|
SizedBox(
|
|
|
|
width: 250,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletProvider, _) {
|
|
|
|
return NameByAddress(
|
|
|
|
wallet: wallet,
|
|
|
|
size: 27,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: wallet.isMember
|
|
|
|
? FontWeight.w500
|
|
|
|
: FontWeight.w400,
|
|
|
|
fontStyle: FontStyle.normal);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
if (duniterIndexer
|
|
|
|
.walletNameIndexer[wallet.address] ==
|
|
|
|
null)
|
|
|
|
Positioned(
|
|
|
|
right: 0,
|
|
|
|
child: InkWell(
|
|
|
|
key: keyRenameWallet,
|
|
|
|
onTap: () async {
|
|
|
|
await walletOptions.editWalletName(
|
|
|
|
context, wallet.id());
|
|
|
|
await Future.delayed(
|
|
|
|
const Duration(milliseconds: 30));
|
|
|
|
},
|
|
|
|
child: ClipRRect(
|
|
|
|
child: Image.asset(
|
|
|
|
walletOptions.isEditing
|
|
|
|
? 'assets/walletOptions/android-checkmark.png'
|
|
|
|
: 'assets/walletOptions/edit.png',
|
|
|
|
width: 25,
|
|
|
|
height: 25),
|
|
|
|
),
|
|
|
|
),
|
2022-12-02 06:58:18 +01:00
|
|
|
),
|
2022-12-07 23:10:28 +01:00
|
|
|
]),
|
|
|
|
SizedBox(height: isTall ? 5 : 0),
|
|
|
|
Balance(
|
|
|
|
address: walletProvider.address.text, size: 21),
|
|
|
|
const SizedBox(width: 30),
|
|
|
|
InkWell(
|
|
|
|
onTap: () => isWalletNameIndexed
|
|
|
|
? {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
PageNoTransit(builder: (context) {
|
|
|
|
return CertificationsScreen(
|
|
|
|
address:
|
|
|
|
walletProvider.address.text,
|
|
|
|
username: duniterIndexer
|
|
|
|
.walletNameIndexer[
|
|
|
|
walletProvider
|
|
|
|
.address.text]!);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
IdentityStatus(
|
|
|
|
address: walletOptions.address.text,
|
|
|
|
isOwner: true,
|
|
|
|
color: orangeC),
|
|
|
|
Certifications(
|
|
|
|
address: walletProvider.address.text,
|
|
|
|
size: 15)
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
SizedBox(height: 10 * ratio),
|
|
|
|
]),
|
|
|
|
const Spacer(flex: 2),
|
|
|
|
]),
|
2022-06-12 18:03:17 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
Expanded(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
2022-07-22 22:18:03 +02:00
|
|
|
// InkWell(
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.push(
|
|
|
|
// context,
|
|
|
|
// MaterialPageRoute(builder: (context) {
|
|
|
|
// return QrCodeFullscreen(
|
|
|
|
// _walletOptions.address.text,
|
|
|
|
// );
|
|
|
|
// }),
|
|
|
|
// );
|
|
|
|
// },
|
|
|
|
// child: QrImageWidget(
|
|
|
|
// data: _walletOptions.address.text,
|
|
|
|
// version: QrVersions.auto,
|
|
|
|
// size: isTall ? 150 : 80,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
SizedBox(height: 30 * ratio),
|
2022-06-12 18:03:17 +02:00
|
|
|
Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletProvider, _) {
|
|
|
|
return Column(children: [
|
2022-08-21 00:44:23 +02:00
|
|
|
confirmIdentityButton(walletProvider),
|
2022-06-12 18:03:17 +02:00
|
|
|
pubkeyWidget(walletProvider, ctx),
|
|
|
|
SizedBox(height: 10 * ratio),
|
2022-06-16 02:43:30 +02:00
|
|
|
activityWidget(
|
2022-08-06 02:22:41 +02:00
|
|
|
context, historyProvider, walletProvider),
|
2022-06-12 18:03:17 +02:00
|
|
|
SizedBox(height: 12 * ratio),
|
|
|
|
setDefaultWalletWidget(
|
|
|
|
context,
|
|
|
|
walletProvider,
|
2022-08-06 02:22:41 +02:00
|
|
|
myWalletProvider,
|
|
|
|
walletOptions,
|
|
|
|
currentChest),
|
2022-06-12 18:03:17 +02:00
|
|
|
SizedBox(height: 17 * ratio),
|
|
|
|
// walletProvider.isMember(context, _walletOptions.address.text)
|
|
|
|
FutureBuilder(
|
2022-12-07 23:10:28 +01:00
|
|
|
future:
|
|
|
|
sub.isMember(walletOptions.address.text),
|
2022-06-12 18:03:17 +02:00
|
|
|
builder: (BuildContext context,
|
2022-08-06 02:22:41 +02:00
|
|
|
AsyncSnapshot<bool> isMember) {
|
|
|
|
if (isMember.connectionState !=
|
2022-06-12 18:03:17 +02:00
|
|
|
ConnectionState.done ||
|
2022-08-06 02:22:41 +02:00
|
|
|
isMember.hasError) {
|
2022-06-12 18:03:17 +02:00
|
|
|
return const Text('');
|
|
|
|
}
|
|
|
|
return Column(children: [
|
|
|
|
if (!walletProvider.isDefaultWallet &&
|
2022-08-06 02:22:41 +02:00
|
|
|
!isMember.data!)
|
2022-06-12 18:03:17 +02:00
|
|
|
deleteWallet(context, walletProvider,
|
2022-08-06 02:22:41 +02:00
|
|
|
currentChest)
|
2022-06-12 18:03:17 +02:00
|
|
|
else
|
|
|
|
const SizedBox(),
|
2022-08-06 02:22:41 +02:00
|
|
|
if (isMember.data!)
|
2022-08-23 00:25:16 +02:00
|
|
|
manageMembership(context)
|
2022-06-12 18:03:17 +02:00
|
|
|
]);
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
),
|
2022-05-28 00:04:37 +02:00
|
|
|
),
|
2022-06-12 18:03:17 +02:00
|
|
|
]),
|
|
|
|
),
|
2021-04-03 00:07:03 +02:00
|
|
|
),
|
2022-06-12 18:03:17 +02:00
|
|
|
CommonElements().offlineInfo(context),
|
|
|
|
]),
|
2021-11-29 04:05:08 +01:00
|
|
|
),
|
|
|
|
);
|
2021-03-06 22:26:30 +01:00
|
|
|
}
|
2021-12-23 21:44:24 +01:00
|
|
|
|
|
|
|
Widget avatar(WalletOptionsProvider walletProvider) {
|
|
|
|
return Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
InkWell(
|
|
|
|
onTap: () async {
|
2022-08-06 02:22:41 +02:00
|
|
|
final newPath = await (walletProvider.changeAvatar());
|
|
|
|
if (newPath != '') {
|
|
|
|
wallet.imageCustomPath = newPath;
|
2022-05-21 06:47:26 +02:00
|
|
|
walletBox.put(wallet.key, wallet);
|
|
|
|
}
|
2022-09-09 01:12:17 +02:00
|
|
|
walletProvider.reload();
|
2021-12-23 21:44:24 +01:00
|
|
|
},
|
2022-05-28 19:13:30 +02:00
|
|
|
child: wallet.imageCustomPath == null || wallet.imageCustomPath == ''
|
2021-12-23 21:44:24 +01:00
|
|
|
? Image.asset(
|
2022-05-28 19:13:30 +02:00
|
|
|
'assets/avatars/${wallet.imageDefaultPath}',
|
2021-12-23 21:44:24 +01:00
|
|
|
width: 110,
|
|
|
|
)
|
2022-05-28 19:13:30 +02:00
|
|
|
: Container(
|
2022-06-04 23:32:44 +02:00
|
|
|
width: 150,
|
|
|
|
height: 150,
|
2022-05-28 19:13:30 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
color: Colors.transparent,
|
|
|
|
image: DecorationImage(
|
2022-06-04 23:32:44 +02:00
|
|
|
fit: BoxFit.cover,
|
2022-05-28 19:13:30 +02:00
|
|
|
image: FileImage(
|
|
|
|
File(wallet.imageCustomPath!),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-12-23 21:44:24 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
right: 0,
|
2021-12-24 15:27:38 +01:00
|
|
|
top: 0,
|
2021-12-23 21:44:24 +01:00
|
|
|
child: InkWell(
|
|
|
|
onTap: () async {
|
2022-05-28 19:13:30 +02:00
|
|
|
wallet.imageCustomPath = await (walletProvider.changeAvatar());
|
2022-09-09 01:12:17 +02:00
|
|
|
walletProvider.reload();
|
2021-12-23 21:44:24 +01:00
|
|
|
},
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/walletOptions/camera.png',
|
|
|
|
height: 40,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-21 00:44:23 +02:00
|
|
|
Widget confirmIdentityButton(WalletOptionsProvider walletProvider) {
|
|
|
|
return Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
|
|
|
return FutureBuilder(
|
|
|
|
future: sub.idtyStatus(walletProvider.address.text),
|
|
|
|
initialData: '',
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.data == 'Created') {
|
|
|
|
return Column(children: [
|
|
|
|
SizedBox(
|
|
|
|
width: 320,
|
|
|
|
height: 60,
|
2022-08-24 23:59:51 +02:00
|
|
|
child: ElevatedButton(
|
|
|
|
key: keyConfirmIdentity,
|
2022-08-21 00:44:23 +02:00
|
|
|
style: ElevatedButton.styleFrom(
|
2022-09-05 08:12:24 +02:00
|
|
|
foregroundColor: Colors.white, elevation: 4,
|
|
|
|
backgroundColor: orangeC, // foreground
|
2022-08-21 00:44:23 +02:00
|
|
|
),
|
2022-12-02 21:18:28 +01:00
|
|
|
onPressed: () async {
|
2022-08-21 01:30:26 +02:00
|
|
|
walletProvider.confirmIdentityPopup(context);
|
2022-08-21 00:44:23 +02:00
|
|
|
// Navigator.push(
|
|
|
|
// context,
|
|
|
|
// MaterialPageRoute(builder: (context) {
|
|
|
|
// return const SearchResultScreen();
|
|
|
|
// }),
|
|
|
|
// );
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
'confirmMyIdentity'.tr(),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 21, fontWeight: FontWeight.w600),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 7),
|
|
|
|
Text(
|
|
|
|
"someoneCreatedYourIdentity".tr(args: [currencyName]),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 40),
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return const SizedBox();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-23 21:44:24 +01:00
|
|
|
Widget pubkeyWidget(WalletOptionsProvider walletProvider, BuildContext ctx) {
|
2022-12-02 10:23:21 +01:00
|
|
|
final shortPubkey = getShortPubkey(walletProvider.address.text);
|
2021-12-23 21:44:24 +01:00
|
|
|
return GestureDetector(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyCopyAddress,
|
2021-12-23 21:44:24 +01:00
|
|
|
onTap: () {
|
2022-05-19 07:00:25 +02:00
|
|
|
Clipboard.setData(ClipboardData(text: walletProvider.address.text));
|
2022-05-21 06:47:26 +02:00
|
|
|
snackCopyKey(ctx);
|
2021-12-23 21:44:24 +01:00
|
|
|
},
|
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 30),
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/key.png',
|
|
|
|
height: 45,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
2022-05-28 00:17:50 +02:00
|
|
|
Text(shortPubkey,
|
2021-12-23 21:44:24 +01:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
fontWeight: FontWeight.w800,
|
|
|
|
fontFamily: 'Monospace',
|
|
|
|
color: Colors.black)),
|
|
|
|
const SizedBox(width: 15),
|
|
|
|
SizedBox(
|
|
|
|
height: 40,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
2022-09-05 08:12:24 +02:00
|
|
|
foregroundColor: Colors.black,
|
|
|
|
shape: RoundedRectangleBorder(
|
2021-12-23 21:44:24 +01:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
2022-09-05 08:12:24 +02:00
|
|
|
),
|
|
|
|
backgroundColor: orangeC,
|
2022-09-05 04:15:27 +02:00
|
|
|
elevation: 1, // foreground
|
2021-12-23 21:44:24 +01:00
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Clipboard.setData(
|
2022-05-19 07:00:25 +02:00
|
|
|
ClipboardData(text: walletProvider.address.text));
|
2022-05-21 06:47:26 +02:00
|
|
|
snackCopyKey(ctx);
|
2021-12-23 21:44:24 +01:00
|
|
|
},
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/copy-white.png',
|
|
|
|
height: 25,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 7),
|
|
|
|
Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
'copy'.tr(),
|
2021-12-23 21:44:24 +01:00
|
|
|
style: TextStyle(fontSize: 15, color: Colors.grey[50]),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-16 02:43:30 +02:00
|
|
|
Widget activityWidget(
|
2021-12-23 21:44:24 +01:00
|
|
|
BuildContext context,
|
2022-08-06 02:22:41 +02:00
|
|
|
WalletsProfilesProvider historyProvider,
|
2021-12-23 21:44:24 +01:00
|
|
|
WalletOptionsProvider walletProvider) {
|
|
|
|
return InkWell(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyOpenActivity,
|
2021-12-23 21:44:24 +01:00
|
|
|
onTap: () {
|
2022-06-16 02:43:30 +02:00
|
|
|
// _historyProvider.nPage = 1;
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
2022-12-08 05:26:55 +01:00
|
|
|
PageNoTransit(builder: (context) {
|
2022-06-16 02:43:30 +02:00
|
|
|
return ActivityScreen(
|
|
|
|
address: walletProvider.address.text,
|
|
|
|
avatar: wallet.imageCustomPath == null
|
|
|
|
? Image.asset(
|
|
|
|
'assets/avatars/${wallet.imageDefaultPath}',
|
|
|
|
width: 110,
|
|
|
|
)
|
|
|
|
: Image.asset(
|
|
|
|
wallet.imageCustomPath!,
|
|
|
|
width: 110,
|
|
|
|
));
|
|
|
|
}),
|
|
|
|
);
|
2021-12-23 21:44:24 +01:00
|
|
|
},
|
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 30),
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/clock.png',
|
|
|
|
height: 45,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 22),
|
2022-06-17 01:13:14 +02:00
|
|
|
Text("displayActivity".tr(),
|
2022-06-17 20:18:54 +02:00
|
|
|
style:
|
|
|
|
const TextStyle(fontSize: 20, fontWeight: FontWeight.w500)),
|
2021-12-23 21:44:24 +01:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-23 00:25:16 +02:00
|
|
|
Widget manageMembership(BuildContext context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final walletOptions =
|
2022-06-05 02:22:22 +02:00
|
|
|
Provider.of<WalletOptionsProvider>(context, listen: false);
|
2021-12-23 21:44:24 +01:00
|
|
|
return InkWell(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyManageMembership,
|
2022-06-05 02:22:22 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return ManageMembership(
|
2022-08-06 02:22:41 +02:00
|
|
|
address: walletOptions.address.text,
|
2022-06-05 02:22:22 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
2021-12-23 21:44:24 +01:00
|
|
|
child: SizedBox(
|
2022-06-05 02:22:22 +02:00
|
|
|
height: 40,
|
2021-12-23 21:44:24 +01:00
|
|
|
child: Row(children: <Widget>[
|
2022-06-05 02:22:22 +02:00
|
|
|
const SizedBox(width: 32),
|
|
|
|
Image.asset(
|
|
|
|
'assets/medal.png',
|
|
|
|
height: 45,
|
2021-12-23 21:44:24 +01:00
|
|
|
),
|
|
|
|
const SizedBox(width: 22),
|
2022-06-17 01:13:14 +02:00
|
|
|
Text('manageMembership'.tr(), style: const TextStyle(fontSize: 20)),
|
2021-12-23 21:44:24 +01:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-05 02:22:22 +02:00
|
|
|
Widget setDefaultWalletWidget(
|
|
|
|
BuildContext context,
|
|
|
|
WalletOptionsProvider walletProvider,
|
2022-11-30 05:42:08 +01:00
|
|
|
final myWalletProvider,
|
|
|
|
final walletOptions,
|
2022-08-06 02:22:41 +02:00
|
|
|
int currentChest) {
|
|
|
|
return Consumer<MyWalletsProvider>(builder: (context, myWalletProvider, _) {
|
|
|
|
WalletData defaultWallet = myWalletProvider.getDefaultWallet();
|
|
|
|
walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]);
|
2022-06-05 02:22:22 +02:00
|
|
|
return InkWell(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keySetDefaultWallet,
|
2022-06-05 02:22:22 +02:00
|
|
|
onTap: !walletProvider.isDefaultWallet
|
|
|
|
? () async {
|
2022-08-06 02:22:41 +02:00
|
|
|
await setDefaultWallet(context, currentChest);
|
2022-06-05 02:22:22 +02:00
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 31),
|
|
|
|
CircleAvatar(
|
|
|
|
backgroundColor:
|
|
|
|
Colors.grey[walletProvider.isDefaultWallet ? 300 : 500],
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/walletOptions/android-checkmark.png',
|
|
|
|
height: 25,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 22),
|
|
|
|
Text(
|
|
|
|
walletProvider.isDefaultWallet
|
2022-06-17 01:13:14 +02:00
|
|
|
? 'thisWalletIsDefault'.tr()
|
|
|
|
: 'defineWalletAsDefault'.tr(),
|
2022-06-05 02:22:22 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
color: walletProvider.isDefaultWallet
|
|
|
|
? Colors.grey[500]
|
|
|
|
: Colors.black)),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
Future setDefaultWallet(BuildContext context, int currentChest) async {
|
2022-11-30 05:42:08 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
|
|
|
final myWalletProvider =
|
2022-05-29 04:30:03 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
2022-11-30 05:42:08 +01:00
|
|
|
final walletOptions =
|
2022-08-13 13:45:43 +02:00
|
|
|
Provider.of<WalletOptionsProvider>(context, listen: false);
|
2022-05-29 04:30:03 +02:00
|
|
|
|
|
|
|
// WalletData defaultWallet = _myWalletProvider.getDefaultWallet()!;
|
|
|
|
// defaultWallet = wallet;
|
2022-08-06 02:22:41 +02:00
|
|
|
await sub.setCurrentWallet(wallet);
|
|
|
|
myWalletProvider.readAllWallets(currentChest);
|
2022-09-09 01:12:17 +02:00
|
|
|
myWalletProvider.reload();
|
|
|
|
walletOptions.reload();
|
2022-05-29 04:30:03 +02:00
|
|
|
}
|
|
|
|
|
2022-12-06 04:33:10 +01:00
|
|
|
Widget deleteWallet(BuildContext context, WalletOptionsProvider walletOptions,
|
|
|
|
int currentChest) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
|
|
|
final myWalletProvider =
|
2022-06-08 04:24:06 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final defaultWallet = myWalletProvider.getDefaultWallet();
|
2022-06-08 04:24:06 +02:00
|
|
|
final bool isDefaultWallet =
|
2022-12-06 04:33:10 +01:00
|
|
|
walletOptions.address.text == defaultWallet.address;
|
2022-06-08 04:24:06 +02:00
|
|
|
// return Consumer<MyWalletsProvider>(
|
|
|
|
// builder: (context, _myWalletProvider, _) {
|
|
|
|
return FutureBuilder(
|
2022-12-06 22:33:42 +01:00
|
|
|
future: sub.hasAccountConsumers(wallet.address),
|
2022-08-06 02:22:41 +02:00
|
|
|
builder: (BuildContext context, AsyncSnapshot<bool> hasConsumers) {
|
|
|
|
if (hasConsumers.connectionState != ConnectionState.done ||
|
|
|
|
hasConsumers.hasError) {
|
2022-06-08 04:24:06 +02:00
|
|
|
return const Text('');
|
|
|
|
}
|
2022-08-06 02:22:41 +02:00
|
|
|
final double balance =
|
2022-12-06 04:33:10 +01:00
|
|
|
walletOptions.balanceCache[walletOptions.address.text] ?? -1;
|
2022-06-08 04:52:20 +02:00
|
|
|
final bool canDelete = !isDefaultWallet &&
|
2022-08-06 02:22:41 +02:00
|
|
|
!hasConsumers.data! &&
|
|
|
|
(balance > 2 || balance == 0);
|
2022-06-08 04:24:06 +02:00
|
|
|
return InkWell(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyDeleteWallet,
|
2022-06-08 04:52:20 +02:00
|
|
|
onTap: canDelete
|
2022-06-08 04:24:06 +02:00
|
|
|
? () async {
|
2022-12-06 04:33:10 +01:00
|
|
|
await walletOptions.deleteWallet(context, wallet);
|
2022-06-08 04:24:06 +02:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2022-08-06 02:22:41 +02:00
|
|
|
myWalletProvider.listWallets =
|
|
|
|
myWalletProvider.readAllWallets(currentChest);
|
2022-09-09 01:12:17 +02:00
|
|
|
myWalletProvider.reload();
|
2022-06-08 04:24:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
: null,
|
2022-06-08 04:52:20 +02:00
|
|
|
child: canDelete
|
2022-06-08 04:24:06 +02:00
|
|
|
? Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 30),
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/trash.png',
|
|
|
|
height: 45,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 19),
|
2022-06-18 03:01:22 +02:00
|
|
|
Text('deleteThisWallet'.tr(),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 20, color: Color(0xffD80000))),
|
2022-06-08 04:24:06 +02:00
|
|
|
])
|
|
|
|
: const SizedBox(width: 30),
|
|
|
|
);
|
|
|
|
});
|
2021-12-23 21:44:24 +01:00
|
|
|
}
|
2021-01-28 15:26:26 +01:00
|
|
|
}
|