Skip to content

Commit

Permalink
Add Walletconnect icon
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Mar 11, 2024
1 parent 02551a2 commit bc7aea1
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 91 deletions.
13 changes: 8 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ android {
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
Expand Down Expand Up @@ -219,9 +222,9 @@ dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation fileTree(include: ['*.aar'], dir: 'libs')
//NB: Downgrade jackson due to bug in 2.15 releases that makes it incompatible with Gradle 8
//noinspection UseTomlInstead,GradleDependency
implementation platform('com.fasterxml.jackson:jackson-bom:2.13.5') //Don't upgrade from 2.13.5 due to Android API24 compatibility

//noinspection BomWithoutPlatform,GradleDependency
implementation platform('com.fasterxml.jackson:jackson-bom:2.13.5') //Do not upgrade! 2.13.5 is latest library with Android API24 compatibility
implementation 'com.fasterxml.jackson.core:jackson-core'
implementation 'com.fasterxml.jackson.core:jackson-databind'

Expand Down Expand Up @@ -282,8 +285,8 @@ dependencies {
//Timber
implementation libs.timber

//noinspection UseTomlInstead
implementation platform('com.walletconnect:android-bom:1.13.1')
//noinspection UseTomlInstead,GradleDependency
implementation platform('com.walletconnect:android-bom:1.13.1') //TODO: Upgrade
implementation("com.walletconnect:android-core", {
exclude group: 'org.web3j', module: '*'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private const val extraPriorityFeeRatio = 0.25 // extra priority fee offere
private const val fallbackPriorityFee = 2000000000L // priority fee offered when there are no recent transactions
private const val MIN_PRIORITY_FEE = 100000000L // Minimum priority fee in Wei, 0.1 Gwei

fun SuggestEIP1559(gasService: GasService, feeHistory: FeeHistory): Single<MutableMap<Int, EIP1559FeeOracleResult>> {
fun suggestEIP1559(gasService: GasService, feeHistory: FeeHistory): Single<MutableMap<Int, EIP1559FeeOracleResult>> {
return suggestPriorityFee(parseLong(feeHistory.oldestBlock.removePrefix("0x"), 16), feeHistory, gasService)
.flatMap { priorityFee -> calculateResult(priorityFee, feeHistory) }
}
Expand Down Expand Up @@ -74,10 +74,10 @@ private fun calculateResult(priorityFee: BigInteger, feeHistory: FeeHistory): Si
val result = mutableMapOf<Int, EIP1559FeeOracleResult>()
for (timeFactor in maxTimeFactor downTo 0) {
var bf: BigInteger
if (timeFactor < 1e-6) {
bf = baseFee.last()
bf = if (timeFactor < 1e-6) {
baseFee.last()
} else {
bf = predictMinBaseFee(baseFee, order, timeFactor.toDouble(), consistentBaseFee)
predictMinBaseFee(baseFee, order, timeFactor.toDouble(), consistentBaseFee)
}
var t = BigDecimal(usePriorityFee)
if (bf > maxBaseFee) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ private Single<Map<Integer, EIP1559FeeOracleResult>> useCalculationIfRequired(Ma
private Single<Map<Integer, EIP1559FeeOracleResult>> getEIP1559FeeStructureCalculation()
{
return getChainFeeHistory(100, "latest", "")
.flatMap(feeHistory -> SuggestEIP1559Kt.SuggestEIP1559(this, feeHistory));
.flatMap(feeHistory -> SuggestEIP1559Kt.suggestEIP1559(this, feeHistory));
}

private void handleError(Throwable err)
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/alphawallet/app/ui/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import com.alphawallet.app.ui.widget.TokensAdapterCallback;
import com.alphawallet.app.ui.widget.adapter.TokensAdapter;
import com.alphawallet.app.ui.widget.entity.SearchToolbarCallback;
import com.alphawallet.app.util.Utils;
import com.alphawallet.app.viewmodel.WalletViewModel;
import com.alphawallet.app.widget.AWalletAlertDialog;
import com.alphawallet.app.widget.SearchToolbar;

import org.web3j.crypto.WalletUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public CustomAdapter.CustomViewHolder onCreateViewHolder(@NonNull ViewGroup pare
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_wc_session, parent, false);

return new CustomAdapter.CustomViewHolder(itemView);
return new CustomViewHolder(itemView);
}

@Override
Expand Down Expand Up @@ -317,7 +317,7 @@ public void updateList(List<WalletConnectSessionItem> list)
notifyDataSetChanged();
}

class CustomViewHolder extends RecyclerView.ViewHolder
static class CustomViewHolder extends RecyclerView.ViewHolder
{
final ImageView icon;
final ImageView statusIcon;
Expand Down
28 changes: 26 additions & 2 deletions app/src/main/java/com/alphawallet/app/ui/WalletFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ private void refreshList()
adapter.clear();
viewModel.prepare();
viewModel.notifyRefresh();
//awWalletConnectClient.updateNotification();
});
}

Expand All @@ -407,6 +406,7 @@ public void comeIntoFocus()
viewModel.startUpdateListener();
viewModel.getTokensService().startUpdateCycleIfRequired();
}
checkWalletConnect();
}

@Override
Expand Down Expand Up @@ -566,6 +566,7 @@ public void onResume()
if (viewModel == null)
{
requireActivity().recreate();
return;
}
else
{
Expand All @@ -581,6 +582,16 @@ public void onResume()
viewModel.startUpdateListener();
viewModel.getTokensService().startUpdateCycleIfRequired();
}

checkWalletConnect();
}

private void checkWalletConnect()
{
if (adapter != null)
{
adapter.checkWalletConnect();
}
}

private void onTokens(TokenCardMeta[] tokens)
Expand All @@ -595,7 +606,7 @@ private void onTokens(TokenCardMeta[] tokens)

if (currentTabPos.equals(TokenFilter.ALL))
{
//awWalletConnectClient.updateNotification();
checkWalletConnect();
}
else
{
Expand Down Expand Up @@ -807,6 +818,19 @@ public void onSearchClicked()
//startActivity(intent);
}

@Override
public void onWCClicked()
{
Intent intent = awWalletConnectClient.getSessionIntent(getContext());
startActivity(intent);
}

@Override
public boolean hasWCSession()
{
return awWalletConnectClient != null && awWalletConnectClient.hasWalletConnectSessions();
}

@Override
public void onSwitchClicked()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public interface TokensAdapterCallback
default void reloadTokens() { };
default void onBuyToken() { }
default void onSearchClicked() { };
default void onSwitchClicked() {};
default void onSwitchClicked() { };
default void onWCClicked() { };
default boolean hasWCSession() { return false; };
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import com.alphawallet.app.entity.CustomViewSettings;
import com.alphawallet.app.entity.TokenFilter;
import com.alphawallet.app.entity.tokendata.TokenGroup;
import com.alphawallet.app.entity.tokens.Attestation;
import com.alphawallet.app.entity.tokens.Token;
import com.alphawallet.app.entity.tokens.TokenCardMeta;
import com.alphawallet.app.entity.walletconnect.WalletConnectSessionItem;
import com.alphawallet.app.repository.TokensRealmSource;
import com.alphawallet.app.service.AssetDefinitionService;
import com.alphawallet.app.service.TokensService;
import com.alphawallet.app.ui.widget.TokensAdapterCallback;
Expand Down Expand Up @@ -169,7 +167,7 @@ public BinderViewHolder<?> onCreateViewHolder(@NonNull ViewGroup parent, int vie
break;

case SearchTokensHolder.VIEW_TYPE:
holder = new SearchTokensHolder(R.layout.layout_manage_token_search, parent, tokensAdapterCallback::onSearchClicked);
holder = new SearchTokensHolder(R.layout.layout_manage_token_search, parent, tokensAdapterCallback);
break;

case WarningHolder.VIEW_TYPE:
Expand Down Expand Up @@ -301,11 +299,11 @@ public void updateToken(TokenCardMeta token)
}
else
{
SortedItem headerItem = new HeaderItem(token.group);
SortedItem<?> headerItem = new HeaderItem(token.group);
items.add(tsi);
items.add(headerItem);

SortedItem chainItem = new ChainItem(token.getChain(), token.group);
SortedItem<?> chainItem = new ChainItem(token.getChain(), token.group);
if (doesNotExist(chainItem))
{
items.add(chainItem);
Expand All @@ -318,12 +316,12 @@ public void updateToken(TokenCardMeta token)
}
}

private boolean doesNotExist(SortedItem token)
private boolean doesNotExist(SortedItem<?> token)
{
return findItem(token) == -1;
}

private int findItem(SortedItem tsi)
private int findItem(SortedItem<?> tsi)
{
for (int i = 0; i < items.size(); i++)
{
Expand All @@ -339,9 +337,8 @@ private void removeMatchingTokenDifferentWeight(TokenCardMeta token)
{
for (int i = 0; i < items.size(); i++)
{
if (items.get(i) instanceof TokenSortedItem)
if (items.get(i) instanceof TokenSortedItem tsi)
{
TokenSortedItem tsi = (TokenSortedItem) items.get(i);
if (tsi.value.equals(token))
{
if (tsi.value.getNameWeight() != token.getNameWeight())
Expand Down Expand Up @@ -523,9 +520,8 @@ private void filterAdapterItems()
for (int i = 0; i < items.size(); i++)
{
Object si = items.get(i);
if (si instanceof TokenSortedItem)
if (si instanceof TokenSortedItem tsi)
{
TokenSortedItem tsi = (TokenSortedItem) si;
if (canDisplayToken(tsi.value))
{
filterTokens.add(tsi.value);
Expand Down Expand Up @@ -567,9 +563,8 @@ public int getScrollPosition()
for (int i = 0; i < items.size(); i++)
{
Object si = items.get(i);
if (si instanceof TokenSortedItem)
if (si instanceof TokenSortedItem tsi)
{
TokenSortedItem tsi = (TokenSortedItem) si;
TokenCardMeta token = tsi.value;
if (scrollToken.equals(token))
{
Expand Down Expand Up @@ -654,4 +649,26 @@ public void addToken(SortedItem<TokenCardMeta> token)
{
items.add(token);
}

public void checkWalletConnect()
{
//activate WC logo in search bar if we have active WC sessions
for (int i = 0; i < items.size(); i++)
{
Object si = items.get(i);
if (si instanceof ManageTokensSearchItem manageTokensSearchItem && manageTokensSearchItem.view instanceof SearchTokensHolder sth)
{
if (tokensAdapterCallback.hasWCSession())
{
sth.enableWalletConnect();
}
else
{
sth.hideWalletConnect();
}

break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alphawallet.app.R;
import com.alphawallet.app.ui.widget.TokensAdapterCallback;
import com.alphawallet.app.ui.widget.entity.ManageTokensData;

public class SearchTokensHolder extends BinderViewHolder<ManageTokensData> {
Expand All @@ -20,7 +22,9 @@ public interface SearchHandler {

final EditText editSearch;
final SearchHandler searchHandler;
final SearchHandler onWCClicked;
final View searchTokenClick;
final ImageView walletConnect;
String wallet;

@Override
Expand All @@ -38,11 +42,32 @@ public void bind(@Nullable ManageTokensData data, @NonNull Bundle addition) {
});
}

public SearchTokensHolder(int res_id, ViewGroup parent, SearchHandler handler) {
public SearchTokensHolder(int res_id, ViewGroup parent, TokensAdapterCallback tCallback) {
super(res_id, parent);
this.editSearch = findViewById(R.id.edit_search);
this.searchHandler = handler;
this.searchHandler = tCallback::onSearchClicked;
this.searchTokenClick = findViewById(R.id.click_layer);
this.walletConnect = findViewById(R.id.icon_wc_active);
this.wallet = null;
this.onWCClicked = tCallback::onWCClicked;

if (tCallback.hasWCSession())
{
enableWalletConnect();
}
}

public void enableWalletConnect()
{
walletConnect.setVisibility(View.VISIBLE);
walletConnect.setOnClickListener(v -> {
if (onWCClicked != null) onWCClicked.onFocus();
});
}

public void hideWalletConnect()
{
walletConnect.setVisibility(View.GONE);
walletConnect.setOnClickListener(null);
}
}
Loading

0 comments on commit bc7aea1

Please sign in to comment.