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

Dragons deeplink and analytics #6

Open
wants to merge 2 commits into
base: rc_1.3.0_browser
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
Expand All @@ -39,10 +40,12 @@
import io.multy.R;
import io.multy.api.MultyApi;
import io.multy.model.entities.Estimation;
import io.multy.model.entities.MultisigFactory;
import io.multy.model.entities.wallet.Owner;
import io.multy.model.entities.wallet.Wallet;
import io.multy.model.entities.wallet.WalletPrivateKey;
import io.multy.model.requests.HdTransactionRequestEntity;
import io.multy.model.responses.ServerConfigResponse;
import io.multy.storage.RealmManager;
import io.multy.ui.adapters.OwnersAdapter;
import io.multy.ui.fragments.MultisigSettingsFragment;
Expand Down Expand Up @@ -307,6 +310,23 @@ private void onProgress(boolean isLoading) {
}
}

private void getServerConfig() {
MultyApi.INSTANCE.getServerConfig().enqueue(new Callback<ServerConfigResponse>() {
@Override
public void onResponse(@NonNull Call<ServerConfigResponse> call, @NonNull Response<ServerConfigResponse> response) {
ServerConfigResponse body = response.body();
if (body != null && body.getMultisigFactory() != null) {
RealmManager.getSettingsDao().saveMultisigFactory(body.getMultisigFactory());
}
}

@Override
public void onFailure(@NonNull Call<ServerConfigResponse> call, @NonNull Throwable t) {
t.printStackTrace();
}
});
}

public void showProgressDialog() {
if (progressDialog == null) {
progressDialog = new Dialog(this);
Expand Down Expand Up @@ -337,12 +357,19 @@ public void onClickAction(View view) {
.commit();

} else {
Wallet linkedWallet = viewModel.getLinkedWallet().getValue();
MultisigFactory multisigFactory = RealmManager.getSettingsDao().getMultisigFactory();
if (multisigFactory == null || TextUtils.isEmpty(multisigFactory.getEthMainNet()) ||
TextUtils.isEmpty(multisigFactory.getEthTestNet())) {
showError(new NullPointerException("Multisig factory address is empty!"));
getServerConfig();
return;
}
view.setEnabled(false);
final String priceOfCreation = (String) textAction.getTag();
final byte[] seed = RealmManager.getSettingsDao().getSeed().getSeed();
String factoryAddress = null;
Wallet multisigWallet = viewModel.getMultisigWallet().getValue();
Wallet linkedWallet = viewModel.getLinkedWallet().getValue();
if (linkedWallet.getCurrencyId() == NativeDataHelper.Blockchain.ETH.getValue() &&
linkedWallet.getNetworkId() == NativeDataHelper.NetworkId.RINKEBY.getValue()) {
factoryAddress = RealmManager.getSettingsDao().getMultisigFactory().getEthTestNet();
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/io/multy/ui/adapters/PortfoliosAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.multy.Multy;
import io.multy.R;
import io.multy.model.entities.OpenDragonsEvent;
import io.multy.ui.fragments.dialogs.DonateDialog;
import io.multy.util.Constants;
import io.multy.util.analytics.Analytics;
import io.multy.util.analytics.AnalyticsConstants;

/**
* Created by appscrunch on 16.11.17.
Expand Down Expand Up @@ -87,6 +87,7 @@ public Object instantiateItem(@NonNull ViewGroup container, int position) {
v.setEnabled(false);
v.postDelayed(() -> v.setEnabled(true), 500);
if (position == 0) {
Analytics.getInstance(v.getContext()).logEvent(AnalyticsConstants.MAIN_SCREEN, AnalyticsConstants.DRAGONS_BANNER_CLICK, null);
EventBus.getDefault().post(new OpenDragonsEvent());
} else {
DonateDialog.getInstance((Integer) v.getTag()).show(fragmentManager, DonateDialog.TAG);
Expand Down
31 changes: 23 additions & 8 deletions app/src/main/java/io/multy/ui/fragments/Web3Fragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import io.multy.util.Constants;
import io.multy.util.CryptoFormatUtils;
import io.multy.util.NativeDataHelper;
import io.multy.util.analytics.Analytics;
import io.multy.util.analytics.AnalyticsConstants;
import io.multy.viewmodels.WalletViewModel;
import io.realm.RealmResults;
import okhttp3.ResponseBody;
Expand Down Expand Up @@ -101,6 +103,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
return convertView;
}

@Override
public void onResume() {
super.onResume();
Analytics.getInstance(requireContext()).logEvent(AnalyticsConstants.WEB3_SCREEN, AnalyticsConstants.BROWSER_OPEN + dappUrl, dappUrl);
}

@Override
public void onDestroy() {
// if (requireActivity().getIntent().hasExtra(Constants.EXTRA_URL)) {
Expand Down Expand Up @@ -292,7 +300,7 @@ void onDestroy() {
}

private void initState() {
webView.setRpcUrl("https://rinkeby.infura.io/v3/78ae782ed28e48c0b3f74ca69c4f7ca8");
// webView.setRpcUrl("https://rinkeby.infura.io/v3/78ae782ed28e48c0b3f74ca69c4f7ca8");
webView.requestFocus();
webView.setOnSignMessageListener(message -> {
Timber.d("onSignMessage:" + message.value);
Expand Down Expand Up @@ -324,15 +332,18 @@ private void initState() {
final String finalPriceAmount = priceAmount;

AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setMessage("You are going to spend " + CryptoFormatUtils.weiToEthLabel(finalPriceAmount) +
" (and " + ethPrice + " in fees) from wallet " + viewModel.getWalletLive().getValue().getWalletName());
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Confirm", (dialog, which) -> {
String message = String.format(getString(R.string.you_going_spend), CryptoFormatUtils.weiToEthLabel(finalPriceAmount),
ethPrice, viewModel.getWalletLive().getValue().getWalletName());
alertDialog.setMessage(message);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.confirmation), (dialog, which) -> {
try {
Wallet wallet = viewModel.getWalletLive().getValue();
byte[] seed = RealmManager.getSettingsDao().getSeed().getSeed();
final int currencyId = wallet.getCurrencyId();
final int networkId = wallet.getNetworkId();
final byte[] tx = NativeDataHelper.makeTransactionEthPayload(seed, wallet.getIndex(), wallet.getActiveAddress().getIndex(),
wallet.getCurrencyId(), wallet.getNetworkId(), wallet.getBalance(), finalPriceAmount,
transaction.recipient.toString(), String.valueOf(transaction.gasLimit), transaction.gasPrice.toString(), wallet.getEthWallet().getNonce(), transaction.payload.replace("0x", ""));
currencyId, networkId, wallet.getBalance(), finalPriceAmount, transaction.recipient.toString(), String.valueOf(transaction.gasLimit),
transaction.gasPrice.toString(), wallet.getEthWallet().getNonce(), transaction.payload.replace("0x", ""));
Timber.i("start converting to hex");
final String hex = "0x" + SendSummaryFragment.byteArrayToHex(tx);
Timber.i("hex converted " + hex);
Expand All @@ -350,6 +361,10 @@ private void initState() {
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.isSuccessful()) {
Timber.i("BUYING SUCCESS");
if (getContext() != null) {
Analytics.getInstance(getContext()).logBrowserSendTx(dappUrl, currencyId, networkId, finalPriceAmount,
String.valueOf(transaction.gasLimit), transaction.gasPrice.toString());
}
} else {
Timber.i("BUYING FAIL");
webView.onSignError(transaction, response.message());
Expand All @@ -369,7 +384,7 @@ public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
webView.onSignError(transaction, e.getMessage());
}
});
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Deny", new DialogInterface.OnClickListener() {
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.deny), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
webView.onSignError(transaction, "Canceled");
Expand All @@ -391,7 +406,7 @@ private void setWallet(long walletId) {
Wallet wallet = viewModel.getWallet(walletId);
fillWalletInfo(wallet);
webView.setWalletAddress(new Address(wallet.getActiveAddress().getAddress()));
webView.setRpcUrl(wallet.getNetworkId() == NativeDataHelper.NetworkId.TEST_NET.getValue() ?
webView.setRpcUrl(wallet.getNetworkId() == NativeDataHelper.NetworkId.RINKEBY.getValue() ?
"https://rinkeby.infura.io/v3/78ae782ed28e48c0b3f74ca69c4f7ca8" : "https://mainnet.infura.io/v3/78ae782ed28e48c0b3f74ca69c4f7ca8");
webView.setChainId(wallet.getNetworkId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import io.multy.model.responses.AuthResponse;
import io.multy.model.responses.ServerConfigResponse;
import io.multy.storage.RealmManager;
import io.multy.storage.SettingsDao;
import io.multy.ui.fragments.BaseSeedFragment;
import io.multy.util.BrickView;
import io.multy.util.Constants;
Expand Down Expand Up @@ -258,25 +257,23 @@ public void restore(String phrase, Context context, Runnable callback) {
final String userId = NativeDataHelper.makeAccountId(seed);
MultyApi.INSTANCE.auth(userId).enqueue(new Callback<AuthResponse>() {
@Override
public void onResponse(Call<AuthResponse> call, Response<AuthResponse> response) {
public void onResponse(@NonNull Call<AuthResponse> call, @NonNull Response<AuthResponse> response) {
if (response.isSuccessful()) {

final boolean initialized = Multy.makeInitialized();
if (!initialized) {
onSeedRestoreFailure(callback);
return;
}
Realm.deleteRealm(Realm.getDefaultConfiguration());
RealmManager.open();
SettingsDao settingsDao = RealmManager.getSettingsDao();
settingsDao.setUserId(new UserId(userId));
settingsDao.setByteSeed(new ByteSeed(seed));
settingsDao.setMnemonic(new Mnemonic(phrase));
RealmManager.getSettingsDao().setUserId(new UserId(userId));
RealmManager.getSettingsDao().setByteSeed(new ByteSeed(seed));
RealmManager.getSettingsDao().setMnemonic(new Mnemonic(phrase));
ServerConfigResponse serverConfig = EventBus.getDefault().removeStickyEvent(ServerConfigResponse.class);
if (serverConfig != null) {
settingsDao.saveDonation(serverConfig.getDonates());
RealmManager.getSettingsDao().saveDonation(serverConfig.getDonates());
RealmManager.getSettingsDao().saveMultisigFactory(serverConfig.getMultisigFactory());
}
settingsDao.saveMultisigFactory(serverConfig.getMultisigFactory());
RealmManager.close();

Prefs.putString(Constants.PREF_AUTH, response.body().getToken());
Expand All @@ -290,7 +287,7 @@ public void onResponse(Call<AuthResponse> call, Response<AuthResponse> response)
}

@Override
public void onFailure(Call<AuthResponse> call, Throwable t) {
public void onFailure(@NonNull Call<AuthResponse> call, @NonNull Throwable t) {
onSeedRestoreFailure(callback);
}
});
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/io/multy/util/analytics/Analytics.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,17 @@ public void logContactPhoneBook() {
logEvent(AnalyticsConstants.CONTACT_EVENT, AnalyticsConstants.CONTACT_PHONEBOOK_OPENED, null);
}

public void logBrowserSendTx(String url, int currencyId, int networkId, String amount, String gasLimit, String gasPrice) {
Bundle bundle = new Bundle();
bundle.putString(AnalyticsConstants.BROWSER_URL, url);
bundle.putInt(AnalyticsConstants.CURRENCY_ID, currencyId);
bundle.putInt(AnalyticsConstants.NETWORK_ID, networkId);
bundle.putString(AnalyticsConstants.AMOUNT, amount);
bundle.putString(AnalyticsConstants.GAS_LIMIT, gasPrice);
bundle.putString(AnalyticsConstants.GAS_PRICE, gasLimit);
analytics.logEvent(AnalyticsConstants.WEB3_SCREEN, bundle);
}

public void logEvent(String event, String argumentName, String argument) {
Bundle bundle = new Bundle();
bundle.putString(argumentName, argument);
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/io/multy/util/analytics/AnalyticsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,14 @@ public class AnalyticsConstants {
public static final String KF_PERMISSIONS_GRANTED = "KF_Permissions_Granted";
public static final String KF_WALLET_COUNT = "KF_Wallets_Count";
public static final String KF_RECEIVED_TRANSACTION = "KF_Transaction_Received";

public static final String DRAGONS_BANNER_CLICK = "Dragon_Banner_Clicked";
public static final String WEB3_SCREEN = "Screen_Browser";
public static final String BROWSER_OPEN = "loading URL ";
public static final String BROWSER_URL = "URL";
public static final String CURRENCY_ID = "Blockchain";
public static final String NETWORK_ID = "NetType";
public static final String AMOUNT = "Amount";
public static final String GAS_LIMIT = "GasPrice";
public static final String GAS_PRICE = "GasLimit";
}
3 changes: 3 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,7 @@
<string name="about_imported">Обратите внимание, что импортированные кошельки нельзя восстановить из seed фразы на другом устройстве. Вы должны сделать резервную копию своего личного ключа, чтобы защитить свои средства, поэтому вы можете импортировать его позже на другое устройство.</string>
<string name="enter_sum_too_much">Вы пытаетесь ввести сумму больше, чем у вас есть на счету</string>
<string name="browser">Браузер</string>
<string name="you_going_spend">Вы потратите %s ETH (и %s ETH комиссии) из кошелька "%s"</string>
<string name="confirm">Подтвердить</string>
<string name="deny">Отменить</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,7 @@
<string name="imported_wallet">Імпортований гаманець</string>
<string name="about_imported">Зверніть увагу, що імпортовані гаманці не можна відновити з seed фрази на іншому пристрої. Ви повинні зробити резервну копію свого особистого ключа, щоб захистити свої кошти, тому ви можете імпортувати його пізніше на інший пристрій.</string>
<string name="enter_sum_too_much">Ви намагаєтеся ввести суму більшу, ніж у вас є на рахунку</string>
<string name="you_going_spend">Ви витратите %s ETH (і %s ETH комісії) з гаманця "%s"</string>
<string name="confirm">Затверджувати</string>
<string name="deny">Відкидати</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,7 @@
<string name="about_imported">Please note that imported wallets can\'t be restored from seed phrase on other device. You should backup your private key in order to secure your funds, so you can import it later on other device.</string>
<string name="enter_sum_too_much">You trying to enter sum more then you have</string>
<string name="browser">Browser</string>
<string name="you_going_spend">You are going to spend %s ETH (and %s ETH in fees) from wallet "%s"</string>
<string name="confirm">Confirm</string>
<string name="deny">Deny</string>
</resources>