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

CustomSettings Implementation #2949

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fb6c06c
- Removed static concept from CustomSettings and called the class dir…
Nov 15, 2022
f300667
- Removed static concept from CustomSettings and called the class dir…
Nov 16, 2022
b6f67f9
- Refactor the code.
Nov 16, 2022
58f61c3
- Removed old function for getting chains from JSON file and have add…
Nov 17, 2022
241cb05
- Removed static concept from CustomSettings and called the class dir…
Nov 15, 2022
8fcca67
- Removed static concept from CustomSettings and called the class dir…
Nov 16, 2022
09dcb9a
- Refactor the code.
Nov 16, 2022
b4a9012
- Removed old function for getting chains from JSON file and have add…
Nov 17, 2022
954f487
- Added Unit test for CustomSettings.
Nov 22, 2022
ed89002
Merge remote-tracking branch 'origin/2758-feature-customisation-json'…
Nov 22, 2022
f1415da
- Refactor the code.
Nov 22, 2022
e953f58
- Removed static concept from CustomSettings and called the class dir…
Nov 15, 2022
21b36d0
- Removed static concept from CustomSettings and called the class dir…
Nov 16, 2022
1c7a210
- Refactor the code.
Nov 16, 2022
7a3110f
- Removed old function for getting chains from JSON file and have add…
Nov 17, 2022
d552a0d
- Added Unit test for CustomSettings.
Nov 22, 2022
a83f68d
- Removed static concept from CustomSettings and called the class dir…
Nov 15, 2022
011f2ea
- Removed old function for getting chains from JSON file and have add…
Nov 17, 2022
37e002b
- Refactor the code.
Nov 22, 2022
14581b9
Merge remote-tracking branch 'origin/2758-feature-customisation-json'…
Nov 28, 2022
41c7a3e
- Resolved conflicts.
Nov 29, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.alphawallet.app;

import static com.alphawallet.app.assertions.Should.shouldSee;
import static com.alphawallet.app.steps.Steps.createNewWallet;
import static com.alphawallet.app.util.Helper.waitUntilLoaded;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

import com.alphawallet.app.util.Helper;

import org.junit.Test;

import java.io.File;
import java.net.URL;

public class CustomSettingsTest extends BaseE2ETest
{
private static File getFileFromPath(Object obj) {
keval-finimble marked this conversation as resolved.
Show resolved Hide resolved
ClassLoader classLoader = obj.getClass().getClassLoader();
assert classLoader != null;
URL resource = classLoader.getResource("assets/custom_view_settings.json");
return new File(resource.getPath());
}

@Test
public void fileObjectShouldNotBeNull() throws Exception {
keval-finimble marked this conversation as resolved.
Show resolved Hide resolved
File file = getFileFromPath(this);
assertThat(file, notNullValue());

createNewWallet();
Helper.wait(1);
shouldSee(R.id.back);
waitUntilLoaded();
}

}

41 changes: 41 additions & 0 deletions app/src/main/assets/custom_view_settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"exclusive_chains": [
{
"chain": 1
}
],
"locked_chains": [
{
"chain": 1
},
{
"chain": 4
},
{
"chain": 10
}
],
"locked_tokens": [
{
"tokenAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"tokenName": "USD Coin",
"tokenSymbol": "USDC",
"tokenDecimals": 6,
"isEnabled": true,
"chainId": 1
}
],
"dark_mode": false,
"isShowContractAddress": true,
"startupDelay": 0,
"imageOverride": 0,
"isHideDappBrowser": false,
"isHideTabBar": false,
"isHasDirectTransfer": true,
"isCanChangeWallets": true,
"isHideEIP681": false,
"isCanAddTokens": true,
"isShowManageTokens": true,
"isShowAllNetworks": false,
"getDecimalPlaces": 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.alphawallet.app.service.AnalyticsService;
import com.alphawallet.app.service.AnalyticsServiceType;
import com.alphawallet.app.service.AssetDefinitionService;
import com.alphawallet.app.service.CustomSettings;
import com.alphawallet.app.service.GasService;
import com.alphawallet.app.service.IPFSService;
import com.alphawallet.app.service.IPFSServiceType;
Expand Down Expand Up @@ -178,9 +179,9 @@ TokenRepositoryType provideTokenRepository(

@Singleton
@Provides
TokenLocalSource provideRealmTokenSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository)
TokenLocalSource provideRealmTokenSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository, CustomSettings customSettings)
{
return new TokensRealmSource(realmManager, ethereumNetworkRepository);
return new TokensRealmSource(realmManager, ethereumNetworkRepository, customSettings);
}

@Singleton
Expand All @@ -196,9 +197,10 @@ TokensService provideTokensServices(EthereumNetworkRepositoryType ethereumNetwor
TokenRepositoryType tokenRepository,
TickerService tickerService,
OpenSeaService openseaService,
AnalyticsServiceType analyticsService)
AnalyticsServiceType analyticsService,
CustomSettings customSettings)
{
return new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, openseaService, analyticsService);
return new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, openseaService, analyticsService, customSettings);
}

@Singleton
Expand Down Expand Up @@ -262,6 +264,13 @@ AssetDefinitionService providingAssetDefinitionServices(IPFSServiceType ipfsServ
return new AssetDefinitionService(ipfsService, ctx, notificationService, realmManager, tokensService, tls, alphaService);
}

@Singleton
@Provides
CustomSettings provideCustomSettings(@ApplicationContext Context context)
{
return new CustomSettings(context);
}

@Singleton
@Provides
KeyService provideKeyService(@ApplicationContext Context ctx, AnalyticsServiceType analyticsService)
Expand Down
166 changes: 0 additions & 166 deletions app/src/main/java/com/alphawallet/app/entity/CustomViewSettings.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
import com.alphawallet.app.R;
import com.alphawallet.app.entity.ContractLocator;
import com.alphawallet.app.entity.ContractType;
import com.alphawallet.app.entity.CustomViewSettings;
import com.alphawallet.app.entity.NetworkInfo;
import com.alphawallet.app.entity.Wallet;
import com.alphawallet.app.entity.tokens.Token;
import com.alphawallet.app.entity.tokens.TokenInfo;
import com.alphawallet.app.service.CustomSettings;
import com.alphawallet.app.util.Utils;
import com.alphawallet.token.entity.ChainSpec;
import com.google.gson.Gson;
Expand Down Expand Up @@ -850,7 +850,7 @@ public List<Long> getSelectedFilters(boolean isMainNet)
@Override
public Long getDefaultNetwork(boolean isMainNet)
{
return isMainNet ? CustomViewSettings.primaryChain : GOERLI_ID;
return isMainNet ? CustomSettings.primaryChain : GOERLI_ID;
}

@Override
Expand Down Expand Up @@ -1039,14 +1039,9 @@ public static List<ChainSpec> extraChains()
return null;
}

public static List<Long> addDefaultNetworks()
{
return CustomViewSettings.alwaysVisibleChains;
}

public static ContractLocator getOverrideToken()
{
return new ContractLocator("", CustomViewSettings.primaryChain, ContractType.ETHEREUM);
return new ContractLocator("", CustomSettings.primaryChain, ContractType.ETHEREUM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.util.Pair;

import com.alphawallet.app.entity.ContractType;
import com.alphawallet.app.entity.CustomViewSettings;
import com.alphawallet.app.entity.NetworkInfo;
import com.alphawallet.app.entity.Wallet;
import com.alphawallet.app.entity.nftassets.NFTAsset;
Expand All @@ -25,6 +24,7 @@
import com.alphawallet.app.repository.entity.RealmTokenMapping;
import com.alphawallet.app.repository.entity.RealmTokenTicker;
import com.alphawallet.app.service.AssetDefinitionService;
import com.alphawallet.app.service.CustomSettings;
import com.alphawallet.app.service.RealmManager;
import com.alphawallet.app.util.Utils;
import com.alphawallet.token.entity.ContractAddress;
Expand Down Expand Up @@ -62,10 +62,13 @@ public class TokensRealmSource implements TokenLocalSource {

private final RealmManager realmManager;
private final EthereumNetworkRepositoryType ethereumNetworkRepository;
private final CustomSettings customSettings;

public TokensRealmSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository) {
public TokensRealmSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository, CustomSettings customSettings)
{
this.realmManager = realmManager;
this.ethereumNetworkRepository = ethereumNetworkRepository;
this.customSettings = customSettings;
}

@Override
Expand Down Expand Up @@ -472,7 +475,7 @@ else if (!newBalance.equals(currentBalance) || !checkEthToken(realm, token))
}

if (!realmToken.isVisibilityChanged() && realmToken.isEnabled() && newBalance != null && newBalance.equals("0")
&& !(token.isEthereum() && CustomViewSettings.alwaysShow(token.tokenInfo.chainId)))
&& !(token.isEthereum() && customSettings.alwaysShow(token.tokenInfo.chainId)))
{
realm.executeTransaction(r -> {
realmToken.setEnabled(false);
Expand All @@ -481,7 +484,7 @@ else if (!newBalance.equals(currentBalance) || !checkEthToken(realm, token))
}
else if ((!realmToken.isVisibilityChanged() && !realmToken.isEnabled()) &&
(token.balance.compareTo(BigDecimal.ZERO) > 0 ||
(token.isEthereum() && CustomViewSettings.alwaysShow(token.tokenInfo.chainId) && !realmToken.isEnabled()))) // enable if base token should be showing
(token.isEthereum() && customSettings.alwaysShow(token.tokenInfo.chainId) && !realmToken.isEnabled()))) // enable if base token should be showing
{
realm.executeTransaction(r -> {
realmToken.setEnabled(true);
Expand All @@ -492,7 +495,7 @@ else if ((!realmToken.isVisibilityChanged() && !realmToken.isEnabled()) &&
else
{
balanceChanged = true;
if (token.isEthereum() && CustomViewSettings.alwaysShow(token.tokenInfo.chainId)) token.tokenInfo.isEnabled = true;
if (token.isEthereum() && customSettings.alwaysShow(token.tokenInfo.chainId)) token.tokenInfo.isEnabled = true;
//write token
realm.executeTransaction(r -> {
token.balance = balance;
Expand Down
Loading