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

Feat: tokenscript engine js #3346

Merged
merged 14 commits into from
Feb 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static com.alphawallet.app.steps.Steps.closeSecurityWarning;
import static com.alphawallet.app.steps.Steps.createNewWallet;
import static com.alphawallet.app.steps.Steps.gotoSettingsPage;
import static com.alphawallet.app.steps.Steps.scrollToImproved;
import static com.alphawallet.app.steps.Steps.selectMenu;
import static com.alphawallet.app.util.Helper.click;

Expand Down Expand Up @@ -38,7 +39,10 @@ public void title_should_see_crash_report_settings_page()
gotoSettingsPage();
selectMenu("Advanced");
Helper.wait(1);
onView(withId(R.id.layout)).perform(swipeUp());
onView(withId(R.id.scroll_layer)).perform(swipeUp());
onView(withId(R.id.scroll_layer)).perform(swipeUp());
onView(withSubstring("Crash")).perform(scrollToImproved());

click(withSubstring("Crash"));
shouldSee("Share Anonymous Data");
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@
android:hardwareAccelerated="true"
android:label="ERC1155 Asset Details" />

<activity
android:name=".ui.TokenScriptJsActivity"
android:hardwareAccelerated="true"
android:label="TokenScript JS Viewer" />

<activity
android:name=".ui.Erc1155AssetListActivity"
android:hardwareAccelerated="true"
Expand Down
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 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 @@
}

@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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
private SettingsItemView analytics;
private SettingsItemView crashReporting;
private SettingsItemView developerOverride;
private SettingsItemView tokenScriptViewer;
private AWalletAlertDialog waitDialog = null;

@Nullable
Expand All @@ -57,7 +58,7 @@
{
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 @@
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 @@
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 @@
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 @@
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 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 @@
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 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 @@ -820,7 +820,7 @@
private void setupWeb3(Wallet wallet)
{
if (wallet == null) { return; }
web3.setChainId(activeNetwork.chainId);
web3.setChainId(activeNetwork.chainId, false);

Check warning on line 823 in app/src/main/java/com/alphawallet/app/ui/DappBrowserFragment.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/ui/DappBrowserFragment.java#L823

Added line #L823 was not covered by tests
web3.setWalletAddress(new Address(wallet.address));

web3.setWebChromeClient(new WebChromeClient()
Expand Down
Loading
Loading