WIP: refactor payment UX workflow
This commit is contained in:
parent
e9291d9277
commit
0009fc4009
|
@ -24,6 +24,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
// configBox.delete('endpoint');
|
||||
if (!configBox.containsKey('endpoint') || configBox.get('endpoint') == '') {
|
||||
log.d('No endpoint, configure...');
|
||||
// configBox.put('endpoint', 'wss://gdev.librelois.fr/ws');
|
||||
configBox.put('endpoint', 'ws://127.0.0.1:9944');
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class SubstrateSdk with ChangeNotifier {
|
|||
bool importIsLoading = false;
|
||||
int blocNumber = 0;
|
||||
bool isLoadingEndpoint = false;
|
||||
String debugConnection = '';
|
||||
|
||||
TextEditingController jsonKeystore = TextEditingController();
|
||||
TextEditingController keystorePassword = TextEditingController();
|
||||
|
@ -48,7 +49,7 @@ class SubstrateSdk with ChangeNotifier {
|
|||
n.endpoint = configBox.get('endpoint');
|
||||
n.ss58 = ss58;
|
||||
node.add(n);
|
||||
int timeout = 7000;
|
||||
int timeout = 10000;
|
||||
|
||||
// if (n.endpoint!.startsWith('ws://')) {
|
||||
// timeout = 5000;
|
||||
|
@ -85,20 +86,19 @@ class SubstrateSdk with ChangeNotifier {
|
|||
notifyListeners();
|
||||
if (res != null) {
|
||||
nodeConnected = true;
|
||||
notifyListeners();
|
||||
snackNode(ctx, true);
|
||||
} else {
|
||||
nodeConnected = false;
|
||||
notifyListeners();
|
||||
snackNode(ctx, false);
|
||||
}
|
||||
|
||||
// Subscribe bloc number
|
||||
if (nodeConnected) {
|
||||
// Subscribe bloc number
|
||||
sdk.api.setting.subscribeBestNumber((res) {
|
||||
blocNumber = int.parse(res.toString());
|
||||
notifyListeners();
|
||||
});
|
||||
notifyListeners();
|
||||
snackNode(ctx, true);
|
||||
} else {
|
||||
nodeConnected = false;
|
||||
debugConnection = res.toString();
|
||||
notifyListeners();
|
||||
snackNode(ctx, false);
|
||||
}
|
||||
|
||||
log.d(sdk.api.connectedNode?.endpoint);
|
||||
|
@ -371,12 +371,12 @@ class SubstrateSdk with ChangeNotifier {
|
|||
);
|
||||
|
||||
try {
|
||||
final tata = await sdk.api.tx.signAndSend(
|
||||
final result = await sdk.api.tx.signAndSend(
|
||||
txInfo,
|
||||
[name],
|
||||
password,
|
||||
);
|
||||
log.d(tata);
|
||||
log.d(result);
|
||||
return 'confirmed';
|
||||
} on Exception catch (e) {
|
||||
log.e(e);
|
||||
|
|
|
@ -265,6 +265,10 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
|
||||
return balance;
|
||||
}
|
||||
|
||||
void reload() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
snackCopyKey(context) {
|
||||
|
|
|
@ -3,9 +3,10 @@ import 'package:gecko/globals.dart';
|
|||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/screens/myWallets/generate_wallets.dart';
|
||||
import 'package:gecko/screens/myWallets/restore_chest.dart';
|
||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||
import 'package:carousel_slider/carousel_slider.dart';
|
||||
import 'package:gecko/screens/onBoarding/5.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ChooseChest extends StatefulWidget {
|
||||
|
@ -136,28 +137,54 @@ class _ChooseChestState extends State<ChooseChest> {
|
|||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// const SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: InkWell(
|
||||
key: const Key('createNewChest'),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const OnboardingStepFive(skipIntro: true);
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: Text('Créer un nouveau coffre',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
color: orangeC,
|
||||
fontWeight: FontWeight.w600))),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
key: const Key('createNewChest'),
|
||||
key: const Key('importChest'),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return GenerateFastChestScreen();
|
||||
return const RestoreChest(skipIntro: true);
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 70,
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: Text('Créer un nouveau coffre',
|
||||
child: Text('Importer un coffre',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
color: orangeC,
|
||||
fontWeight: FontWeight.w600))),
|
||||
)),
|
||||
const SizedBox(height: 10),
|
||||
const SizedBox(height: 20),
|
||||
]),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -22,9 +22,7 @@ class ChooseWalletScreen extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
WalletsProfilesProvider _walletViewProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
|
||||
// HomeProvider _homeProvider = Provider.of<HomeProvider>(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
|
@ -50,19 +48,22 @@ class ChooseWalletScreen extends StatelessWidget {
|
|||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed: () async {
|
||||
final acc = _sub.getCurrentWallet();
|
||||
log.d(
|
||||
"fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.outputPubkey.text}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $pin");
|
||||
final resultPay = await _sub.pay(context,
|
||||
fromAddress: acc.address!,
|
||||
destAddress: _walletViewProvider.outputPubkey.text,
|
||||
amount:
|
||||
double.parse(_walletViewProvider.payAmount.text),
|
||||
password: pin.toUpperCase());
|
||||
await paymentsResult(context, resultPay);
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
// Payment workflow !
|
||||
// final acc = _sub.getCurrentWallet();
|
||||
// log.d(
|
||||
// "fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.outputPubkey.text}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $pin");
|
||||
// final resultPay = await _sub.pay(context,
|
||||
// fromAddress: acc.address!,
|
||||
// destAddress: _walletViewProvider.outputPubkey.text,
|
||||
// amount:
|
||||
// double.parse(_walletViewProvider.payAmount.text),
|
||||
// password: pin.toUpperCase());
|
||||
// await paymentsResult(context, resultPay);
|
||||
},
|
||||
child: const Text(
|
||||
'Valider le paiement',
|
||||
'Choisir ce portefeuille',
|
||||
style:
|
||||
TextStyle(fontSize: 24, fontWeight: FontWeight.w600),
|
||||
),
|
||||
|
@ -80,6 +81,8 @@ class ChooseWalletScreen extends StatelessWidget {
|
|||
Provider.of<MyWalletsProvider>(context);
|
||||
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
|
||||
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
WalletsProfilesProvider _walletViewProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
|
||||
WalletData? defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(currentChest);
|
||||
|
@ -129,8 +132,12 @@ class ChooseWalletScreen extends StatelessWidget {
|
|||
onTap: () {
|
||||
_derivation = _repository.derivation!;
|
||||
_selectedId = _repository.id();
|
||||
chestBox.get(currentChest)!.defaultWallet =
|
||||
_repository.number;
|
||||
|
||||
_sub.setCurrentWallet(_repository.address!);
|
||||
_myWalletProvider.rebuildWidget();
|
||||
_walletViewProvider.reload();
|
||||
},
|
||||
child: ClipOvalShadow(
|
||||
shadow: const Shadow(
|
||||
|
@ -196,8 +203,11 @@ class ChooseWalletScreen extends StatelessWidget {
|
|||
onTap: () {
|
||||
_derivation = _repository.derivation!;
|
||||
_selectedId = _repository.id();
|
||||
chestBox.get(currentChest)!.defaultWallet =
|
||||
_repository.number;
|
||||
_sub.setCurrentWallet(_repository.address!);
|
||||
_myWalletProvider.rebuildWidget();
|
||||
// _myWalletProvider.rebuildWidget();
|
||||
_sub.reload();
|
||||
},
|
||||
)
|
||||
]),
|
||||
|
|
|
@ -212,21 +212,33 @@ class UnlockingWallet extends StatelessWidget {
|
|||
pinFocus.requestFocus();
|
||||
} else {
|
||||
pinColor = Colors.green[400];
|
||||
if (action == "mywallets") {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const WalletsHome();
|
||||
}),
|
||||
);
|
||||
} else if (action == "pay") {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return ChooseWalletScreen(
|
||||
chest: currentChestNumber, pin: _pin.toUpperCase());
|
||||
}),
|
||||
);
|
||||
switch (action) {
|
||||
case "mywallets":
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const WalletsHome();
|
||||
}),
|
||||
);
|
||||
break;
|
||||
case "changeWallet":
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return ChooseWalletScreen(
|
||||
chest: currentChestNumber, pin: _pin.toUpperCase());
|
||||
}),
|
||||
);
|
||||
break;
|
||||
case "pay":
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return ChooseWalletScreen(
|
||||
chest: currentChestNumber, pin: _pin.toUpperCase());
|
||||
}),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:gecko/globals.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/providers/cesium_plus.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
|
@ -23,11 +24,11 @@ class WalletViewScreen extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
WalletsProfilesProvider _historyProvider =
|
||||
WalletsProfilesProvider _walletViewProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
CesiumPlusProvider _cesiumPlusProvider =
|
||||
Provider.of<CesiumPlusProvider>(context, listen: false);
|
||||
_historyProvider.pubkey = pubkey!;
|
||||
_walletViewProvider.pubkey = pubkey!;
|
||||
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
|
@ -41,7 +42,8 @@ class WalletViewScreen extends StatelessWidget {
|
|||
),
|
||||
body: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
headerProfileView(context, _historyProvider, _cesiumPlusProvider),
|
||||
headerProfileView(
|
||||
context, _walletViewProvider, _cesiumPlusProvider),
|
||||
SizedBox(height: isTall ? 120 : 70),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
|
||||
Column(children: <Widget>[
|
||||
|
@ -163,7 +165,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
image: AssetImage('assets/vector_white.png'),
|
||||
)),
|
||||
onTap: () {
|
||||
paymentPopup(context, _historyProvider);
|
||||
paymentPopup(context, _walletViewProvider);
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
@ -182,11 +184,14 @@ class WalletViewScreen extends StatelessWidget {
|
|||
|
||||
void paymentPopup(
|
||||
BuildContext context, WalletsProfilesProvider _walletViewProvider) {
|
||||
// WalletsProfilesProvider _walletViewProvider =
|
||||
// Provider.of<WalletsProfilesProvider>(context);
|
||||
const double shapeSize = 20;
|
||||
WalletsProfilesProvider _walletViewProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||
// SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
|
||||
const double shapeSize = 20;
|
||||
WalletData? defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(configBox.get('currentChest'));
|
||||
_walletViewProvider.outputPubkey.text = pubkey!;
|
||||
|
@ -218,7 +223,8 @@ class WalletViewScreen extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
padding: const EdgeInsets.only(
|
||||
top: 24, bottom: 0, left: 24, right: 24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -230,86 +236,168 @@ class WalletViewScreen extends StatelessWidget {
|
|||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'Saisissez dans le champ ci-dessous le montant à virer.',
|
||||
'Depuis:',
|
||||
style: TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey[600]),
|
||||
),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Column(children: <Widget>[
|
||||
TextField(
|
||||
controller: _walletViewProvider.payAmount,
|
||||
autofocus: true,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (_) => setState(() {}),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d+\.?\d{0,2}')),
|
||||
],
|
||||
// onChanged: (v) => _searchProvider.rebuildWidget(),
|
||||
decoration: InputDecoration(
|
||||
hintText: '0.00',
|
||||
suffix: Text(currencyName),
|
||||
filled: true,
|
||||
fillColor: Colors.transparent,
|
||||
const SizedBox(height: 10),
|
||||
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return UnlockingWallet(
|
||||
wallet: defaultWallet, action: "pay");
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
// height: 25,
|
||||
decoration: BoxDecoration(
|
||||
// border: OutlineInputBorder(
|
||||
// borderSide:
|
||||
// BorderSide(color: Colors.grey[500], width: 2),
|
||||
// borderRadius: BorderRadius.circular(8)),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey[500]!, width: 2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(20),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 40,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w600,
|
||||
border: Border.all(
|
||||
color:
|
||||
Colors.grey[500]!, // Set border color
|
||||
width: 2), // Set border width
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(10.0)), // Set ro
|
||||
),
|
||||
padding: const EdgeInsets.all(10),
|
||||
|
||||
child: Row(children: [
|
||||
Text(defaultWallet!.name!),
|
||||
const Spacer(),
|
||||
FutureBuilder(
|
||||
future:
|
||||
_sub.getBalance(defaultWallet.address!),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<num?> _balance) {
|
||||
if (_balance.connectionState !=
|
||||
ConnectionState.done ||
|
||||
_balance.hasError) {
|
||||
if (balanceCache[
|
||||
defaultWallet.address!] !=
|
||||
null) {
|
||||
return Text(
|
||||
balanceCache[
|
||||
defaultWallet.address!]!,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
));
|
||||
} else {
|
||||
return SizedBox(
|
||||
height: 15,
|
||||
width: 15,
|
||||
child: CircularProgressIndicator(
|
||||
color: orangeC,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
balanceCache[defaultWallet.address!] =
|
||||
"${_balance.data.toString()} $currencyName";
|
||||
return Text(
|
||||
balanceCache[defaultWallet.address!]!,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
),
|
||||
);
|
||||
}),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
// const Spacer(),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 4,
|
||||
primary: orangeC, // background
|
||||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed:
|
||||
_walletViewProvider.payAmount.text != ''
|
||||
? () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return UnlockingWallet(
|
||||
wallet: defaultWallet,
|
||||
action: "pay");
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
: null,
|
||||
child: const Text(
|
||||
'Effectuer le virement',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
]),
|
||||
);
|
||||
}),
|
||||
const Spacer(),
|
||||
|
||||
// const SizedBox(height: 10),
|
||||
Text(
|
||||
'Montant:',
|
||||
style: TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey[600]),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TextField(
|
||||
controller: _walletViewProvider.payAmount,
|
||||
autofocus: true,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (_) => setState(() {
|
||||
// _walletViewProvider.reload();
|
||||
}),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d+\.?\d{0,2}')),
|
||||
],
|
||||
// onChanged: (v) => _searchProvider.rebuildWidget(),
|
||||
decoration: InputDecoration(
|
||||
hintText: '0.00',
|
||||
suffix: Text(currencyName),
|
||||
filled: true,
|
||||
fillColor: Colors.transparent,
|
||||
// border: OutlineInputBorder(
|
||||
// borderSide:
|
||||
// BorderSide(color: Colors.grey[500], width: 2),
|
||||
// borderRadius: BorderRadius.circular(8)),
|
||||
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey[500]!, width: 2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(20),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 40,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
// const SizedBox(height: 40),
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 4,
|
||||
primary: orangeC, // background
|
||||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed: _walletViewProvider.payAmount.text != ''
|
||||
? () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return UnlockingWallet(
|
||||
wallet: defaultWallet,
|
||||
action: "pay");
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
: null,
|
||||
child: const Text(
|
||||
'Effectuer le virement',
|
||||
style: TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
]),
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue