Skip to content

Commit

Permalink
Fix for token send and tidy up code
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Feb 19, 2024
1 parent c18d4ec commit 5ea7b3b
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,8 @@ public interface PreferenceRepositoryType
boolean isPostNotificationsPermissionRequested(String address);

void setPostNotificationsPermissionRequested(String address, boolean hasRequested);

boolean getUseTSViewer();

void setUseTSViewer(boolean toggleState);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SharedPreferenceRepository implements PreferenceRepositoryType {
public static final String HIDE_ZERO_BALANCE_TOKENS = "hide_zero_balance_tokens";
public static final String FULL_SCREEN_STATE = "full_screen";
public static final String EXPERIMENTAL_1559_TX = "ex_1559_tx";
public static final String USE_TOKENSCRIPT_VIEWER = "use_ts_viewer";
public static final String DEVELOPER_OVERRIDE = "developer_override";
public static final String TESTNET_ENABLED = "testnet_enabled";
public static final String PRICE_ALERTS = "price_alerts";
Expand Down Expand Up @@ -469,10 +470,23 @@ public boolean isPostNotificationsPermissionRequested(String address) {
}

@Override
public void setPostNotificationsPermissionRequested(String address, boolean hasRequested) {
public void setPostNotificationsPermissionRequested(String address, boolean hasRequested)
{
pref.edit().putBoolean(getAddressKey(POST_NOTIFICATIONS_PERMISSION_REQUESTED, address), hasRequested).apply();
}

@Override
public boolean getUseTSViewer()
{
return pref.getBoolean(USE_TOKENSCRIPT_VIEWER, true);

Check warning on line 481 in app/src/main/java/com/alphawallet/app/repository/SharedPreferenceRepository.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/repository/SharedPreferenceRepository.java#L481

Added line #L481 was not covered by tests
}

@Override
public void setUseTSViewer(boolean state)
{
pref.edit().putBoolean(USE_TOKENSCRIPT_VIEWER, state).apply();
}

Check warning on line 488 in app/src/main/java/com/alphawallet/app/repository/SharedPreferenceRepository.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/repository/SharedPreferenceRepository.java#L487-L488

Added lines #L487 - L488 were not covered by tests

@NonNull
private String getAddressKey(String key, String address)
{
Expand Down
148 changes: 81 additions & 67 deletions app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class AdvancedSettingsActivity extends BaseActivity
private SettingsItemView analytics;
private SettingsItemView crashReporting;
private SettingsItemView developerOverride;
private SettingsItemView tokenScriptViewer;
private AWalletAlertDialog waitDialog = null;

@Nullable
Expand All @@ -57,7 +58,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
viewModel = new ViewModelProvider(this)
.get(AdvancedSettingsViewModel.class);
.get(AdvancedSettingsViewModel.class);

Check warning on line 61 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L61

Added line #L61 was not covered by tests

setContentView(R.layout.activity_generic_settings);
toolbar();
Expand All @@ -82,68 +83,74 @@ public void onDestroy()
private void initializeSettings()
{
nodeStatus = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_node_status)
.withTitle(R.string.action_node_status)
.withListener(this::onNodeStatusClicked)
.build();
.withIcon(R.drawable.ic_settings_node_status)
.withTitle(R.string.action_node_status)
.withListener(this::onNodeStatusClicked)
.build();

Check warning on line 89 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L86-L89

Added lines #L86 - L89 were not covered by tests

console = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_console)
.withTitle(R.string.title_console)
.withListener(this::onConsoleClicked)
.build();
.withIcon(R.drawable.ic_settings_console)
.withTitle(R.string.title_console)
.withListener(this::onConsoleClicked)
.build();

Check warning on line 95 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L92-L95

Added lines #L92 - L95 were not covered by tests

clearBrowserCache = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_cache)
.withTitle(R.string.title_clear_browser_cache)
.withListener(this::onClearBrowserCacheClicked)
.build();
.withIcon(R.drawable.ic_settings_cache)
.withTitle(R.string.title_clear_browser_cache)
.withListener(this::onClearBrowserCacheClicked)
.build();

Check warning on line 101 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L98-L101

Added lines #L98 - L101 were not covered by tests

tokenScript = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_tokenscript)
.withTitle(R.string.title_tokenscript)
.withListener(this::onTokenScriptClicked)
.build();
.withIcon(R.drawable.ic_settings_tokenscript)
.withTitle(R.string.title_tokenscript)
.withListener(this::onTokenScriptClicked)
.build();

Check warning on line 107 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L104-L107

Added lines #L104 - L107 were not covered by tests

//TODO Change Icon
tokenScriptManagement = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_tokenscript_manage)
.withTitle(R.string.tokenscript_management)
.withListener(this::onTokenScriptManagementClicked)
.build();
.withIcon(R.drawable.ic_settings_tokenscript_manage)
.withTitle(R.string.tokenscript_management)
.withListener(this::onTokenScriptManagementClicked)
.build();

Check warning on line 114 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L111-L114

Added lines #L111 - L114 were not covered by tests

tokenScriptViewer = new SettingsItemView.Builder(this)
.withType(SettingsItemView.Type.TOGGLE)
.withIcon(R.drawable.ic_tokenscript)
.withTitle(R.string.use_tokenscript_viewer)
.withListener(this::onUseTokenScriptViewer)
.build();

Check warning on line 121 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L116-L121

Added lines #L116 - L121 were not covered by tests

fullScreenSettings = new SettingsItemView.Builder(this)
.withType(SettingsItemView.Type.TOGGLE)
.withIcon(R.drawable.ic_phoneicon)
.withTitle(R.string.fullscreen)
.withListener(this::onFullScreenClicked)
.build();
.withType(SettingsItemView.Type.TOGGLE)
.withIcon(R.drawable.ic_phoneicon)
.withTitle(R.string.fullscreen)
.withListener(this::onFullScreenClicked)
.build();

Check warning on line 128 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L124-L128

Added lines #L124 - L128 were not covered by tests

refreshTokenDatabase = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_reset_tokens)
.withTitle(R.string.title_reload_token_data)
.withListener(this::onReloadTokenDataClicked)
.build();
.withIcon(R.drawable.ic_settings_reset_tokens)
.withTitle(R.string.title_reload_token_data)
.withListener(this::onReloadTokenDataClicked)
.build();

Check warning on line 134 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L131-L134

Added lines #L131 - L134 were not covered by tests

eip1559Transactions = new SettingsItemView.Builder(this)
.withType(SettingsItemView.Type.TOGGLE)
.withIcon(R.drawable.ic_icons_settings_1559)
.withTitle(R.string.experimental_1559)
// .withSubtitle(R.string.experimental_1559_tx_sub)
.withListener(this::on1559TransactionsClicked)
.build();
.withType(SettingsItemView.Type.TOGGLE)
.withIcon(R.drawable.ic_icons_settings_1559)
.withTitle(R.string.experimental_1559)
.withListener(this::on1559TransactionsClicked)
.build();

Check warning on line 141 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L137-L141

Added lines #L137 - L141 were not covered by tests

analytics = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_analytics)
.withTitle(R.string.settings_title_analytics)
.withListener(this::onAnalyticsClicked)
.build();
.withIcon(R.drawable.ic_settings_analytics)
.withTitle(R.string.settings_title_analytics)
.withListener(this::onAnalyticsClicked)
.build();

Check warning on line 147 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L144-L147

Added lines #L144 - L147 were not covered by tests

crashReporting = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_crash_reporting)
.withTitle(R.string.settings_title_crash_reporting)
.withListener(this::onCrashReportingClicked)
.build();
.withIcon(R.drawable.ic_settings_crash_reporting)
.withTitle(R.string.settings_title_crash_reporting)
.withListener(this::onCrashReportingClicked)
.build();

Check warning on line 153 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L150-L153

Added lines #L150 - L153 were not covered by tests

developerOverride = new SettingsItemView.Builder(this)
.withType(SettingsItemView.Type.TOGGLE)
Expand All @@ -155,6 +162,7 @@ private void initializeSettings()
fullScreenSettings.setToggleState(viewModel.getFullScreenState());
eip1559Transactions.setToggleState(viewModel.get1559TransactionsState());
developerOverride.setToggleState(viewModel.getDeveloperOverrideState());
tokenScriptViewer.setToggleState(viewModel.getTokenScriptViewerState());

Check warning on line 165 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L165

Added line #L165 was not covered by tests
}

private void onDeveloperOverride()
Expand All @@ -172,6 +180,11 @@ private void on1559TransactionsClicked()
viewModel.toggle1559Transactions(eip1559Transactions.getToggleState());
}

private void onUseTokenScriptViewer()
{
viewModel.toggleUseViewer(tokenScriptViewer.getToggleState());
}

Check warning on line 186 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L185-L186

Added lines #L185 - L186 were not covered by tests

private void addSettingsToLayout()
{
LinearLayout advancedSettingsLayout = findViewById(R.id.layout);
Expand All @@ -186,6 +199,7 @@ private void addSettingsToLayout()
advancedSettingsLayout.addView(fullScreenSettings);
advancedSettingsLayout.addView(refreshTokenDatabase);
advancedSettingsLayout.addView(eip1559Transactions);
advancedSettingsLayout.addView(tokenScriptViewer);

Check warning on line 202 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L202

Added line #L202 was not covered by tests
advancedSettingsLayout.addView(analytics);
advancedSettingsLayout.addView(crashReporting);
advancedSettingsLayout.addView(developerOverride);
Expand All @@ -204,25 +218,25 @@ private void onConsoleClicked()
private void onClearBrowserCacheClicked()
{
Single.fromCallable(() ->
{
WebView webView = new WebView(this);
webView.clearCache(true);
webView.clearFormData();
webView.clearHistory();
webView.clearSslPreferences();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookies(null);
WebStorage.getInstance().deleteAllData();
viewModel.blankFilterSettings();
Glide.get(this).clearDiskCache();
return 1;
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(v ->
{
Toast.makeText(this, getString(R.string.toast_browser_cache_cleared), Toast.LENGTH_SHORT).show();
finish();
}).isDisposed();
{
WebView webView = new WebView(this);
webView.clearCache(true);
webView.clearFormData();
webView.clearHistory();
webView.clearSslPreferences();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookies(null);
WebStorage.getInstance().deleteAllData();
viewModel.blankFilterSettings();
Glide.get(this).clearDiskCache();
return 1;
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(v ->

Check warning on line 235 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L222-L235

Added lines #L222 - L235 were not covered by tests
{
Toast.makeText(this, getString(R.string.toast_browser_cache_cleared), Toast.LENGTH_SHORT).show();
finish();
}).isDisposed();

Check warning on line 239 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L237-L239

Added lines #L237 - L239 were not covered by tests
}

private void onReloadTokenDataClicked()
Expand All @@ -242,9 +256,9 @@ private void onReloadTokenDataClicked()
viewModel.stopChainActivity();
showWaitDialog();
clearTokenCache = viewModel.resetTokenData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::showResetResult);
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::showResetResult);

Check warning on line 261 in app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java#L259-L261

Added lines #L259 - L261 were not covered by tests

viewModel.blankFilterSettings();
});
Expand Down Expand Up @@ -340,7 +354,7 @@ private void askWritePermission()
private boolean checkWritePermission()
{
return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
== PackageManager.PERMISSION_GRANTED;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public class NFTAssetDetailActivity extends BaseActivity implements StandardFunc
private boolean triggeredReload;
private long chainId;
private Web3TokenView tokenScriptView;
private static final boolean FORCE_EMBEDDED_VIEWER = true;
private boolean useNativeTokenScript = false;
private boolean usingNativeTokenScript = false;

Check warning on line 117 in app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java#L117

Added line #L117 was not covered by tests

@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
Expand Down Expand Up @@ -291,7 +290,7 @@ private void handleShortCut(String walletAddress)
token = viewModel.getTokensService().getToken(walletAddress, chainId, tokenAddress);
if (token == null)
{
ShortcutUtils.showConfirmationDialog(this, singletonList(tokenAddress), getString(R.string.remove_shortcut_while_token_not_found));
ShortcutUtils.showConfirmationDialog(this, singletonList(tokenAddress), getString(R.string.remove_shortcut_while_token_not_found), null);

Check warning on line 293 in app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java#L293

Added line #L293 was not covered by tests
}
else
{
Expand All @@ -307,9 +306,10 @@ private void setup()
setTitle(token.tokenInfo.name);
updateDefaultTokenData();

if (!NFTAssetDetailActivity.FORCE_EMBEDDED_VIEWER) {
if (!viewModel.getUseTSViewer())
{
TokenDefinition td = viewModel.getAssetDefinitionService().getAssetDefinition(this.token);

Check warning on line 311 in app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java#L311

Added line #L311 was not covered by tests
this.useNativeTokenScript = td.nameSpace != null;
this.usingNativeTokenScript = td.nameSpace != null;
}

if (asset != null && asset.isAttestation())
Expand All @@ -319,8 +319,10 @@ private void setup()
else
{
viewModel.getAsset(token, tokenId);
if (this.useNativeTokenScript)
if (this.usingNativeTokenScript)
{
viewModel.updateLocalAttributes(token, tokenId); //when complete calls displayTokenView

Check warning on line 324 in app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java#L324

Added line #L324 was not covered by tests
}
}
}

Expand Down Expand Up @@ -352,8 +354,10 @@ private void newScriptFound(TokenDefinition td)

setTitle(token.getTokenName(viewModel.getAssetDefinitionService(), 1));

if (!NFTAssetDetailActivity.FORCE_EMBEDDED_VIEWER)
this.useNativeTokenScript = td.nameSpace != null;
if (!viewModel.getUseTSViewer())
{
this.usingNativeTokenScript = td.nameSpace != null;
}

//now re-load the verbs if already called. If wallet is null this won't complete
setupFunctionBar(viewModel.getWallet());
Expand All @@ -362,10 +366,9 @@ private void newScriptFound(TokenDefinition td)
{
setupAttestation(td);
}
else
else if (this.usingNativeTokenScript)
{
if (this.useNativeTokenScript)
displayTokenView(td);
displayTokenView(td);
}
}
else
Expand Down Expand Up @@ -402,9 +405,12 @@ private void setupFunctionBar(Wallet wallet)
{
FunctionButtonBar functionBar = findViewById(R.id.layoutButtons);

if (this.useNativeTokenScript){
if (this.usingNativeTokenScript)
{
functionBar.setupFunctions(this, viewModel.getAssetDefinitionService(), token, null, Collections.singletonList(tokenId));

Check warning on line 410 in app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java#L410

Added line #L410 was not covered by tests
} else {
}
else
{
functionBar.setupFunctionsForJsViewer(this, R.string.title_tokenscript, this.token, Collections.singletonList(tokenId));

Check warning on line 414 in app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/NFTAssetDetailActivity.java#L414

Added line #L414 was not covered by tests
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void handleShortCut(String walletAddress)
token = viewModel.getTokenService().getToken(walletAddress, chainId, tokenAddress);

Check warning on line 242 in app/src/main/java/com/alphawallet/app/ui/TokenScriptJsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/TokenScriptJsActivity.java#L241-L242

Added lines #L241 - L242 were not covered by tests
if (token == null)
{
ShortcutUtils.showConfirmationDialog(this, singletonList(tokenAddress), getString(R.string.remove_shortcut_while_token_not_found));
ShortcutUtils.showConfirmationDialog(this, singletonList(tokenAddress), getString(R.string.remove_shortcut_while_token_not_found), null);

Check warning on line 245 in app/src/main/java/com/alphawallet/app/ui/TokenScriptJsActivity.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/TokenScriptJsActivity.java#L245

Added line #L245 was not covered by tests
}
else
{
Expand Down
Loading

0 comments on commit 5ea7b3b

Please sign in to comment.