Skip to content

Commit

Permalink
Fix for TokenScript display and attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Dec 19, 2023
1 parent 4a2d4e4 commit e97f515
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,17 @@ public TokenScriptResult.Attribute parseFunctionResult(TransactionResult transac
if (!TextUtils.isEmpty(res) && res.equalsIgnoreCase("TRUE")) val = BigInteger.ONE;
else val = BigInteger.ZERO;
}
else if (attr.syntax == TokenDefinition.Syntax.Integer)
{
if (transactionResult.result.startsWith("0x"))
{
val = new BigInteger(transactionResult.result, 16);

Check warning on line 737 in app/src/main/java/com/alphawallet/app/entity/tokenscript/TokenscriptFunction.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/entity/tokenscript/TokenscriptFunction.java#L737

Added line #L737 was not covered by tests
}
else
{
val = new BigInteger(transactionResult.result);

Check warning on line 741 in app/src/main/java/com/alphawallet/app/entity/tokenscript/TokenscriptFunction.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/entity/tokenscript/TokenscriptFunction.java#L741

Added line #L741 was not covered by tests
}
}
else if (attr.syntax == TokenDefinition.Syntax.NumericString && attr.as != As.Address)
{
if (transactionResult.result == null)
Expand Down Expand Up @@ -894,12 +905,13 @@ else if (!TextUtils.isEmpty(element.value))
public Single<TokenScriptResult.Attribute> fetchAttrResult(Token token, Attribute attr, BigInteger tokenId,
TokenDefinition td, AttributeInterface attrIf, ViewType itemView)
{
final BigInteger useTokenId = (attr == null) ? BigInteger.ZERO : tokenId;
if (attr == null)
{
return Single.fromCallable(() -> new TokenScriptResult.Attribute("bd", "bd", BigInteger.ZERO, ""));
}
else if (token.getAttributeResult(attr.name, useTokenId) != null)

final BigInteger useTokenId = attr.usesTokenId() ? tokenId : BigInteger.ZERO;
if (token.getAttributeResult(attr.name, useTokenId) != null)
{
return Single.fromCallable(() -> token.getAttributeResult(attr.name, useTokenId));
}
Expand Down Expand Up @@ -929,6 +941,7 @@ else if (attr.function == null) // static attribute from tokenId (eg city mappi
ContractAddress useAddress = new ContractAddress(attr.function); //always use the function attribute's address
long lastTxUpdate = attrIf.getLastTokenUpdate(useAddress.chainId, useAddress.address);
TransactionResult cachedResult = attrIf.getFunctionResult(useAddress, attr, useTokenId); //Needs to allow for multiple tokenIds

if ((itemView == ViewType.ITEM_VIEW || (!attr.isVolatile() && ((attrIf.resolveOptimisedAttr(useAddress, attr, cachedResult) || !cachedResult.needsUpdating(lastTxUpdate)))))) //can we use wallet's known data or cached value?
{
return resultFromDatabase(cachedResult, attr);
Expand Down Expand Up @@ -973,7 +986,12 @@ private Single<TokenScriptResult.Attribute> staticAttribute(Attribute attr, BigI
return Single.fromCallable(() -> {
try
{
if (attr.userInput)
if (refTags.containsKey(attr.name))
{
attr.userInput = false;
return new TokenScriptResult.Attribute(attr.name, attr.label, BigInteger.ZERO, refTags.get(attr.name), false);

Check warning on line 992 in app/src/main/java/com/alphawallet/app/entity/tokenscript/TokenscriptFunction.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/alphawallet/app/entity/tokenscript/TokenscriptFunction.java#L991-L992

Added lines #L991 - L992 were not covered by tests
}
else if (attr.userInput)
{
return new TokenScriptResult.Attribute(attr.name, attr.label, BigInteger.ZERO, "", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,8 @@ private boolean matchesExistingScript(Token token, String uri)
.equalTo("instanceKey", entryKey)
.findFirst();

if (entry != null && !TextUtils.isEmpty(entry.getFileHash())
if (entry != null && Utils.isIPFS(entry.getIpfsPath())
&& !TextUtils.isEmpty(entry.getFileHash())
&& !TextUtils.isEmpty(entry.getFilePath())
&& !TextUtils.isEmpty(entry.getIpfsPath())
&& entry.getIpfsPath().equals(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.webkit.CookieManager;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.Toast;
Expand Down Expand Up @@ -201,12 +203,17 @@ private void onConsoleClicked()

private void onClearBrowserCacheClicked()
{
WebView webView = new WebView(this);
webView.clearCache(true);
viewModel.blankFilterSettings();

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();

Check warning on line 216 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#L208-L216

Added lines #L208 - L216 were not covered by tests
Glide.get(this).clearDiskCache();
return 1;
}).subscribeOn(Schedulers.io())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@
import com.alphawallet.token.entity.TSAction;
import com.alphawallet.token.entity.TokenScriptResult;
import com.alphawallet.token.entity.TokenscriptElement;
import org.web3j.utils.Numeric;

import org.web3j.crypto.Hash;
import org.web3j.crypto.Keys;
import org.web3j.crypto.Sign;
import org.web3j.utils.Numeric;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.SignatureException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ private boolean displayTokenView(final TokenDefinition td)
LinearLayout webWrapper = findViewById(R.id.layout_webwrapper);
tokenScriptView = new Web3TokenView(this);
tokenScriptView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tokenScriptView.clearCache(true);

Check warning on line 862 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#L862

Added line #L862 was not covered by tests

if (tokenScriptView.renderTokenScriptView(token, new TicketRange(tokenId, token.getAddress()), viewModel.getAssetDefinitionService(), ViewType.VIEW, td))
{
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/com/alphawallet/app/web3/Web3TokenView.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package com.alphawallet.app.web3;

import static androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_ON;
import static androidx.webkit.WebSettingsCompat.setAlgorithmicDarkeningAllowed;
import static com.alphawallet.app.service.AssetDefinitionService.ASSET_DETAIL_VIEW_NAME;
import static com.alphawallet.app.service.AssetDefinitionService.ASSET_SUMMARY_VIEW_NAME;
import static com.alphawallet.token.tools.TokenDefinition.TOKENSCRIPT_ERROR;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Base64;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
Expand Down

0 comments on commit e97f515

Please sign in to comment.