This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
608 additions
and
434 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'bridge_helper.dart'; | ||
export 'bridge_functions_helper.dart'; |
152 changes: 152 additions & 0 deletions
152
lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_functions_helper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:datadashwallet/common/components/components.dart'; | ||
import 'package:datadashwallet/features/common/common.dart'; | ||
import 'package:datadashwallet/features/portfolio/subfeatures/token/add_token/domain/custom_tokens_use_case.dart'; | ||
import 'package:datadashwallet/features/settings/settings.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:mxc_logic/mxc_logic.dart'; | ||
|
||
import '../../../open_dapp.dart'; | ||
|
||
class BridgeFunctionsHelper { | ||
BridgeFunctionsHelper({ | ||
required this.state, | ||
required this.context, | ||
required this.translate, | ||
required this.navigator, | ||
required this.customTokensUseCase, | ||
required this.tokenContractUseCase, | ||
required this.transactionHistoryUseCase, | ||
required this.chainConfigurationUseCase, | ||
required this.addError, | ||
required this.loading, | ||
}); | ||
|
||
OpenDAppState state; | ||
TokenContractUseCase tokenContractUseCase; | ||
CustomTokensUseCase customTokensUseCase; | ||
TransactionsHistoryUseCase transactionHistoryUseCase; | ||
ChainConfigurationUseCase chainConfigurationUseCase; | ||
NavigatorState? navigator; | ||
BuildContext? context; | ||
String? Function(String) translate; | ||
void Function(bool v) loading; | ||
void Function(dynamic error, [StackTrace? stackTrace]) addError; | ||
|
||
Future<TransactionGasEstimation?> estimatedFee( | ||
String from, | ||
String to, | ||
EtherAmount? gasPrice, | ||
Uint8List data, | ||
BigInt? amountOfGas, | ||
) async { | ||
loading(true); | ||
try { | ||
final gasFee = await tokenContractUseCase.estimateGasFeeForContractCall( | ||
from: from, | ||
to: to, | ||
gasPrice: gasPrice, | ||
data: data, | ||
amountOfGas: amountOfGas); | ||
loading(false); | ||
|
||
return gasFee; | ||
} catch (e, s) { | ||
addError(e, s); | ||
} finally { | ||
loading(false); | ||
} | ||
} | ||
|
||
Future<String?> sendTransaction(String to, EtherAmount amount, | ||
Uint8List? data, TransactionGasEstimation? estimatedGasFee, String url, | ||
{String? from}) async { | ||
final res = await tokenContractUseCase.sendTransaction( | ||
privateKey: state.account!.privateKey, | ||
to: to, | ||
from: from, | ||
amount: amount, | ||
data: data, | ||
estimatedGasFee: estimatedGasFee); | ||
if (!MXCChains.isMXCChains(state.network!.chainId)) { | ||
recordTransaction(res); | ||
} | ||
|
||
return res.hash; | ||
} | ||
|
||
String? signMessage( | ||
String hexData, | ||
) { | ||
loading(true); | ||
try { | ||
final res = tokenContractUseCase.signMessage( | ||
privateKey: state.account!.privateKey, message: hexData); | ||
return res; | ||
} catch (e, s) { | ||
addError(e, s); | ||
} finally { | ||
loading(false); | ||
} | ||
} | ||
|
||
String? signTypedMessage( | ||
String hexData, | ||
) { | ||
loading(true); | ||
try { | ||
final res = tokenContractUseCase.signTypedMessage( | ||
privateKey: state.account!.privateKey, data: hexData); | ||
return res; | ||
} catch (e, s) { | ||
addError(e, s); | ||
} finally { | ||
loading(false); | ||
} | ||
} | ||
|
||
bool addAsset(Token token) { | ||
loading(true); | ||
try { | ||
customTokensUseCase.addItem(token); | ||
return true; | ||
} catch (error, stackTrace) { | ||
addError(error, stackTrace); | ||
return false; | ||
} finally { | ||
loading(false); | ||
} | ||
} | ||
|
||
void recordTransaction(TransactionModel tx) { | ||
final currentNetwork = state.network!; | ||
final chainId = currentNetwork.chainId; | ||
final token = Token( | ||
chainId: currentNetwork.chainId, | ||
logoUri: currentNetwork.logo, | ||
name: currentNetwork.label ?? currentNetwork.web3RpcHttpUrl, | ||
symbol: currentNetwork.symbol, | ||
address: null, | ||
); | ||
|
||
tx = tx.copyWith(token: token); | ||
|
||
transactionHistoryUseCase.spyOnTransaction( | ||
tx, | ||
); | ||
transactionHistoryUseCase.updateItem( | ||
tx, | ||
); | ||
} | ||
|
||
Network? updateNetwork(Network network, int index) { | ||
chainConfigurationUseCase.updateItem(network, index); | ||
return network; | ||
} | ||
|
||
Network? addNewNetwork(Network newNetwork) { | ||
chainConfigurationUseCase.addItem(newNetwork); | ||
return newNetwork; | ||
} | ||
} |
Oops, something went wrong.