Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

October #2083

Merged
merged 5 commits into from
Nov 8, 2023
Merged

October #2083

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/app/shared/constants/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ class Parameters {
static const String clientId = 'urn:altme:0001';
static const String clientSecret =
'urn:uuid:f2e1b84a-930b-4250-a6c6-f35cabf698c8';

static const int maxEntries = 3;
}
2 changes: 1 addition & 1 deletion lib/app/shared/constants/secure_storage_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SecureStorageKeys {
static const String enableCryptographicHolderBinding =
'enableCryptographicHolderBinding';
static const String enableScopeParameter = 'enableScopeParameter';
static const String isPreRegisteredWallet = 'isPreRegisteredWallet';
static const String useBasicClientAuthentication = 'isPreRegisteredWallet';
static const String clientId = 'clientId';
static const String clientSecret = 'clientSecret';

Expand Down
1 change: 1 addition & 0 deletions lib/app/shared/extension/extension.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'credential_status.dart';
export 'iterable_extension.dart';
export 'string_extension.dart';
export 'unit8List_extension.dart';
21 changes: 21 additions & 0 deletions lib/app/shared/extension/unit8List_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'dart:typed_data';

extension Uint8ListExtension on Uint8List {
Uint8List get filterPayload {
final tester = Uint8List.fromList([5, 1]);

if (length <= 6) {
return this;
}

if (this[0] != tester[0]) {
return this;
}

if (this[1] != tester[1]) {
return this;
}

return sublist(6);
}
}
195 changes: 107 additions & 88 deletions lib/dashboard/connection/operation/cubit/operation_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -458,122 +458,141 @@ class OperationCubit extends Cubit<OperationState> {
emit(state.copyWith(status: AppStatus.goBack));
}

String? rpcNodeUrlForTransaction;

Future<OperationsList> getBeaonOperationList({
required bool preCheckBalance,
}) async {
try {
log.i('getOperationList');
int retryCount = 0;
const maxRetries = Parameters.maxEntries;
while (retryCount < maxRetries) {
try {
log.i('getOperationList');

final BeaconRequest beaconRequest = beaconCubit.state.beaconRequest!;
final BeaconRequest beaconRequest = beaconCubit.state.beaconRequest!;

final CryptoAccountData? currentAccount = walletCubit
.getCryptoAccountData(beaconRequest.request!.sourceAddress!);
final CryptoAccountData? currentAccount = walletCubit
.getCryptoAccountData(beaconRequest.request!.sourceAddress!);

if (currentAccount == null) {
throw ResponseMessage(
message: ResponseString
.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER,
);
}
if (currentAccount == null) {
throw ResponseMessage(
message: ResponseString
.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER,
);
}

late String baseUrl;

late String baseUrl;
late String rpcNodeUrl;
final NetworkType? networkType = beaconRequest.request?.network?.type;

switch (beaconRequest.request!.network!.type!) {
case NetworkType.mainnet:
if (networkType == null) {
throw ResponseMessage(
message: ResponseString
.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER,
);
}

if (networkType == NetworkType.mainnet) {
baseUrl = TezosNetwork.mainNet().apiUrl;
final rpcNodeUrlList =
TezosNetwork.mainNet().rpcNodeUrl as List<String>;
rpcNodeUrl = rpcNodeUrlList[Random().nextInt(rpcNodeUrlList.length)];
case NetworkType.ghostnet:

rpcNodeUrlForTransaction ??=
rpcNodeUrlList[Random().nextInt(rpcNodeUrlList.length)];
} else if (networkType == NetworkType.ghostnet) {
baseUrl = TezosNetwork.ghostnet().apiUrl;
rpcNodeUrl = TezosNetwork.ghostnet().rpcNodeUrl as String;
case NetworkType.mondaynet:
case NetworkType.delphinet:
case NetworkType.edonet:
case NetworkType.florencenet:
case NetworkType.granadanet:
case NetworkType.hangzhounet:
case NetworkType.ithacanet:
case NetworkType.jakartanet:
case NetworkType.kathmandunet:
case NetworkType.custom:
rpcNodeUrlForTransaction =
TezosNetwork.ghostnet().rpcNodeUrl as String;
} else {
throw ResponseMessage(
message: ResponseString
.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER,
);
}

// TezartError also handles low balance

if (preCheckBalance) {
/// check xtz balance
log.i('checking xtz');
final int balance = await dioClient.get(
'$baseUrl/v1/accounts/${beaconRequest.request!.sourceAddress!}/balance',
) as int;
log.i('total xtz - $balance');
final formattedBalance = int.parse(
balance.toStringAsFixed(6).replaceAll('.', '').replaceAll(',', ''),
);
}

final amount = int.parse(beaconRequest.operationDetails!.first.amount!);
// TezartError also handles low balance

if (preCheckBalance) {
/// check xtz balance
log.i('checking xtz');
final int balance = await dioClient.get(
'$baseUrl/v1/accounts/${beaconRequest.request!.sourceAddress!}/balance',
) as int;
log.i('total xtz - $balance');
final formattedBalance = int.parse(
balance.toStringAsFixed(6).replaceAll('.', '').replaceAll(',', ''),
);

if (amount >= formattedBalance) {
emit(
state.copyWith(
message: StateMessage.error(
messageHandler: ResponseMessage(
message:
ResponseString.RESPONSE_STRING_transactionIsLikelyToFail,
final amount =
int.parse(beaconRequest.operationDetails!.first.amount!);

if (amount >= formattedBalance) {
emit(
state.copyWith(
message: StateMessage.error(
messageHandler: ResponseMessage(
message: ResponseString
.RESPONSE_STRING_transactionIsLikelyToFail,
),
),
),
),
);
);
}
}
}

final client = TezartClient(rpcNodeUrl);
final keystore =
keyGenerator.getKeystore(secretKey: currentAccount.secretKey);

final operationList = OperationsList(
source: keystore,
publicKey: keystore.publicKey,
rpcInterface: client.rpcInterface,
);
final client = TezartClient(rpcNodeUrlForTransaction!);
final keystore =
keyGenerator.getKeystore(secretKey: currentAccount.secretKey);

final List<Operation> operations = getBeaonOperation();
for (final element in operations) {
operationList.appendOperation(element);
}
final operationList = OperationsList(
source: keystore,
publicKey: keystore.publicKey,
rpcInterface: client.rpcInterface,
);

final isReveal = await client.isKeyRevealed(keystore.address);
if (!isReveal) {
operationList.prependOperation(RevealOperation());
}
log.i(
'publicKey: ${keystore.publicKey} '
'amount: ${state.amount} '
'networkFee: ${state.fee} '
'address: ${keystore.address} =>To address: '
'${beaconRequest.operationDetails!.first.destination!}',
);
final List<Operation> operations = getBeaonOperation();
for (final element in operations) {
operationList.appendOperation(element);
}

return operationList;
} catch (e, s) {
log.e('error : $e, s: $s');
if (e is MessageHandler) {
rethrow;
} else if (e is TezartNodeError) {
log.e('e: $e , metadata: ${e.metadata} , s: $s');
rethrow;
} else {
throw ResponseMessage(
message: ResponseString.RESPONSE_STRING_OPERATION_FAILED,
final isReveal = await client.isKeyRevealed(keystore.address);
if (!isReveal) {
operationList.prependOperation(RevealOperation());
}
log.i(
'publicKey: ${keystore.publicKey} '
'amount: ${state.amount} '
'networkFee: ${state.fee} '
'address: ${keystore.address} =>To address: '
'${beaconRequest.operationDetails!.first.destination!}',
);

return operationList;
} catch (e, s) {
log.e('error : $e, s: $s');
retryCount++;
log.i('retryCount: $retryCount');

if (e is MessageHandler) {
rethrow;
} else if (e is TezartNodeError) {
log.e('e: $e , metadata: ${e.metadata} , s: $s');
if (retryCount < maxRetries) {
await Future<void>.delayed(const Duration(seconds: 1));
} else {
rethrow;
}
} else {
throw ResponseMessage(
message: ResponseString.RESPONSE_STRING_OPERATION_FAILED,
);
}
}
}

throw ResponseMessage(
message: ResponseString.RESPONSE_STRING_OPERATION_FAILED,
);
}

List<Operation> getBeaonOperation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class SignPayloadCubit extends Cubit<SignPayloadState> {
encodedPayload = stringToHexPrefixedWith05(payload: payload);
signingType = SigningType.raw;
}
final bytes = hexToBytes(encodedPayload);
final bytes = hexToBytes(encodedPayload).filterPayload;

payloadMessage = utf8.decode(bytes, allowMalformed: true);

case ConnectionBridgeType.walletconnect:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class _SignPayloadViewState extends State<SignPayloadView> {
textAlign: TextAlign.left,
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: Sizes.spaceXLarge),
const SizedBox(height: Sizes.spaceXSmall),
Text(
message,
textAlign: TextAlign.left,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Oidc4vcSettingMenuView extends StatelessWidget {
const SubjectSyntaxTypeWidget(),
const CryptographicHolderBindingWidget(),
const ScopeParameterWidget(),
const PreRegisteredWalletWidget(),
const ClientAuthenticationWidget(),
DrawerItem(
title: l10n.clientMetadata,
onTap: () {
Expand Down
Loading