Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Permission bug & local data #189

Merged
merged 14 commits into from
Apr 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TransactionsHistoryUseCase extends ReactiveUseCase {
if (selectedNetwork != null) {
final chainId = selectedNetwork.chainId;
checkChainChange(chainId);
if (!Config.isMxcChains(chainId)) {
if (!MXCChains.isMXCChains(chainId)) {
checkForPendingTransactions();
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ class TransactionsHistoryUseCase extends ReactiveUseCase {
TransactionModel newPendingTransaction,
int chainId,
TransactionActions transactionActions) {
if (!Config.isMxcChains(chainId)) {
if (!MXCChains.isMXCChains(chainId)) {
newPendingTransaction =
newPendingTransaction.copyWith(action: transactionActions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void showReceiveBottomSheet(
VoidCallback onL3Tap,
void Function(String url) launchUrlInPlatformDefault,
bool showError) {
if (Config.isMxcChains(chainId)) {
if (MXCChains.isMXCChains(chainId)) {
showWalletAddressDialogMXCChains(
context: context,
walletAddress: walletAddress,
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/background_process/dapp_hooks_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DAppHooksService {
final wifiHooksEnabled = dappHooksData.wifiHooks.enabled;

// Make sure user is logged in
if (isLoggedIn && Config.isMxcChains(chainId) && serviceEnabled) {
if (isLoggedIn && MXCChains.isMXCChains(chainId) && serviceEnabled) {
await AXSNotification()
.setupFlutterNotifications(shouldInitFirebase: false);
await contextLessTranslationUseCase.setupTranslator();
Expand Down Expand Up @@ -76,7 +76,7 @@ class DAppHooksService {
final minerHooksTime = dappHooksData.minerHooks.time;
final selectedMiners = dappHooksData.minerHooks.selectedMiners;
// Make sure user is logged in
if (isLoggedIn && Config.isMxcChains(chainId) && minerHooksEnabled) {
if (isLoggedIn && MXCChains.isMXCChains(chainId) && minerHooksEnabled) {
await AXSNotification()
.setupFlutterNotifications(shouldInitFirebase: false);
await contextLessTranslationUseCase.setupTranslator();
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/background_process/notifications_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NotificationsService {
final serviceEnabled = periodicalCallData.serviceEnabled;

// Make sure user is logged in
if (isLoggedIn && Config.isMxcChains(chainId) && serviceEnabled) {
if (isLoggedIn && MXCChains.isMXCChains(chainId) && serviceEnabled) {
await AXSNotification()
.setupFlutterNotifications(shouldInitFirebase: false);
await contextLessTranslationUseCase.setupTranslator();
Expand Down
10 changes: 10 additions & 0 deletions lib/core/src/providers/providers_use_cases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ final Provider<GesturesInstructionUseCase> gesturesInstructionUseCaseProvider =
final Provider<TokenContractUseCase> tokenContractUseCaseProvider = Provider(
(ref) => TokenContractUseCase(
ref.watch(web3RepositoryProvider),
ref.watch(chainConfigurationUseCaseProvider),
ref.watch(accountUseCaseProvider),
ref.watch(functionUseCaseProvider),
),
);

Expand Down Expand Up @@ -242,3 +245,10 @@ final Provider<MXCWebsocketUseCase> mxcWebsocketUseCaseProvider = Provider(
ref.watch(functionUseCaseProvider),
),
);

final Provider<IPFSUseCase> ipfsUseCaseProvider = Provider(
(ref) => IPFSUseCase(
ref.watch(web3RepositoryProvider),
ref.watch(chainConfigurationUseCaseProvider),
),
);
8 changes: 8 additions & 0 deletions lib/features/common/app/function_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class FunctionUseCase extends ReactiveUseCase {
}
}

void mxcChainsAndEthereumFuncWrapper(
Function func,
) {
if (_chainConfigurationUseCase.isMXCChains() || _chainConfigurationUseCase.isEthereumMainnet()) {
func();
}
}

void chainsFuncWrapper(Function mxcChainsFunc, Function noneMXCChainsFunc) {
if (_chainConfigurationUseCase.isMXCChains()) {
mxcChainsFunc();
Expand Down
9 changes: 1 addition & 8 deletions lib/features/common/app/launcher_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,7 @@ class LauncherUseCase extends ReactiveUseCase {
}

String? getNftMarketPlaceUrl() {
final enabledNetwork = _chainConfigurationUseCase.selectedNetwork.value!;
if (enabledNetwork.chainId == Config.mxcTestnetChainId) {
return Urls.mxcTestnetNftMarketPlace;
} else if (enabledNetwork.chainId == Config.mxcMainnetChainId) {
return Urls.mxcMainnetNftMarketPlace;
} else {
return null;
}
return _repository.launcherRepository.getNftMarketPlaceUrl();
}

Future<void> launchEmailApp() async {
Expand Down
1 change: 1 addition & 0 deletions lib/features/common/contract/contract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export 'pricing_use_case.dart';
export 'token_contract_use_case.dart';
export 'transaction_controller.dart';
export 'tweets_use_case.dart';
export 'ipfs_gateway_use_case.dart';
85 changes: 85 additions & 0 deletions lib/features/common/contract/ipfs_gateway_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'dart:async';

import 'package:datadashwallet/common/common.dart';
import 'package:datadashwallet/core/core.dart';
import 'package:datadashwallet/features/settings/settings.dart';
import 'package:mxc_logic/mxc_logic.dart';

class IPFSUseCase extends ReactiveUseCase {
IPFSUseCase(this._repository, this._chainConfigurationUseCase) {
initializeIpfsGateways();
}

final Web3Repository _repository;
final ChainConfigurationUseCase _chainConfigurationUseCase;

void initializeIpfsGateways() async {
processIpfsGatewayListLocal();
Utils.retryFunction(processIpfsGatewayList);
}

Future<void> processIpfsGatewayListLocal() async =>
checkIpfsGatewaysWrapper(getIpfsGateWaysLocal);

Future<void> processIpfsGatewayList() async =>
checkIpfsGatewaysWrapper(getIpfsGateWays);

Future<List<String>> getDefaultIpfsGateWaysLocal() async =>
getDefaultIpfsGateWaysWrapper(
_repository.ipfsRepository.getDefaultIpfsGatewaysFromLocal);

Future<List<String>> getDefaultIpfsGateWays() async =>
getDefaultIpfsGateWaysWrapper(
_repository.ipfsRepository.getDefaultIpfsGateways);

Future<List<String>> getDefaultIpfsGateWaysWrapper(
Future<DefaultIpfsGateways> Function() function) async {
final result = await function();
final List<String> list = [];

list.addAll(result.gateways ?? []);

return list;
}

Future<bool> checkIpfsGatewayStatus(String url) async {
return await _repository.ipfsRepository.checkIpfsGateway(url);
}

Future<List<String>?> getIpfsGateWaysLocal() async {
final newList = await getDefaultIpfsGateWaysLocal();
_chainConfigurationUseCase.updateIpfsGateWayList(newList);

return newList;
}

Future<List<String>?> getIpfsGateWays() async {
final newList = await getDefaultIpfsGateWays();
_chainConfigurationUseCase.updateIpfsGateWayList(newList);

return newList;
}

void checkIpfsGatewaysWrapper(
Future<List<String>?> Function() function) async {
final List<String>? list = await function();

if (list != null) {
checkIpfsGateways(list);
} else {
throw 'Error while retrieving ipfs gateway list!';
}
}

void checkIpfsGateways(List<String> list) async {
for (int i = 0; i < list.length; i++) {
final cUrl = list[i];
final response = await checkIpfsGatewayStatus(cUrl);

if (response != false) {
_chainConfigurationUseCase.changeIpfsGateWay(cUrl);
break;
}
}
}
}
15 changes: 0 additions & 15 deletions lib/features/common/contract/nft_contract_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,4 @@ class NftContractUseCase extends ReactiveUseCase {
) async {
return await _repository.nftContract.getNftsByAddress(address);
}

Future<List<String>> getDefaultIpfsGateWays() async {
final result = await _repository.nftContract.getDefaultIpfsGateways();
final List<String> list = [];

if (result != null) {
list.addAll(result.gateways ?? []);
}

return list;
}

Future<bool> checkIpfsGatewayStatus(String url) async {
return await _repository.nftContract.checkIpfsGateway(url);
}
}
53 changes: 44 additions & 9 deletions lib/features/common/contract/token_contract_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:datadashwallet/common/common.dart';
import 'package:datadashwallet/core/core.dart';
import 'package:datadashwallet/features/common/common.dart';
import 'package:datadashwallet/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart';
import 'package:flutter/services.dart';
import 'package:mxc_logic/mxc_logic.dart';
import 'package:web3dart/web3dart.dart';
Expand All @@ -16,9 +17,39 @@ extension Unique<E, T> on List<E> {
class TokenContractUseCase extends ReactiveUseCase {
TokenContractUseCase(
this._repository,
);
this._chainConfigurationUseCase,
this._accountUseCase,
this._functionUseCase,
) {
initListeners();
}

void initListeners() {
_accountUseCase.account.listen((v) {
account = v;
});

_chainConfigurationUseCase.selectedNetwork.listen((v) {
if (v != null) {
_functionUseCase.mxcChainsAndEthereumFuncWrapper(
() => loadLocalTokenList(v.chainId));
}
});
}

void loadLocalTokenList(int chainId) async {
final stringData = await MXCFileHelpers.getTokenList(chainId);
DefaultTokens data =
DefaultTokens.fromJson(stringData).changeAssetsRemoteToLocal();
getDefaultTokens(account!.address, defaultTokens: data);
}

final Web3Repository _repository;
final ChainConfigurationUseCase _chainConfigurationUseCase;
final AccountUseCase _accountUseCase;
final FunctionUseCase _functionUseCase;

Account? account;

late final ValueStream<bool> online = reactive(false);

Expand Down Expand Up @@ -55,10 +86,12 @@ class TokenContractUseCase extends ReactiveUseCase {
.getTokenTransfersByAddress(address, TokenType.erc_20);
}

Future<List<Token>> getDefaultTokens(String walletAddress) async {
Future<List<Token>> getDefaultTokens(String walletAddress,
{DefaultTokens? defaultTokens}) async {
final result =
defaultTokens ?? await _repository.tokenContract.getDefaultTokens();
tokensList.value.clear();
tokensList.value.addAll(customTokenList);
final result = await _repository.tokenContract.getDefaultTokens();

final cNetwork = _repository.tokenContract.getCurrentNetwork();

Expand Down Expand Up @@ -176,11 +209,13 @@ class TokenContractUseCase extends ReactiveUseCase {
customTokenList = customTokens;
update(tokensList, tokensList.value);

getTokensBalance(
customTokens,
walletAddress,
shouldGetPrice,
);
if (customTokenList.isNotEmpty) {
getTokensBalance(
customTokens,
walletAddress,
shouldGetPrice,
);
}
}

Future<EtherAmount> getGasPrice() async =>
Expand Down
14 changes: 13 additions & 1 deletion lib/features/common/contract/tweets_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ import 'package:mxc_logic/mxc_logic.dart';
class TweetsUseCase extends ReactiveUseCase {
TweetsUseCase(
this._repository,
);
) {
initTweetsList();
}

final Web3Repository _repository;
late final ValueStream<DefaultTweets?> defaultTweets = reactive(null);

void initTweetsList() async {
final data = await getDefaultTweetsLocal();
update(defaultTweets, data);
}

Future<DefaultTweets> getDefaultTweetsLocal() async {
return await _repository.tweetsRepository.getDefaultTweetsLocal();
}

Future<DefaultTweets> getDefaultTweets() async {
return await _repository.tweetsRepository.getDefaultTweets();
Expand Down
9 changes: 8 additions & 1 deletion lib/features/dapps/domain/dapp_store_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import 'package:mxc_logic/mxc_logic.dart';
class DappStoreUseCase extends ReactiveUseCase {
DappStoreUseCase(
this._repository,
);
) {
loadLocalDApps();
}

final Web3Repository _repository;

late final ValueStream<List<Dapp>> dapps = reactive([]);

loadLocalDApps() async {
final result = await _repository.dappStoreRepository.getAllDappsFromLocal();
update(dapps, result);
}

Future<void> getAllDapps() async {
final result = await _repository.dappStoreRepository.getAllDapps();

Expand Down
Loading
Loading