Skip to content

Commit

Permalink
Added more helper functions test
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed May 14, 2024
1 parent 473db15 commit ffd39e8
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 8 deletions.
9 changes: 6 additions & 3 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2156,16 +2156,19 @@ String? getWalletAddress(CredentialSubjectModel credentialSubjectModel) {
return null;
}

Future<String> fetchRpcUrl(BlockchainNetwork blockchainNetwork) async {
Future<String> fetchRpcUrl({
required BlockchainNetwork blockchainNetwork,
required DotEnv dotEnv,
}) async {
String rpcUrl = '';

if (blockchainNetwork is BinanceNetwork ||
blockchainNetwork is FantomNetwork) {
rpcUrl = blockchainNetwork.rpcNodeUrl as String;
} else {
if (blockchainNetwork.networkname == 'Mainnet') {
await dotenv.load();
final String infuraApiKey = dotenv.get('INFURA_API_KEY');
await dotEnv.load();
final String infuraApiKey = dotEnv.get('INFURA_API_KEY');

late String prefixUrl;

Expand Down
11 changes: 8 additions & 3 deletions lib/dashboard/connection/operation/cubit/operation_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ class OperationCubit extends Cubit<OperationState> {
walletConnectCubit.state.transaction!.value!;
amount = MWeb3Client.formatEthAmount(amount: ethAmount.getInWei);

final web3RpcURL =
await fetchRpcUrl(manageNetworkCubit.state.network);
final web3RpcURL = await fetchRpcUrl(
blockchainNetwork: manageNetworkCubit.state.network,
dotEnv: dotenv,
);
log.i('web3RpcURL - $web3RpcURL');

final (_, _, feeData) = await MWeb3Client.estimateEVMFee(
Expand Down Expand Up @@ -356,7 +358,10 @@ class OperationCubit extends Cubit<OperationState> {
final EtherAmount ethAmount =
walletConnectCubit.state.transaction!.value!;

final rpcUrl = await fetchRpcUrl(manageNetworkCubit.state.network);
final rpcUrl = await fetchRpcUrl(
blockchainNetwork: manageNetworkCubit.state.network,
dotEnv: dotenv,
);

log.i('rpcUrl - $rpcUrl');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ class ConfirmTokenTransactionCubit extends Cubit<ConfirmTokenTransactionState> {
final sender = credentials.address;
final reciever = EthereumAddress.fromHex(state.withdrawalAddress);

final web3RpcURL = await fetchRpcUrl(manageNetworkCubit.state.network);
final web3RpcURL = await fetchRpcUrl(
blockchainNetwork: manageNetworkCubit.state.network,
dotEnv: dotenv,
);

final (maxGas, priceOfGas, feeData) = await MWeb3Client.estimateEVMFee(
web3RpcURL: web3RpcURL,
Expand Down Expand Up @@ -424,7 +427,10 @@ class ConfirmTokenTransactionCubit extends Cubit<ConfirmTokenTransactionState> {
} else {
final selectedEthereumNetwork = manageNetworkCubit.state.network;

final chainRpcUrl = await fetchRpcUrl(manageNetworkCubit.state.network);
final chainRpcUrl = await fetchRpcUrl(
blockchainNetwork: manageNetworkCubit.state.network,
dotEnv: dotenv,
);

await _sendContractInvocationOperationEVM(
tokenAmount: state.totalAmount,
Expand Down
Loading

0 comments on commit ffd39e8

Please sign in to comment.