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

build: ⬆️ Upgrade web_socket #37

Merged
merged 2 commits into from
Dec 13, 2024
Merged
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: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
flutter 3.24.4-stable
flutter 3.24.5-stable
84 changes: 19 additions & 65 deletions lib/src/util/transaction_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ mixin TransactionMixin {
) {
return ArchethicTransactionSender(
apiService: apiService,
phoenixHttpEndpoint: '${apiService.endpoint}/socket/websocket',
websocketEndpoint:
'${apiService.endpoint.replaceAll('https:', 'wss:').replaceAll('http:', 'wss:')}/socket/websocket',
);
}

Expand All @@ -40,72 +37,29 @@ mixin TransactionMixin {
break;
}
var next = false;
String websocketEndpoint;
switch (apiService.endpoint) {
case 'https://mainnet.archethic.net':
case 'https://testnet.archethic.net':
websocketEndpoint =
"${apiService.endpoint.replaceAll('https:', 'wss:').replaceAll('http:', 'wss:')}/socket/websocket";
break;
default:
websocketEndpoint =
"${apiService.endpoint.replaceAll('https:', 'wss:').replaceAll('http:', 'ws:')}/socket/websocket";
break;
}

final transactionRepository = ArchethicTransactionSender(
apiService: apiService,
phoenixHttpEndpoint: '${apiService.endpoint}/socket/websocket',
websocketEndpoint: websocketEndpoint,
);
await transactionRepository.send(
transaction: transaction,
onConfirmation: (confirmation) async {
if (confirmation.isEnoughConfirmed) {
if (kDebugMode) {
sl.get<LogManager>().log(
'nbConfirmations: ${confirmation.nbConfirmations}, transactionAddress: ${confirmation.transactionAddress}, maxConfirmations: ${confirmation.maxConfirmations}',
level: LogLevel.debug,
name: 'TransactionDexMixin - sendTransactions',
);
}
transactionRepository.close();
next = true;
}
},
onError: (error) async {
transactionRepository.close();
error.maybeMap(
connectivity: (_) {
errorDetail = 'No connection';
},
consensusNotReached: (_) {
errorDetail = 'Consensus not reached';
},
timeout: (_) {
errorDetail = 'Timeout';
},
invalidConfirmation: (_) {
errorDetail = 'Invalid Confirmation';
},
insufficientFunds: (_) {
errorDetail = 'Insufficient funds';
},
other: (error) {
errorDetail = error.messageLabel;
if (error.data != null) {
final data = error.data! as Map<String, dynamic>;
if (data['data'] != null && data['data']['message'] != null) {
errorDetail = data['data']['message'];
}
try {
await transactionRepository.send(
transaction: transaction,
onConfirmation: (confirmation) async {
if (confirmation.isEnoughConfirmed) {
if (kDebugMode) {
sl.get<LogManager>().log(
'nbConfirmations: ${confirmation.nbConfirmations}, transactionAddress: ${confirmation.transactionAddress}, maxConfirmations: ${confirmation.maxConfirmations}',
level: LogLevel.debug,
name: 'TransactionDexMixin - sendTransactions',
);
}
},
orElse: () {
errorDetail = 'An error is occured';
},
);
},
);
transactionRepository.close();
next = true;
}
},
);
} catch (transactionError) {
errorDetail = transactionError.toString();
}

while (next == false && errorDetail.isEmpty) {
await Future.delayed(const Duration(seconds: 1));
Expand Down
Loading
Loading