From aa109b989d48daf2ef5a9e220f9fbbac81683169 Mon Sep 17 00:00:00 2001 From: James Brown Date: Thu, 28 Nov 2024 16:04:40 +0800 Subject: [PATCH] Update TokenScript handling (#3411) --- app/src/main/AndroidManifest.xml | 6 ++- .../app/service/AssetDefinitionService.java | 21 +++++++++- .../alphawallet/app/ui/FunctionActivity.java | 8 ++-- .../main/res/layout/activity_script_view.xml | 28 +++---------- .../token/entity/ActionModifier.java | 3 +- .../token/tools/TokenDefinition.java | 40 +++++++++++++++---- 6 files changed, 69 insertions(+), 37 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9d4b5cc489..d40dc985c0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -214,12 +214,14 @@ + android:label="@string/token_function" + android:windowSoftInputMode="adjustResize"/> + android:label="@string/token_function" + android:windowSoftInputMode="adjustResize"/> >> fetchFunctionMap(Token token, @NotN ContractType type, UpdateType update) { return Single.fromCallable(() -> { - ActionModifier requiredActionModifier = type == ContractType.ATTESTATION ? ActionModifier.ATTESTATION : ActionModifier.NONE; + List modifiers = getAllowedTypes(type); Map> validActions = new HashMap<>(); TokenDefinition td = getAssetDefinition(token); if (td != null) @@ -2306,7 +2306,7 @@ public Single>> fetchFunctionMap(Token token, @NotN for (String actionName : actions.keySet()) { TSAction action = actions.get(actionName); - if (action == null || action.modifier != requiredActionModifier) + if (action == null || !modifiers.contains(action.modifier)) { continue; //do not include attestations if this isn't an attestation fetch } @@ -2342,6 +2342,23 @@ public Single>> fetchFunctionMap(Token token, @NotN }); } + private List getAllowedTypes(ContractType type) + { + List modifiers = new ArrayList<>(); + switch (type) + { + case ATTESTATION -> { + modifiers.add(ActionModifier.ATTESTATION); + } + default -> { + modifiers.add(ActionModifier.NONE); + modifiers.add(ActionModifier.ACTIVITY); + } + } + + return modifiers; + } + private void addIntrinsicAttributes(Map attrs, Token token, BigInteger tokenId) { //add tokenId, ownerAddress & contractAddress diff --git a/app/src/main/java/com/alphawallet/app/ui/FunctionActivity.java b/app/src/main/java/com/alphawallet/app/ui/FunctionActivity.java index 48565a411d..6bebfdca22 100644 --- a/app/src/main/java/com/alphawallet/app/ui/FunctionActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/FunctionActivity.java @@ -59,6 +59,7 @@ import com.alphawallet.app.widget.SignTransactionDialog; import com.alphawallet.ethereum.EthereumNetworkBase; import com.alphawallet.hardware.SignatureFromKey; +import com.alphawallet.token.entity.ActionModifier; import com.alphawallet.token.entity.Attribute; import com.alphawallet.token.entity.EthereumMessage; import com.alphawallet.token.entity.MethodArg; @@ -280,7 +281,6 @@ private void onAttr(TokenScriptResult.Attribute attribute) private void fillEmpty() { - findViewById(R.id.layout_webwrapper).setVisibility(View.VISIBLE); tokenView.loadData("No Data", "text/html", "utf-8"); } @@ -339,7 +339,10 @@ private void initViewModel() private void setupFunctions() { FunctionButtonBar functionBar = findViewById(R.id.layoutButtons); - functionBar.setupFunctionList(this, actionMethod); + if (action != null && action.modifier != ActionModifier.ACTIVITY) + { + functionBar.setupFunctionList(this, actionMethod); + } } @Override @@ -661,7 +664,6 @@ public void onPageLoaded(WebView view) @Override public void onPageRendered(WebView view) { - findViewById(R.id.layout_webwrapper).setVisibility(View.VISIBLE); if (parsePass == 1) { tokenView.reload(); diff --git a/app/src/main/res/layout/activity_script_view.xml b/app/src/main/res/layout/activity_script_view.xml index f493cea1af..dbb76d48f3 100644 --- a/app/src/main/res/layout/activity_script_view.xml +++ b/app/src/main/res/layout/activity_script_view.xml @@ -6,30 +6,14 @@ - - - - - - - - - + android:layout_height="match_parent" + android:layout_above="@id/layoutButtons" + android:layout_below="@id/toolbar"> - + tag in tokens"); @@ -767,7 +783,6 @@ else if (thisDate.before(schemaDate)) public boolean isSchemaLessThanMinimum() { - if (nameSpace == null) { return true; @@ -806,14 +821,15 @@ private void extractCard(Element card) throws Exception tokenViews.views.put(tv.getLabel(), tv); break; case "action": + case "activity": action = handleAction(card); actions.put(action.name, action); setModifier(action, card); break; - case "activity": + /*case "activity": activity = processActivityView(card); activityCards.put(card.getAttribute("name"), activity); - break; + break;*/ case "onboarding": // do not parse onboarding cards break; @@ -839,6 +855,16 @@ private void setModifier(TSAction action, Element card) throws Exception default: throw new SAXException("Unexpected modifier found: " + modifier); } + + String type = card.getAttribute("type"); + switch (type) + { + case "activity": + action.modifier = ActionModifier.ACTIVITY; + break; + default: + break; + } } private TSAction handleAction(Element action) throws Exception