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

Improve Send #3229

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8fca478
Rename LI.FI Token entity to avoid confusion
justindg Apr 25, 2023
ffe8225
Rename event listener
justindg Apr 25, 2023
4bfd9dd
Initial commit
justindg Apr 27, 2023
76e5812
Cleanup Bottom Navigation
justindg Apr 27, 2023
d669d35
Create new activity for handling Transfer Requests
justindg May 11, 2023
d55ff4f
Use transfer request router
justindg May 11, 2023
776b57e
Use appropriate routers
justindg May 11, 2023
a984b3c
Rename Tokens class
justindg May 11, 2023
45b8eeb
Move to utils package
justindg May 11, 2023
624c91b
Rename and move to utils package
justindg May 11, 2023
fe0ceba
Apply changes to SendActivity
justindg May 11, 2023
abb85ad
Add new methods to InputAddress
justindg May 11, 2023
e295a91
UI fixes/updates
justindg May 12, 2023
4b76068
Fixed NPE
justindg May 16, 2023
75bc52b
Restore chain change dialog
justindg May 16, 2023
0897667
Rename LI.FI Token entity to avoid confusion
justindg Apr 25, 2023
c2f33e3
Rename event listener
justindg Apr 25, 2023
443d800
Initial commit
justindg Apr 27, 2023
dace070
Cleanup Bottom Navigation
justindg Apr 27, 2023
d6918db
Create new activity for handling Transfer Requests
justindg May 11, 2023
3445d37
Use transfer request router
justindg May 11, 2023
365a6d0
Use appropriate routers
justindg May 11, 2023
2d36cb5
Rename Tokens class
justindg May 11, 2023
fbc3343
Move to utils package
justindg May 11, 2023
09401f7
Rename and move to utils package
justindg May 11, 2023
96cb987
Apply changes to SendActivity
justindg May 11, 2023
d72ab49
Add new methods to InputAddress
justindg May 11, 2023
67944ee
UI fixes/updates
justindg May 12, 2023
5ae4571
Fixed NPE
justindg May 16, 2023
f67fa07
Restore chain change dialog
justindg May 16, 2023
767c161
Cleanup
justindg May 16, 2023
893176f
Update EIP681 layout
justindg May 17, 2023
98ca6e5
Add unit tests
justindg May 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@
android:name=".ui.NotificationSettingsActivity"
android:label="@string/title_notifications" />

<activity
android:name=".ui.TransferRequestActivity"
android:label="@string/transfer_request" />

<service
android:name=".service.PriceAlertsService"
android:enabled="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class Action

@SerializedName("fromToken")
@Expose
public Token fromToken;
public LifiToken fromToken;

@SerializedName("toToken")
@Expose
public Token toToken;
public LifiToken toToken;

@SerializedName("fromAmount")
@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class Connection

@SerializedName("fromTokens")
@Expose
public List<Token> fromTokens;
public List<LifiToken> fromTokens;

@SerializedName("toTokens")
@Expose
public List<Token> toTokens;
public List<LifiToken> toTokens;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;

public class FeeCost
{
@SerializedName("name")
Expand All @@ -17,7 +15,7 @@ public class FeeCost

@SerializedName("token")
@Expose
public Token token;
public LifiToken token;

@SerializedName("amount")
@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public class GasCost

@SerializedName("token")
@Expose
public Token token;
public LifiToken token;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.Objects;

public class Token
public class LifiToken
{
@SerializedName("address")
@Expose
Expand Down Expand Up @@ -47,7 +47,7 @@ public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Token lToken = (Token) o;
LifiToken lToken = (LifiToken) o;
return address.equals(lToken.address) && symbol.equals(lToken.symbol);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.alphawallet.app.repository;

import android.util.Pair;

import com.alphawallet.app.entity.CurrencyItem;
import com.alphawallet.app.entity.tokens.Token;

import java.util.Set;

Expand Down Expand Up @@ -138,4 +141,8 @@ public interface PreferenceRepositoryType
boolean isPostNotificationsPermissionRequested(String address);

void setPostNotificationsPermissionRequested(String address, boolean hasRequested);

void setLastSentToken(Token address);

Pair<String, Long> getLastSentToken();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;

import com.alphawallet.app.C;
import com.alphawallet.app.entity.CurrencyItem;
import com.alphawallet.app.entity.tokens.Token;

import java.util.HashSet;
import java.util.Locale;
Expand Down Expand Up @@ -52,6 +54,8 @@ public class SharedPreferenceRepository implements PreferenceRepositoryType {
private static final String LAUNCH_COUNT = "launch_count";
private static final String NEW_WALLET = "new_wallet_";
private static final String WATCH_ONLY = "watch_only";
private static final String LAST_SENT_TOKEN_ADDRESS = "last_sent_token_address";
private static final String LAST_SENT_TOKEN_CHAIN_ID = "last_sent_token_chain_id";

private final SharedPreferences pref;

Expand Down Expand Up @@ -460,6 +464,22 @@ public void setPostNotificationsPermissionRequested(String address, boolean hasR
pref.edit().putBoolean(getAddressKey(POST_NOTIFICATIONS_PERMISSION_REQUESTED, address), hasRequested).apply();
}

@Override
public void setLastSentToken(Token token)
{
pref.edit().putString(LAST_SENT_TOKEN_ADDRESS, token.tokenInfo.address).apply();
pref.edit().putLong(LAST_SENT_TOKEN_CHAIN_ID, token.tokenInfo.chainId).apply();
}

@Override
public Pair<String, Long> getLastSentToken()
{
return new Pair<>(
pref.getString(LAST_SENT_TOKEN_ADDRESS, ""),
pref.getLong(LAST_SENT_TOKEN_CHAIN_ID, 0)
);
}

@NonNull
private String getAddressKey(String key, String address)
{
Expand Down
38 changes: 26 additions & 12 deletions app/src/main/java/com/alphawallet/app/router/SendTokenRouter.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
package com.alphawallet.app.router;


import android.app.Activity;
import android.content.Intent;

import com.alphawallet.app.C;
import com.alphawallet.app.entity.QRResult;
import com.alphawallet.app.entity.Wallet;
import com.alphawallet.app.entity.tokens.Token;
import com.alphawallet.app.ui.SendActivity;

public class SendTokenRouter {
public void open(Activity context, String address, String symbol, int decimals, Wallet wallet, Token token, long chainId) {
public class SendTokenRouter
{

// From token detail page
public void open(Activity context, Token token)
{
Intent intent = new Intent(context, SendActivity.class);
intent.putExtra(C.EXTRA_CONTRACT_ADDRESS, token.getAddress());
intent.putExtra(C.EXTRA_NETWORKID, token.tokenInfo.chainId);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivityForResult(intent, C.COMPLETED_TRANSACTION);
}

// From address scan
public void open(Activity context, String recipientAddress)
{
//TODO Implement
Intent intent = new Intent(context, SendActivity.class);
intent.putExtra(C.EXTRA_ADDRESS, recipientAddress);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivityForResult(intent, C.COMPLETED_TRANSACTION);
}

// From bottom nav
public void open(Activity context)
{
Intent intent = new Intent(context, SendActivity.class);
intent.putExtra(C.EXTRA_CONTRACT_ADDRESS, address);
intent.putExtra(C.EXTRA_ADDRESS, token.getAddress());
intent.putExtra(C.EXTRA_NETWORKID, chainId);
intent.putExtra(C.EXTRA_SYMBOL, symbol);
intent.putExtra(C.EXTRA_DECIMALS, decimals);
intent.putExtra(C.Key.WALLET, wallet);
intent.putExtra(C.EXTRA_AMOUNT, (QRResult)null);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivityForResult(intent, C.COMPLETED_TRANSACTION);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.alphawallet.app.router;


import android.app.Activity;
import android.content.Intent;

import com.alphawallet.app.C;
import com.alphawallet.app.entity.QRResult;
import com.alphawallet.app.ui.TransferRequestActivity;

public class TransferRequestRouter
{
public void open(Activity context, QRResult result)
{
Intent intent = new Intent(context, TransferRequestActivity.class);
intent.putExtra(C.EXTRA_AMOUNT, result);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivityForResult(intent, C.COMPLETED_TRANSACTION);
}
}
18 changes: 9 additions & 9 deletions app/src/main/java/com/alphawallet/app/service/SwapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.alphawallet.app.C;
import com.alphawallet.app.entity.lifi.RouteOptions;
import com.alphawallet.app.entity.lifi.Token;
import com.alphawallet.app.entity.lifi.LifiToken;
import com.alphawallet.app.repository.SwapRepository;
import com.alphawallet.app.util.BalanceUtils;
import com.alphawallet.app.util.JsonUtils;
Expand Down Expand Up @@ -125,8 +125,8 @@ public Single<String> getConnections(long from, long to)
return Single.fromCallable(() -> fetchPairs(from, to));
}

public Single<String> getQuote(Token source,
Token dest,
public Single<String> getQuote(LifiToken source,
LifiToken dest,
String address,
String amount,
String slippage,
Expand All @@ -135,8 +135,8 @@ public Single<String> getQuote(Token source,
return Single.fromCallable(() -> fetchQuote(source, dest, address, amount, slippage, allowExchanges));
}

public Single<String> getRoutes(Token source,
Token dest,
public Single<String> getRoutes(LifiToken source,
LifiToken dest,
String address,
String amount,
String slippage,
Expand Down Expand Up @@ -180,8 +180,8 @@ public String fetchPairs(long fromChain, long toChain)
return executeRequest(builder.build().toString());
}

public String fetchQuote(Token source,
Token dest,
public String fetchQuote(LifiToken source,
LifiToken dest,
String address,
String amount,
String slippage,
Expand All @@ -200,8 +200,8 @@ public String fetchQuote(Token source,
return executeRequest(builder.build().toString());
}

public String fetchRoutes(Token source,
Token dest,
public String fetchRoutes(LifiToken source,
LifiToken dest,
String address,
String amount,
String slippage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ private void finishAndLaunchSend()
}
else
{
viewModel.showSend(this, currentResult, token);
viewModel.showSend(this, currentResult);
finish();
}
}
else
{
//launch send payment screen for eth transaction
viewModel.showSend(this, currentResult, viewModel.getToken(currentResult.chainId, viewModel.wallet().getValue().address));
viewModel.showSend(this, currentResult);
finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ public void handleQRCode(int resultCode, Intent data, FragmentMessenger messenge
viewModel.track(Analytics.Action.SCAN_QR_CODE_SUCCESS, props);

//EIP681 payment request scanned, should go to send
viewModel.showSend(getContext(), result);
viewModel.showSend(getActivity(), result);
break;

case FUNCTION_CALL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public void handleTokenScriptFunction(String function, List<BigInteger> selectio
@Override
public void showSend()
{
viewModel.showSendToken(this, wallet, token);
viewModel.showSendToken(this, token);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ private void showPointOfSaleMode()
{
setContentView(R.layout.activity_eip681);
initViews();
findViewById(R.id.toolbar_title).setVisibility(View.GONE);
setTitle("");
setTitle(getString(R.string.generate_payment_request));
displayAddress = Keys.toChecksumAddress(wallet.address);
networkInfo = viewModel.getEthereumNetworkRepository().getNetworkByChain(overrideNetwork);
currentMode = AddressMode.MODE_POS;
layoutInputAmount.setVisibility(View.VISIBLE);

copyWalletName = findViewById(R.id.copy_wallet_name);
copyWalletName.setVisibility(View.GONE);
amountInput = findViewById(R.id.input_amount);
setupPOSMode(networkInfo);
}
Expand All @@ -214,6 +214,7 @@ private void setupPOSMode(NetworkInfo info)
if (token == null) token = viewModel.getTokenService().getToken(info.chainId, wallet.address);
amountInput.setupToken(token, viewModel.getAssetDefinitionService(), viewModel.getTokenService(), this);
amountInput.setAmount("");
amountInput.focus();
updateCryptoAmount(BigDecimal.ZERO);
}

Expand Down
Loading