Skip to content

Commit

Permalink
Update aar file,add export wif function and Optimize some functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
healergyl committed Jun 13, 2023
1 parent 95ed402 commit 62fc87e
Show file tree
Hide file tree
Showing 14 changed files with 469 additions and 13 deletions.
Binary file modified app/libs/Obdmobile.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class CreateChannelDialog implements Wallet.ScanChannelListener {
private AlertDialog mAlertDialog;
TextView localEdit;
TextView channelAmountTv;
TextView maxAmountTv;
TextView channelFeeTv;
TextView feePerByteTv;
SelectSpeedPopupWindow mSelectSpeedPopupWindow;
Expand Down Expand Up @@ -336,6 +337,7 @@ private void showStepTwo() {
EditText channelAmountEdit = mAlertDialog.findViewById(R.id.edit_channel_amount);
channelAmountEdit.addTextChangedListener(new DecimalInputTextWatcher(DecimalInputTextWatcher.Type.decimal, 8));
channelAmountTv = mAlertDialog.findViewById(R.id.tv_channel_amount);
maxAmountTv = mAlertDialog.findViewById(R.id.tv_amount_max);
channelFeeTv = mAlertDialog.findViewById(R.id.tv_channel_fee);
feePerByteTv = mAlertDialog.findViewById(R.id.tv_fee_per_byte);
Button amountUnitButton = mAlertDialog.findViewById(R.id.btn_amount_unit);
Expand Down Expand Up @@ -504,6 +506,7 @@ public void onItemClick(View view, ListAssetItemEntity item) {
DecimalFormat df = new DecimalFormat("0.00######");
assetBalanceMax = df.format(Double.parseDouble(String.valueOf(item.getAmount())) / 100000000);
}
maxAmountTv.setText(assetBalanceMax);
channelAmountEdit.setText("");
channelAmountTv.setText("0");
if (!StringUtils.isEmpty(channelAmountEdit.getText().toString())) {
Expand All @@ -518,6 +521,17 @@ public void onItemClick(View view, ListAssetItemEntity item) {
mSelectAssetUnitPopupWindow.show(v);
}
});
/**
* @描述: 增加MAX按钮的点击事件,点击将balance的值填入amount输入框中
* @Description: Add the click event of MAX button, click to fill the balance value into the amount input box
*/
TextView maxTv = mAlertDialog.findViewById(R.id.tv_channel_max);
maxTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
channelAmountEdit.setText(assetBalanceMax);
}
});
/**
* @描述: 点击back
* @desc: click back button
Expand Down Expand Up @@ -915,6 +929,7 @@ public void run() {
DecimalFormat df = new DecimalFormat("0.00######");
assetBalanceMax = df.format(Double.parseDouble(String.valueOf(resp.getConfirmedBalance())) / 100000000);
}
maxAmountTv.setText(assetBalanceMax);
}
});
} catch (InvalidProtocolBufferException e) {
Expand Down
163 changes: 163 additions & 0 deletions app/src/main/java/com/omni/wallet/view/dialog/ExportWifDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package com.omni.wallet.view.dialog;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.protobuf.InvalidProtocolBufferException;
import com.omni.wallet.R;
import com.omni.wallet.baselibrary.dialog.AlertDialog;
import com.omni.wallet.baselibrary.utils.LogUtils;
import com.omni.wallet.baselibrary.utils.StringUtils;
import com.omni.wallet.baselibrary.utils.ToastUtils;
import com.omni.wallet.framelibrary.entity.User;
import com.omni.wallet.utils.CopyUtil;
import com.omni.wallet.utils.SecretAESOperator;

import lnrpc.LightningOuterClass;
import obdmobile.Callback;
import obdmobile.Obdmobile;

/**
* 汉: 导出WIF的弹窗
* En: ExportWifDialog
* author: guoyalei
* date: 2023/6/13
*/
public class ExportWifDialog {
private static final String TAG = ExportWifDialog.class.getSimpleName();
private Context mContext;
private AlertDialog mAlertDialog;
private boolean mCanClick = false;
String wifStr;

public ExportWifDialog(Context context) {
this.mContext = context;
}

public void show() {
if (mAlertDialog == null) {
mAlertDialog = new AlertDialog.Builder(mContext, R.style.dialog_translucent_theme)
.setContentView(R.layout.layout_dialog_export_wif)
.setAnimation(R.style.popup_anim_style)
.fullWidth()
.fullHeight()
.create();
}
EditText mPwdEdit = mAlertDialog.findViewById(R.id.password_input);
mPwdEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
mAlertDialog.findViewById(R.id.btn_unlock).setOnClickListener(v -> unlockWallet());
mAlertDialog.findViewById(R.id.pass_switch).setOnClickListener(v -> {
ImageView mPwdEyeIv = mAlertDialog.findViewById(R.id.pass_switch);
if (mCanClick) {
mCanClick = false;
mPwdEyeIv.setImageResource(R.mipmap.icon_eye_open);
//显示密码(show password)
mPwdEdit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
mCanClick = true;
mPwdEyeIv.setImageResource(R.mipmap.icon_eye_close);
//隐藏密码(hide password)
mPwdEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
});
/**
* @描述: 点击 close
* @desc: click close button
*/
mAlertDialog.findViewById(R.id.layout_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAlertDialog.dismiss();
}
});
if (mAlertDialog.isShowing()) {
mAlertDialog.dismiss();
}
mAlertDialog.show();
}

private void unlockWallet() {
EditText mPwdEdit = mAlertDialog.findViewById(R.id.password_input);
String passwordString = mPwdEdit.getText().toString();
String newSecretString = SecretAESOperator.getInstance().encrypt(passwordString);
boolean passIsMatched = checkedPassMatched(newSecretString);
if (passIsMatched) {
showWif();
} else {
String toastString = mContext.getResources().getString(R.string.toast_unlock_error);
ToastUtils.showToast(mContext, toastString);
}
}

private void showWif() {
mAlertDialog.findViewById(R.id.layout_unlock).setVisibility(View.GONE);
mAlertDialog.findViewById(R.id.layout_wif).setVisibility(View.VISIBLE);
TextView wifTv = mAlertDialog.findViewById(R.id.tv_wif);
LightningOuterClass.DumpPrivkeyRequest dumpPrivkeyRequest = LightningOuterClass.DumpPrivkeyRequest.newBuilder()
.setAddress(User.getInstance().getWalletAddress(mContext))
.build();
Obdmobile.oB_DumpPrivkey(dumpPrivkeyRequest.toByteArray(), new Callback() {
@Override
public void onError(Exception e) {
LogUtils.e(TAG, "------------------dumpPrivkeyOnError------------------" + e.getMessage());
}

@Override
public void onResponse(byte[] bytes) {
if (bytes == null) {
return;
}
try {
LightningOuterClass.DumpPrivkeyResponse resp = LightningOuterClass.DumpPrivkeyResponse.parseFrom(bytes);
LogUtils.e(TAG, "------------------dumpPrivkeyOnResponse------------------" + resp.toString());
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
wifStr = resp.getKeyWif();
wifTv.setText(wifStr);
}
});
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
});
mAlertDialog.findViewById(R.id.iv_copy_wif).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (StringUtils.isEmpty(wifStr)) {
ToastUtils.showToast(mContext, "WIF is empty");
return;
}
//接收需要复制到粘贴板的地址
//Get the address which will copy to clipboard
String toCopyAddress = wifStr;
//接收需要复制成功的提示语
//Get the notice when you copy success
String toastString = "Already copy the WIF to clipboard!";
CopyUtil.SelfCopy(mContext, toCopyAddress, toastString);
}
});
}

public boolean checkedPassMatched(String inputPass) {
boolean isMatched;
String localPass = User.getInstance().getPasswordMd5(mContext);
isMatched = inputPass.equals(localPass);
return isMatched;
}

public void release() {
if (mAlertDialog != null) {
mAlertDialog.dismiss();
mAlertDialog = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.omni.wallet.entity.event.BackUpEvent;
import com.omni.wallet.framelibrary.entity.User;
import com.omni.wallet.ui.activity.channel.ChannelsActivity;
import com.omni.wallet.view.dialog.ExportWifDialog;
import com.omni.wallet.view.dialog.LoadingDialog;
import com.omni.wallet.view.dialog.NewVersionDialog;
import com.omni.wallet.view.dialog.UnlockDialog;
Expand Down Expand Up @@ -147,6 +148,15 @@ public void onClick(View v) {
ToastUtils.showToast(mContext, "Not yet open, please wait");
}
});
// Export WIF
rootView.findViewById(R.id.layout_export_wif).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMenuPopWindow.dismiss();
ExportWifDialog mExportWifDialog = new ExportWifDialog(mContext);
mExportWifDialog.show();
}
});
// node_info
rootView.findViewById(R.id.layout_node_info).setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -156,7 +166,7 @@ public void onClick(View v) {
mNodeInfoPopupWindow.show(view, pubKey);
}
});
// select directory
// select directory
rootView.findViewById(R.id.backup_directory_select).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.omni.wallet.entity.event.BackUpEvent;
import com.omni.wallet.framelibrary.entity.User;
import com.omni.wallet.ui.activity.channel.ChannelsActivity;
import com.omni.wallet.view.dialog.ExportWifDialog;
import com.omni.wallet.view.dialog.LoadingDialog;
import com.omni.wallet.view.dialog.NewVersionDialog;
import com.omni.wallet.view.dialog.UnlockDialog;
Expand Down Expand Up @@ -147,6 +148,15 @@ public void onClick(View v) {
ToastUtils.showToast(mContext, "Not yet open, please wait");
}
});
// Export WIF
rootView.findViewById(R.id.layout_export_wif).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMenuPopWindow.dismiss();
ExportWifDialog mExportWifDialog = new ExportWifDialog(mContext);
mExportWifDialog.show();
}
});
// node_info
rootView.findViewById(R.id.layout_node_info).setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -156,7 +166,7 @@ public void onClick(View v) {
mNodeInfoPopupWindow.show(view, pubKey);
}
});
// select directory
// select directory
rootView.findViewById(R.id.backup_directory_select).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.omni.wallet.entity.event.BackUpEvent;
import com.omni.wallet.framelibrary.entity.User;
import com.omni.wallet.ui.activity.channel.ChannelsActivity;
import com.omni.wallet.view.dialog.ExportWifDialog;
import com.omni.wallet.view.dialog.LoadingDialog;
import com.omni.wallet.view.dialog.NewVersionDialog;
import com.omni.wallet.view.dialog.UnlockDialog;
Expand Down Expand Up @@ -145,6 +146,15 @@ public void onClick(View v) {
ToastUtils.showToast(mContext, "Not yet open, please wait");
}
});
// Export WIF
rootView.findViewById(R.id.layout_export_wif).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMenuPopWindow.dismiss();
ExportWifDialog mExportWifDialog = new ExportWifDialog(mContext);
mExportWifDialog.show();
}
});
// node_info
rootView.findViewById(R.id.layout_node_info).setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -154,7 +164,7 @@ public void onClick(View v) {
mNodeInfoPopupWindow.show(view, pubKey);
}
});
// select directory
// select directory
rootView.findViewById(R.id.backup_directory_select).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Loading

0 comments on commit 62fc87e

Please sign in to comment.