payment inter wallets is working; bug with feedback position

This commit is contained in:
poka 2022-09-12 04:52:34 +02:00
parent edbe1d8b5c
commit 8b32bb8e26
9 changed files with 385 additions and 352 deletions

View File

@ -339,7 +339,7 @@ class DuniterIndexer with ChangeNotifier {
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
walletsProfiles.address = profile['id']; walletsProfiles.address = profile['id'];
return WalletViewScreen( return WalletViewScreen(
pubkey: profile['id'], address: profile['id'],
username: g1WalletsBox username: g1WalletsBox
.get(profile['id']) .get(profile['id'])
?.id ?.id

View File

@ -44,7 +44,7 @@ class WalletsProfilesProvider with ChangeNotifier {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return WalletViewScreen(pubkey: barcode!.rawContent); return WalletViewScreen(address: barcode!.rawContent);
}), }),
); );
} else { } else {

View File

@ -354,7 +354,7 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return WalletViewScreen(pubkey: repository[1]); return WalletViewScreen(address: repository[1]);
}), }),
); );
// Navigator.pop(context); // Navigator.pop(context);

View File

@ -53,8 +53,6 @@ class ChooseWalletScreen extends StatelessWidget {
), ),
onPressed: () async { onPressed: () async {
await sub.setCurrentWallet(selectedWallet!); await sub.setCurrentWallet(selectedWallet!);
// _walletViewProvider.reload();
sub.reload(); sub.reload();
// Navigator.pop(context); // Navigator.pop(context);

View File

@ -18,6 +18,7 @@ import 'package:gecko/screens/myWallets/choose_chest.dart';
import 'package:gecko/screens/myWallets/import_g1_v1.dart'; import 'package:gecko/screens/myWallets/import_g1_v1.dart';
import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
import 'package:gecko/screens/myWallets/wallet_options.dart'; import 'package:gecko/screens/myWallets/wallet_options.dart';
import 'package:gecko/screens/wallet_view.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class WalletsHome extends StatelessWidget { class WalletsHome extends StatelessWidget {
@ -159,6 +160,7 @@ class WalletsHome extends StatelessWidget {
WalletOptionsProvider walletOptions = WalletOptionsProvider walletOptions =
Provider.of<WalletOptionsProvider>(context, listen: false); Provider.of<WalletOptionsProvider>(context, listen: false);
final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
if (!isWalletsExists) { if (!isWalletsExists) {
return const Text(''); return const Text('');
@ -196,7 +198,37 @@ class WalletsHome extends StatelessWidget {
mainAxisSpacing: 0, mainAxisSpacing: 0,
children: <Widget>[ children: <Widget>[
for (WalletData repository in listWallets as Iterable<WalletData>) for (WalletData repository in listWallets as Iterable<WalletData>)
Padding( LongPressDraggable<String>(
data: repository.address!,
dragAnchorStrategy:
(Draggable<Object> _, BuildContext __, Offset ___) =>
const Offset(0, 0),
feedback: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: orangeC,
shape: const CircleBorder(),
padding: const EdgeInsets.all(15),
),
child: const SizedBox(
height: 35,
child: Image(image: AssetImage('assets/vector_white.png')),
),
),
child: DragTarget<String>(onAccept: (senderAddress) async {
log.d(
'INTERPAY: sender: $senderAddress --- receiver: ${repository.address!}');
final walletData =
myWalletProvider.getWalletDataByAddress(senderAddress);
await sub.setCurrentWallet(walletData!);
sub.reload();
paymentPopup(context, repository.address!);
}, builder: (
BuildContext context,
List<dynamic> accepted,
List<dynamic> rejected,
) {
return Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: GestureDetector( child: GestureDetector(
key: keyOpenWallet(repository.address!), key: keyOpenWallet(repository.address!),
@ -252,22 +284,28 @@ class WalletsHome extends StatelessWidget {
image: DecorationImage( image: DecorationImage(
fit: BoxFit.fitHeight, fit: BoxFit.fitHeight,
image: FileImage( image: FileImage(
File(repository.imageCustomPath!), File(repository
.imageCustomPath!),
), ),
), ),
), ),
), ),
)), )),
Stack(children: <Widget>[ Stack(children: <Widget>[
balanceBuilder(context, repository.address!, balanceBuilder(
repository.address == defaultWallet.address), context,
repository.address!,
repository.address ==
defaultWallet.address),
nameBuilder(context, repository, defaultWallet, nameBuilder(context, repository, defaultWallet,
currentChestNumber), currentChestNumber),
]), ]),
]), ]),
), ),
), ),
)), ));
}),
),
Consumer<SubstrateSdk>(builder: (context, sub, _) { Consumer<SubstrateSdk>(builder: (context, sub, _) {
return sub.nodeConnected return sub.nodeConnected
? addNewDerivation(context) ? addNewDerivation(context)

View File

@ -116,7 +116,7 @@ class ContactsScreen extends StatelessWidget {
walletsProfilesClass.address = walletsProfilesClass.address =
g1Wallet.pubkey; g1Wallet.pubkey;
return WalletViewScreen( return WalletViewScreen(
pubkey: g1Wallet.pubkey, address: g1Wallet.pubkey,
username: g1WalletsBox username: g1WalletsBox
.get(g1Wallet.pubkey) .get(g1Wallet.pubkey)
?.id ?.id

View File

@ -143,7 +143,7 @@ class SearchResultScreen extends StatelessWidget {
walletsProfilesClass.address = walletsProfilesClass.address =
g1Wallet.pubkey; g1Wallet.pubkey;
return WalletViewScreen( return WalletViewScreen(
pubkey: g1Wallet.pubkey, address: g1Wallet.pubkey,
username: g1WalletsBox username: g1WalletsBox
.get(g1Wallet.pubkey) .get(g1Wallet.pubkey)
?.id ?.id

View File

@ -24,9 +24,9 @@ import 'package:qr_flutter/qr_flutter.dart';
class WalletViewScreen extends StatelessWidget { class WalletViewScreen extends StatelessWidget {
const WalletViewScreen( const WalletViewScreen(
{required this.pubkey, this.username, this.avatar, Key? key}) {required this.address, this.username, this.avatar, Key? key})
: super(key: key); : super(key: key);
final String? pubkey; final String? address;
final String? username; final String? username;
final Image? avatar; final Image? avatar;
final double buttonSize = 100; final double buttonSize = 100;
@ -39,7 +39,7 @@ class WalletViewScreen extends StatelessWidget {
Provider.of<WalletsProfilesProvider>(context, listen: false); Provider.of<WalletsProfilesProvider>(context, listen: false);
CesiumPlusProvider cesiumPlusProvider = CesiumPlusProvider cesiumPlusProvider =
Provider.of<CesiumPlusProvider>(context, listen: false); Provider.of<CesiumPlusProvider>(context, listen: false);
walletProfile.address = pubkey!; walletProfile.address = address!;
SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false); SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
HomeProvider homeProvider = HomeProvider homeProvider =
Provider.of<HomeProvider>(context, listen: false); Provider.of<HomeProvider>(context, listen: false);
@ -67,14 +67,14 @@ class WalletViewScreen extends StatelessWidget {
onPressed: () async { onPressed: () async {
G1WalletsList? newContact; G1WalletsList? newContact;
g1WalletsBox.toMap().forEach((key, value) { g1WalletsBox.toMap().forEach((key, value) {
if (key == pubkey) newContact = value; if (key == address) newContact = value;
}); });
// G1WalletsList(pubkey: pubkey!, username: username); // G1WalletsList(pubkey: pubkey!, username: username);
await walletProfile.addContact( await walletProfile.addContact(
newContact ?? G1WalletsList(pubkey: pubkey!)); newContact ?? G1WalletsList(pubkey: address!));
}, },
icon: Icon( icon: Icon(
walletProfile.isContact(pubkey!) walletProfile.isContact(address!)
? Icons.add_reaction_rounded ? Icons.add_reaction_rounded
: Icons.add_reaction_outlined, : Icons.add_reaction_outlined,
size: 35, size: 35,
@ -110,7 +110,7 @@ class WalletViewScreen extends StatelessWidget {
bottomNavigationBar: homeProvider.bottomAppBar(context), bottomNavigationBar: homeProvider.bottomAppBar(context),
body: SafeArea( body: SafeArea(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
walletProfile.headerProfileView(context, pubkey!, username), walletProfile.headerProfileView(context, address!, username),
SizedBox(height: isTall ? 10 : 0), SizedBox(height: isTall ? 10 : 0),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
Column(children: <Widget>[ Column(children: <Widget>[
@ -134,7 +134,7 @@ class WalletViewScreen extends StatelessWidget {
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
return ActivityScreen( return ActivityScreen(
address: pubkey, address: address,
avatar: avatar:
cesiumPlusProvider.defaultAvatar(50)); cesiumPlusProvider.defaultAvatar(50));
}), }),
@ -155,7 +155,7 @@ class WalletViewScreen extends StatelessWidget {
WalletData? defaultWallet = myWalletProvider.getDefaultWallet(); WalletData? defaultWallet = myWalletProvider.getDefaultWallet();
return FutureBuilder( return FutureBuilder(
future: sub.certState(defaultWallet.address!, future: sub.certState(defaultWallet.address!,
pubkey!), // .canCertify(_defaultWallet.address!, pubkey!), address!), // .canCertify(_defaultWallet.address!, pubkey!),
builder: (context, AsyncSnapshot<Map<String, int>> snapshot) { builder: (context, AsyncSnapshot<Map<String, int>> snapshot) {
if (snapshot.data == null) return const SizedBox(); if (snapshot.data == null) return const SizedBox();
String duration = ''; String duration = '';
@ -223,7 +223,7 @@ class WalletViewScreen extends StatelessWidget {
context, context,
"areYouSureYouWantToCertify".tr( "areYouSureYouWantToCertify".tr(
args: [ args: [
getShortPubkey(pubkey!) getShortPubkey(address!)
])); ]));
if (result ?? false) { if (result ?? false) {
@ -303,7 +303,7 @@ class WalletViewScreen extends StatelessWidget {
image: AssetImage('assets/copy_key.png'), image: AssetImage('assets/copy_key.png'),
height: 90)), height: 90)),
onTap: () { onTap: () {
Clipboard.setData(ClipboardData(text: pubkey)); Clipboard.setData(ClipboardData(text: address));
snackCopyKey(context); snackCopyKey(context);
}), }),
), ),
@ -340,14 +340,14 @@ class WalletViewScreen extends StatelessWidget {
splashColor: yellowC, splashColor: yellowC,
onTap: sub.nodeConnected onTap: sub.nodeConnected
? () { ? () {
paymentPopup(context, walletProfile); paymentPopup(context, address!);
} }
: null, // inkwell color : null, // inkwell color
child: const Padding( child: const Padding(
padding: EdgeInsets.all(14), padding: EdgeInsets.all(14),
child: Image( child: Image(
image: AssetImage('assets/vector_white.png'), image: AssetImage('assets/vector_white.png')),
))), )),
), ),
), ),
), ),
@ -397,11 +397,13 @@ class WalletViewScreen extends StatelessWidget {
), ),
]); ]);
} }
}
void paymentPopup( void paymentPopup(BuildContext context, String toAddress) {
BuildContext context, WalletsProfilesProvider walletViewProvider) {
// WalletsProfilesProvider _walletViewProvider = // WalletsProfilesProvider _walletViewProvider =
// Provider.of<WalletsProfilesProvider>(context, listen: false); // Provider.of<WalletsProfilesProvider>(context, listen: false);
final walletViewProvider =
Provider.of<WalletsProfilesProvider>(context, listen: false);
final myWalletProvider = final myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false); Provider.of<MyWalletsProvider>(context, listen: false);
@ -433,8 +435,9 @@ class WalletViewScreen extends StatelessWidget {
(double.parse(walletViewProvider.payAmount.text) + (double.parse(walletViewProvider.payAmount.text) +
2 / balanceRatio) <= 2 / balanceRatio) <=
(balanceCache[defaultWallet.address] ?? 0) && (balanceCache[defaultWallet.address] ?? 0) &&
walletViewProvider.address != defaultWallet.address) { toAddress != defaultWallet.address) {
if ((balanceCache[pubkey] == 0 || balanceCache[pubkey] == null) && if ((balanceCache[toAddress] == 0 ||
balanceCache[toAddress] == null) &&
double.parse(walletViewProvider.payAmount.text) < double.parse(walletViewProvider.payAmount.text) <
5 / balanceRatio) { 5 / balanceRatio) {
canValidate = false; canValidate = false;
@ -507,8 +510,7 @@ class WalletViewScreen extends StatelessWidget {
), ),
); );
} }
if (pin != null || if (pin != null || myWalletProvider.pinCode != '') {
myWalletProvider.pinCode != '') {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) { MaterialPageRoute(builder: (context) {
@ -522,10 +524,9 @@ class WalletViewScreen extends StatelessWidget {
width: double.infinity, width: double.infinity,
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
color: Colors.blueAccent.shade200, color: Colors.blueAccent.shade200, width: 2),
width: 2), borderRadius:
borderRadius: const BorderRadius.all( const BorderRadius.all(Radius.circular(10.0)),
Radius.circular(10.0)),
), ),
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
child: Row(children: [ child: Row(children: [
@ -578,8 +579,8 @@ class WalletViewScreen extends StatelessWidget {
// borderRadius: BorderRadius.circular(8)), // borderRadius: BorderRadius.circular(8)),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide( borderSide:
color: Colors.grey[500]!, width: 2), BorderSide(color: Colors.grey[500]!, width: 2),
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
), ),
contentPadding: const EdgeInsets.all(20), contentPadding: const EdgeInsets.all(20),
@ -619,8 +620,7 @@ class WalletViewScreen extends StatelessWidget {
if (pin != null || if (pin != null ||
myWalletProvider.pinCode != '') { myWalletProvider.pinCode != '') {
// Payment workflow ! // Payment workflow !
WalletsProfilesProvider WalletsProfilesProvider walletViewProvider =
walletViewProvider =
Provider.of<WalletsProfilesProvider>( Provider.of<WalletsProfilesProvider>(
context, context,
listen: false); listen: false);
@ -629,14 +629,12 @@ class WalletViewScreen extends StatelessWidget {
listen: false); listen: false);
final acc = sub.getCurrentWallet(); final acc = sub.getCurrentWallet();
log.d( log.d(
"fromAddress: ${acc.address!},destAddress: ${walletViewProvider.address!}, amount: ${double.parse(walletViewProvider.payAmount.text)}, password: $pin"); "fromAddress: ${acc.address!},destAddress: $toAddress, amount: ${double.parse(walletViewProvider.payAmount.text)}, password: $pin");
sub.pay( sub.pay(
fromAddress: acc.address!, fromAddress: acc.address!,
destAddress: destAddress: toAddress,
walletViewProvider.address!,
amount: double.parse( amount: double.parse(
walletViewProvider walletViewProvider.payAmount.text),
.payAmount.text),
password: password:
pin ?? myWalletProvider.pinCode); pin ?? myWalletProvider.pinCode);
Navigator.push( Navigator.push(
@ -662,5 +660,4 @@ class WalletViewScreen extends StatelessWidget {
); );
}); });
}).then((value) => walletViewProvider.payAmount.text = ''); }).then((value) => walletViewProvider.payAmount.text = '');
}
} }

View File

@ -611,7 +611,7 @@ packages:
name: image_picker_android name: image_picker_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.5+2" version: "0.8.5+3"
image_picker_for_web: image_picker_for_web:
dependency: transitive dependency: transitive
description: description:
@ -826,7 +826,7 @@ packages:
name: package_info_plus_windows name: package_info_plus_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0"
path: path:
dependency: transitive dependency: transitive
description: description:
@ -980,7 +980,7 @@ packages:
name: pointycastle name: pointycastle
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.6.1" version: "3.6.2"
polkawallet_sdk: polkawallet_sdk:
dependency: "direct main" dependency: "direct main"
description: description:
@ -1003,7 +1003,7 @@ packages:
name: printing name: printing
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.9.2" version: "5.9.3"
process: process:
dependency: transitive dependency: transitive
description: description:
@ -1096,7 +1096,7 @@ packages:
name: shared_preferences_android name: shared_preferences_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.12" version: "2.0.13"
shared_preferences_ios: shared_preferences_ios:
dependency: transitive dependency: transitive
description: description:
@ -1325,7 +1325,7 @@ packages:
name: win32 name: win32
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.7.0" version: "3.0.0"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description: