Merge branch 'dev' into 'master'
activity screen: add gdev start time delimiter See merge request clients/gecko!43
This commit is contained in:
commit
42801f8145
|
@ -50,3 +50,6 @@ const debugPin = true;
|
||||||
String indexerEndpoint = '';
|
String indexerEndpoint = '';
|
||||||
late double balanceRatio;
|
late double balanceRatio;
|
||||||
late int udValue;
|
late int udValue;
|
||||||
|
|
||||||
|
// Indexer
|
||||||
|
late DateTime startBlockchainTime;
|
||||||
|
|
|
@ -87,3 +87,12 @@ query ($name: String!) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
|
|
||||||
|
const String getBlockchainStartQ = r'''
|
||||||
|
query {
|
||||||
|
block(limit: 1) {
|
||||||
|
created_at
|
||||||
|
number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
|
|
@ -446,7 +446,24 @@ class DuniterIndexer with ChangeNotifier {
|
||||||
// QueryResult<Object?> result, FetchMoreOptions options, String address) {}
|
// QueryResult<Object?> result, FetchMoreOptions options, String address) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// Manuals queries
|
||||||
|
|
||||||
Future<bool> isIdtyExist(String name) async {
|
Future<bool> isIdtyExist(String name) async {
|
||||||
|
final variables = <String, dynamic>{
|
||||||
|
'name': name,
|
||||||
|
};
|
||||||
|
final result = await _execQuery(isIdtyExistQ, variables);
|
||||||
|
return result.data!['identity']?.isEmpty ?? false ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<DateTime> getBlockStart() async {
|
||||||
|
final result = await _execQuery(getBlockchainStartQ, {});
|
||||||
|
startBlockchainTime = DateTime.parse(result.data!['block'][0]['created_at']);
|
||||||
|
return startBlockchainTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<QueryResult> _execQuery(
|
||||||
|
String query, Map<String, dynamic> variables) async {
|
||||||
final httpLink = HttpLink(
|
final httpLink = HttpLink(
|
||||||
'$indexerEndpoint/v1/graphql',
|
'$indexerEndpoint/v1/graphql',
|
||||||
);
|
);
|
||||||
|
@ -456,14 +473,8 @@ Future<bool> isIdtyExist(String name) async {
|
||||||
link: httpLink,
|
link: httpLink,
|
||||||
);
|
);
|
||||||
|
|
||||||
final QueryOptions options = QueryOptions(
|
final QueryOptions options =
|
||||||
document: gql(isIdtyExistQ),
|
QueryOptions(document: gql(query), variables: variables);
|
||||||
variables: <String, dynamic>{
|
|
||||||
'name': name,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
final QueryResult result = await client.query(options);
|
return await client.query(options);
|
||||||
|
|
||||||
return result.data!['identity']?.isEmpty ?? false ? false : true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
import 'package:gecko/models/chest_data.dart';
|
import 'package:gecko/models/chest_data.dart';
|
||||||
import 'package:gecko/models/wallet_data.dart';
|
import 'package:gecko/models/wallet_data.dart';
|
||||||
|
import 'package:gecko/providers/duniter_indexer.dart';
|
||||||
import 'package:gecko/providers/home.dart';
|
import 'package:gecko/providers/home.dart';
|
||||||
import 'package:gecko/providers/my_wallets.dart';
|
import 'package:gecko/providers/my_wallets.dart';
|
||||||
import 'package:gecko/providers/wallet_options.dart';
|
import 'package:gecko/providers/wallet_options.dart';
|
||||||
|
@ -383,6 +384,77 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
return estimateFees.partialFee / 100;
|
return estimateFees.partialFee / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int hexStringToUint16(String input) {
|
||||||
|
// Slice the string in 2-char substrings and parse it from hex to decimal
|
||||||
|
final bytes = sliceString(input, 2).map((s) => int.parse(s, radix: 16));
|
||||||
|
|
||||||
|
// Create a Uint8 from the 2-bytes list
|
||||||
|
final u8list = Uint8List.fromList(bytes.toList());
|
||||||
|
|
||||||
|
// Return a Uint16 little endian representation
|
||||||
|
return ByteData.view(u8list.buffer).getUint16(0, Endian.little);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> sliceString(String input, int count) {
|
||||||
|
if (input.isEmpty) return [];
|
||||||
|
|
||||||
|
if (input.length % count != 0) {
|
||||||
|
throw ArgumentError("Cannot slice $input in $count slices.");
|
||||||
|
}
|
||||||
|
// final slices = List<String>(count);
|
||||||
|
var slices = List<String>.filled(count, '');
|
||||||
|
|
||||||
|
int len = input.length;
|
||||||
|
int sliceSize = len ~/ count;
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
var start = i * sliceSize;
|
||||||
|
slices[i] = input.substring(start, start + sliceSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return List.unmodifiable(slices);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<DateFormat> getBlockchainStart() async {
|
||||||
|
////// Manu indexer
|
||||||
|
//// Extract block date. Ugly, I can't find a better way to get the date of the block ?
|
||||||
|
//// The only polkadot issue for that : https://github.com/polkadot-js/api/issues/2603
|
||||||
|
// const created_at = new Date(
|
||||||
|
// signedBlock.block.extrinsics
|
||||||
|
// .filter(
|
||||||
|
// ({ method: { section, method } }) =>
|
||||||
|
// section === 'timestamp' && method === 'set'
|
||||||
|
// )[0]
|
||||||
|
// .args[0].toNumber()
|
||||||
|
// )
|
||||||
|
//// manu rpc
|
||||||
|
// genesis: api.genesisHash.toHex(),
|
||||||
|
// chain: await api.rpc.chain.getHeader(),
|
||||||
|
// chainInfo: await api.registry.getChainProperties(),
|
||||||
|
// test: await api.rpc.state.getPairs('0x')
|
||||||
|
// query block finalisé qui ne change jamais.
|
||||||
|
// api.rpc.chain.subscribeFinalizedHeads
|
||||||
|
// events: await api.rpc.state.getStorage('0x26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7'),
|
||||||
|
// lastFinalizedBlock: await api.rpc.chain.getFinalizedHead()
|
||||||
|
// get block
|
||||||
|
// api.rpc.chain.getFinalizedHead
|
||||||
|
|
||||||
|
// shit
|
||||||
|
// final blockHash =
|
||||||
|
// await sdk.webView!.evalJavascript('api.rpc.chain.getBlockHash(1)');
|
||||||
|
// final Map blockContent = await sdk.webView!
|
||||||
|
// .evalJavascript('api.rpc.chain.getBlock("$blockHash")');
|
||||||
|
// final String dateBrut = blockContent['block']['extrinsics'][0];
|
||||||
|
|
||||||
|
// final dateTextByte = hex.decode(dateBrut.substring(2));
|
||||||
|
|
||||||
|
// final dateText = await sdk.webView!
|
||||||
|
// .evalJavascript('api.tx($dateTextByte)', wrapPromise: false);
|
||||||
|
|
||||||
|
// log.d('aaaaaaaaaaaaaaaaaaaaa: $dateText');
|
||||||
|
return DateFormat();
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
////// 3: SUBSTRATE CONNECTION //////
|
////// 3: SUBSTRATE CONNECTION //////
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
|
@ -403,7 +475,7 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> connectNode(BuildContext ctx) async {
|
Future<void> connectNode(BuildContext ctx) async {
|
||||||
HomeProvider homeProvider = Provider.of<HomeProvider>(ctx, listen: false);
|
final homeProvider = Provider.of<HomeProvider>(ctx, listen: false);
|
||||||
final myWalletProvider = Provider.of<MyWalletsProvider>(ctx, listen: false);
|
final myWalletProvider = Provider.of<MyWalletsProvider>(ctx, listen: false);
|
||||||
|
|
||||||
homeProvider.changeMessage("connectionPending".tr(), 0);
|
homeProvider.changeMessage("connectionPending".tr(), 0);
|
||||||
|
@ -448,6 +520,9 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
await initCurrencyParameters();
|
await initCurrencyParameters();
|
||||||
await getBalanceRatio();
|
await getBalanceRatio();
|
||||||
|
|
||||||
|
// Indexer
|
||||||
|
getBlockStart();
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
homeProvider.changeMessage(
|
homeProvider.changeMessage(
|
||||||
"wellConnectedToNode"
|
"wellConnectedToNode"
|
||||||
|
|
|
@ -34,6 +34,8 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier {
|
||||||
HomeProvider homeProvider =
|
HomeProvider homeProvider =
|
||||||
Provider.of<HomeProvider>(context, listen: false);
|
Provider.of<HomeProvider>(context, listen: false);
|
||||||
|
|
||||||
|
// log.d('aaaaaaaaaaaaaaaaaaaaa $startBlockchainTime');
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -196,6 +198,8 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier {
|
||||||
bool isTody = false;
|
bool isTody = false;
|
||||||
bool isYesterday = false;
|
bool isYesterday = false;
|
||||||
bool isThisWeek = false;
|
bool isThisWeek = false;
|
||||||
|
bool isMigrationTime = false;
|
||||||
|
bool isMigrationTimePassed = false;
|
||||||
|
|
||||||
final Map<int, String> monthsInYear = {
|
final Map<int, String> monthsInYear = {
|
||||||
1: "month1".tr(),
|
1: "month1".tr(),
|
||||||
|
@ -278,7 +282,25 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier {
|
||||||
finalAmount = '$amount $currencyName';
|
finalAmount = '$amount $currencyName';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isMigrationTimePassed && date.compareTo(startBlockchainTime) < 0) {
|
||||||
|
isMigrationTimePassed = true;
|
||||||
|
isMigrationTime = true;
|
||||||
|
} else {
|
||||||
|
isMigrationTime = false;
|
||||||
|
}
|
||||||
|
|
||||||
return Column(children: <Widget>[
|
return Column(children: <Widget>[
|
||||||
|
if (isMigrationTime)
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 30),
|
||||||
|
child: Text(
|
||||||
|
'Début de la ĞDev',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
),
|
||||||
if (dateDelimiter != null)
|
if (dateDelimiter != null)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 30),
|
padding: const EdgeInsets.symmetric(vertical: 30),
|
||||||
|
|
|
@ -32,6 +32,7 @@ class HeaderProfile extends StatelessWidget {
|
||||||
|
|
||||||
return Stack(children: <Widget>[
|
return Stack(children: <Widget>[
|
||||||
Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
||||||
|
// sub.getBlockchainStart();
|
||||||
bool isAccountExist = balanceCache[address] != 0;
|
bool isAccountExist = balanceCache[address] != 0;
|
||||||
return Container(
|
return Container(
|
||||||
height: 180,
|
height: 180,
|
||||||
|
|
|
@ -5,7 +5,7 @@ description: Pay with G1.
|
||||||
# pub.dev using `pub publish`. This is preferred for private packages.
|
# pub.dev using `pub publish`. This is preferred for private packages.
|
||||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
version: 0.0.12+37
|
version: 0.0.12+39
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
|
|
Loading…
Reference in New Issue