Fixes from alchemy (#1818)

Improve approve for NFT and truncate address if required
pull/1826/head
James Brown 4 years ago committed by GitHub
parent 43653f20e5
commit cb27462773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      app/src/main/java/com/alphawallet/app/entity/TransactionInput.java
  2. 2
      app/src/main/java/com/alphawallet/app/ui/MyDappsFragment.java
  3. 15
      app/src/main/java/com/alphawallet/app/widget/AddressDetailView.java
  4. 4
      app/src/main/java/com/alphawallet/app/widget/EventDetailWidget.java
  5. 1
      app/src/main/res/layout/item_address_detail.xml
  6. 2
      app/src/main/res/values-es/strings.xml
  7. 2
      app/src/main/res/values-zh/strings.xml
  8. 2
      app/src/main/res/values/strings.xml
  9. 12
      lib/src/main/java/com/alphawallet/token/entity/EthereumMessage.java

@ -201,11 +201,11 @@ public class TransactionInput
switch (type)
{
case APPROVE: //show address as token name, ENS name or formatted address
String amount = getFirstValueScaled(ctx, t.tokenInfo.decimals);
String amount = getOperationValue(t, tx);
String approveAddr = getFirstAddress();
Token approveToken = tService.getToken(tx.chainId, approveAddr);
approveAddr = approveToken == null ? ENSHandler.matchENSOrFormat(ctx, approveAddr) : approveToken.getShortName();
operation = ctx.getString(R.string.default_approve, amount, t.getSymbol(), approveAddr);
operation = ctx.getString(R.string.default_approve, amount, approveAddr);
break;
case TERMINATE_CONTRACT:
operation = ENSHandler.matchENSOrFormat(ctx, tx.to);
@ -562,7 +562,8 @@ public class TransactionInput
break;
case APPROVE:
case ALLOCATE_TO:
operationValue = getFirstValueScaled(null, token.tokenInfo.decimals);
operationValue = getApproveValue(token);
if (token.isNonFungible()) addSymbol = false;
break;
case TRANSFER_TO:
case RECEIVE_FROM:
@ -613,6 +614,20 @@ public class TransactionInput
return operationValue;
}
private String getApproveValue(Token token)
{
if (token.isNonFungible() && miscData.size() > 0)
{
//grab tokenId
BigInteger bi = new BigInteger(miscData.get(0), 16);
return "#" + bi.toString(10);
}
else
{
return getFirstValueScaled(null, token.tokenInfo.decimals);
}
}
public boolean shouldShowSymbol(Token token)
{
switch (type)

@ -20,6 +20,7 @@ import java.util.List;
import com.alphawallet.app.R;
import com.alphawallet.app.entity.DApp;
import com.alphawallet.app.util.KeyboardUtils;
import com.alphawallet.app.widget.AWalletAlertDialog;
@ -49,6 +50,7 @@ public class MyDappsFragment extends Fragment {
list.setAdapter(adapter);
noDapps = view.findViewById(R.id.no_dapps);
showOrHideViews();
KeyboardUtils.hideKeyboard(view);
return view;
}

@ -83,8 +83,23 @@ public class AddressDetailView extends LinearLayout
{
setVisibility(View.VISIBLE);
recipientDetails.setVisibility(View.GONE);
//shorten requesterURL if required
requesterUrl = abbreviateURL(requesterUrl);
textAddressSummary.setText(requesterUrl);
ViewGroup.LayoutParams param = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 3.4f);
textAddressSummary.setLayoutParams(param);
}
private String abbreviateURL(String inputURL)
{
if (inputURL.length() > 32)
{
int index = inputURL.indexOf("/", 20);
return inputURL.substring(0,index);
}
else
{
return inputURL;
}
}
}

@ -55,8 +55,8 @@ public class EventDetailWidget extends LinearLayout
resourceId = R.string.default_approved;
break;
case "ownerApproved":
resourceId = R.string.default_approve;
break;
detail.setText(getContext().getString(R.string.default_approve, eventAmount, data.getDetailAddress()));
return;
default:
resourceId = R.string.default_to;
break;

@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="300dp"
android:orientation="vertical">
<View

@ -705,7 +705,7 @@
<string name="default_to">Sent %1$s %2$s to %3$s</string>
<string name="default_from">Received %1$s %2$s from %3$s</string>
<string name="default_approved">You have received approval to move %1$s %2$s from %3$s</string>
<string name="default_approve">Approved %3$s to move %1$s %2$s</string>
<string name="default_approve">Approved %2$s to move %1$s</string>
<string name="contract_call">Llamada de contrato</string>
<string name="insufficient_gas">Gas insuficientes</string>
<string name="not_enough_gas_message">We estimate this transaction will fail due to insufficient funds. Do you wish to try to send?</string>

@ -705,7 +705,7 @@
<string name="default_to">Sent %1$s %2$s to %3$s</string>
<string name="default_from">Received %1$s %2$s from %3$s</string>
<string name="default_approved">You have received approval to move %1$s %2$s from %3$s</string>
<string name="default_approve">Approved %3$s to move %1$s %2$s</string>
<string name="default_approve">Approved %2$s to move %1$s</string>
<string name="contract_call">合约调用</string>
<string name="insufficient_gas">资金不够</string>
<string name="not_enough_gas_message">We estimate this transaction will fail due to insufficient funds. Do you wish to try to send?</string>

@ -733,7 +733,7 @@
<string name="default_to">Sent %1$s %2$s to %3$s</string>
<string name="default_from">Received %1$s %2$s from %3$s</string>
<string name="default_approved">You have received approval to move %1$s %2$s from %3$s</string>
<string name="default_approve">Approved %3$s to move %1$s %2$s</string>
<string name="default_approve">Approved %2$s to move %1$s</string>
<string name="contract_call">Contract call</string>
<string name="insufficient_gas">Insufficient Gas</string>
<string name="not_enough_gas_message">We estimate this transaction will fail due to insufficient funds. Do you wish to try to send?</string>

@ -27,9 +27,9 @@ public class EthereumMessage implements Signable {
this.messageBytes = Numeric.hexStringToByteArray(message);
this.displayOrigin = displayOrigin;
this.leafPosition = leafPosition;
this.messageType = type;
this.prehash = getEthereumMessage(message);
this.userMessage = message;
messageType = type;
}
private byte[] getEthereumMessage(String message) {
@ -43,10 +43,18 @@ public class EthereumMessage implements Signable {
encodedMessage = message.getBytes();
}
byte[] result;
if (messageType == SignMessageType.SIGN_PERSONAL_MESSAGE)
{
byte[] prefix = MESSAGE_PREFIX.concat(String.valueOf(encodedMessage.length)).getBytes();
byte[] result = new byte[prefix.length + encodedMessage.length];
result = new byte[prefix.length + encodedMessage.length];
System.arraycopy(prefix, 0, result, 0, prefix.length);
System.arraycopy(encodedMessage, 0, result, prefix.length, encodedMessage.length);
}
else
{
result = messageBytes;
}
return result;
}

Loading…
Cancel
Save