diff --git a/android/app/src/main/jniLibs/arm64-v8a/libpeaq_codec_api.so b/android/app/src/main/jniLibs/arm64-v8a/libpeaq_codec_api.so index 10d3934..1d6ab1b 100755 Binary files a/android/app/src/main/jniLibs/arm64-v8a/libpeaq_codec_api.so and b/android/app/src/main/jniLibs/arm64-v8a/libpeaq_codec_api.so differ diff --git a/android/app/src/main/jniLibs/armeabi-v7a/libpeaq_codec_api.so b/android/app/src/main/jniLibs/armeabi-v7a/libpeaq_codec_api.so index b5b992b..ff64ce0 100755 Binary files a/android/app/src/main/jniLibs/armeabi-v7a/libpeaq_codec_api.so and b/android/app/src/main/jniLibs/armeabi-v7a/libpeaq_codec_api.so differ diff --git a/android/app/src/main/jniLibs/x86_64/libpeaq_codec_api.so b/android/app/src/main/jniLibs/x86_64/libpeaq_codec_api.so index 72a413d..ce45ee7 100755 Binary files a/android/app/src/main/jniLibs/x86_64/libpeaq_codec_api.so and b/android/app/src/main/jniLibs/x86_64/libpeaq_codec_api.so differ diff --git a/lib/common/providers/charge_provider.dart b/lib/common/providers/charge_provider.dart index fa273bf..ce826fc 100644 --- a/lib/common/providers/charge_provider.dart +++ b/lib/common/providers/charge_provider.dart @@ -208,10 +208,9 @@ class CEVChargeProvider with ChangeNotifier { if (!walletCreated || multisigAddress.isEmpty) { setStatus(LoadingStatus.error, message: Env.creatingMultisigWalletFailed); + return; } - // print("generateAndFundMultisigWallet multisigAddress:: $multisigAddress"); - var token = (10 * pow(10, 19)); var seed = appProvider.accountProvider.account.seed!; @@ -225,6 +224,7 @@ class CEVChargeProvider with ChangeNotifier { if (resp.error!) { setStatus(LoadingStatus.error, message: resp.message!); + return; } await Future.delayed(const Duration(seconds: 3)); diff --git a/lib/common/providers/peer_provider.dart b/lib/common/providers/peer_provider.dart index eeaea5e..ad4a439 100644 --- a/lib/common/providers/peer_provider.dart +++ b/lib/common/providers/peer_provider.dart @@ -34,7 +34,7 @@ late final dylib = late final api = PeaqCodecApiImpl(dylib); void runPeriodically(void Function() callback) => - Timer.periodic(const Duration(milliseconds: 3000), (timer) => callback()); + Timer.periodic(const Duration(milliseconds: 1000), (timer) => callback()); class CEVPeerProvider with ChangeNotifier { CEVPeerProvider({ @@ -52,6 +52,7 @@ class CEVPeerProvider with ChangeNotifier { LoadingStatus _status = LoadingStatus.idle; String _error = ''; String _statusMessage = ''; + double _chargeProgress = 0; bool _isLoggedIn = false; bool _showNodeDropdown = false; List _details = []; @@ -70,6 +71,7 @@ class CEVPeerProvider with ChangeNotifier { bool get isPeerConnected => _isPeerConnected; bool get isPeerSubscribed => _isPeerSubscribed; String get multisigAddress => _multisigAddress; + double get chargeProgress => _chargeProgress; Future initLog() async { api.initLogger(); @@ -98,7 +100,10 @@ class CEVPeerProvider with ChangeNotifier { print("getEvent EVENT decodedRes $decodedRes"); - if (!decodedRes["error"]) { + // decode rust data data + var rData = CEVRustResponse.fromJson(decodedRes); + + if (!rData.error!) { // decode event data List docRawData = List.from(decodedRes["data"]); String docCharCode = String.fromCharCodes(docRawData); @@ -106,6 +111,7 @@ class CEVPeerProvider with ChangeNotifier { var ev = msg.Event(); ev.mergeFromBuffer(docOutputAsUint8List); + print("getEvent EVENT_ID ${ev.eventId.toString()}"); print("getEvent EVENT ev ${ev.toProto3Json()}"); switch (ev.eventId) { @@ -159,6 +165,12 @@ class CEVPeerProvider with ChangeNotifier { _authenticatePeer(ev.identityResponseData); break; } + case msg.EventType.CHARGING_STATUS: + { + _chargeProgress = ev.chargingStatusData.progress / 100; + notifyListeners(); + break; + } default: {} } @@ -262,16 +274,19 @@ class CEVPeerProvider with ChangeNotifier { var utf8Res = utf8.decode(data); var decodedRes = json.decode(utf8Res); - if (!decodedRes["error"]) { + // decode rust data data + var rData = CEVRustResponse.fromJson(decodedRes); + + if (!rData.error!) { // decode address data List docRawData = List.from(decodedRes["data"]); String addr = String.fromCharCodes(docRawData); _multisigAddress = addr; notifyListeners(); - return false; + return true; } - return true; + return false; } Future transferFund( diff --git a/lib/screens/charging_session.dart b/lib/screens/charging_session.dart index 6f4ddca..25a7537 100644 --- a/lib/screens/charging_session.dart +++ b/lib/screens/charging_session.dart @@ -1,5 +1,6 @@ import 'package:charmev/common/models/enum.dart'; import 'package:charmev/common/providers/charge_provider.dart'; +import 'package:charmev/common/providers/peer_provider.dart'; import 'package:charmev/common/widgets/loading_view.dart'; import 'package:charmev/common/widgets/status_card.dart'; import 'package:charmev/keys.dart'; @@ -111,6 +112,9 @@ class _CharginSessionScreenState extends State Widget _buildScreen(BuildContext context, CEVChargeProvider chargeProvider) { final boxW = MediaQuery.of(context).size.width / 1.2; + CEVPeerProvider peerProvider = CEVPeerProvider.of(context); + + print("charge progress:: ${peerProvider.chargeProgress}"); return SizedBox( height: double.infinity, @@ -122,32 +126,12 @@ class _CharginSessionScreenState extends State mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [ - chargeProvider.chargingStatus == LoadingStatus.charging - ? CEVCountdown( - maxCount: chargeProvider.totalTimeInSeconds, - onTimeout: () async { - var stopUrlSet = false; - if (stopUrlSet) { - chargeProvider.stopCharge(); - } - }, - displayChild: (counter) { - counter = (chargeProvider.counter + 1); - chargeProvider.updateTimer(counter); - - return CEVProgressCard( - progress: chargeProvider.progress, - child: _buildPump(context), - size: 172, - margin: const EdgeInsets.all(32), - ); - }) - : CEVProgressCard( - progress: chargeProvider.progress, - child: _buildPump(context), - size: 172, - margin: const EdgeInsets.all(32), - ), + CEVProgressCard( + progress: peerProvider.chargeProgress, + child: _buildPump(context), + size: 172, + margin: const EdgeInsets.all(32), + ), _buildDetails(boxW, chargeProvider), const SizedBox( height: 50.0, diff --git a/pubspec.lock b/pubspec.lock index 2ea29f7..c218d2d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -482,8 +482,8 @@ packages: dependency: "direct main" description: path: dart - ref: "0567eeb20e2709a4da5c870f61ed46ae466d0634" - resolved-ref: "0567eeb20e2709a4da5c870f61ed46ae466d0634" + ref: dev + resolved-ref: dbc42ef455480bc4049e09d572f51c465c1e71d5 url: "https://github.com/peaqnetwork/peaq-network-ev-charging-message-format.git" source: git version: "0.1.0" diff --git a/pubspec.yaml b/pubspec.yaml index 31aeebe..4525153 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,7 +57,7 @@ dependencies: git: url: https://github.com/peaqnetwork/peaq-network-ev-charging-message-format.git path: dart - ref: 0567eeb20e2709a4da5c870f61ed46ae466d0634 + ref: dev dev_dependencies: flutter_test: diff --git a/rust/src/chain.rs b/rust/src/chain.rs index c5dcec4..2b2d756 100644 --- a/rust/src/chain.rs +++ b/rust/src/chain.rs @@ -55,12 +55,19 @@ pub fn transfer( let to = sr25519::Public::from_str(&address.as_str()).unwrap(); let to = AccountId::decode(&mut &to.0[..]).unwrap_or_default(); + let from_account = AccountId::decode(&mut &from.public().0[..]).unwrap_or_default(); let mut former_balance: Balance = 0; - match api.get_account_data(&to).unwrap() { + if let Some(account) = api.get_account_data(&to).unwrap() { + former_balance = account.free; + } + + match api.get_account_data(&from_account).unwrap() { Some(account) => { - former_balance = account.free; + if account.free < amount { + return Some(ChainError::Error("Insufficient Funds".to_string())); + } } None => { return Some(ChainError::Error( diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 88848bc..be352c7 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -2,6 +2,7 @@ use codec::{Decode, Encode}; // use keyring::sr25519; use keyring::ed25519; use keyring::sr25519; +use log::trace; use sp_core::blake2_256; use sp_runtime::traits::Verify; pub use sp_runtime::{ @@ -24,12 +25,12 @@ pub fn create_multisig_account(consumer: &str, provider: &str) -> String { let who = &mut [consumer.as_bytes().to_vec(), provider.as_bytes().to_vec()]; // &who.sort(); - let entropy = (b"modlpy/utilisuba", &who[..], 2).using_encoded(blake2_256); - println!("entropy:: {:?}", &entropy); + let entropy = (b"modlpy/utilisuba", &who[..].sort(), 2).using_encoded(blake2_256); + trace!("entropy:: {:?}", &entropy); let multi = AccountId::decode(&mut &entropy[..]).unwrap_or_default(); - println!("MULTI:: {}", &multi); + trace!("MULTI:: {}", &multi); multi.to_string() }