diff --git a/app/libs/Obdmobile.aar b/app/libs/Obdmobile.aar index 8d4257dd..2f124650 100644 Binary files a/app/libs/Obdmobile.aar and b/app/libs/Obdmobile.aar differ diff --git a/app/src/main/java/com/omni/wallet/view/dialog/CreateChannelDialog.java b/app/src/main/java/com/omni/wallet/view/dialog/CreateChannelDialog.java index 3ec08eea..845d212c 100644 --- a/app/src/main/java/com/omni/wallet/view/dialog/CreateChannelDialog.java +++ b/app/src/main/java/com/omni/wallet/view/dialog/CreateChannelDialog.java @@ -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; @@ -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); @@ -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())) { @@ -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 @@ -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) { diff --git a/app/src/main/java/com/omni/wallet/view/dialog/ExportWifDialog.java b/app/src/main/java/com/omni/wallet/view/dialog/ExportWifDialog.java new file mode 100644 index 00000000..ae2023c7 --- /dev/null +++ b/app/src/main/java/com/omni/wallet/view/dialog/ExportWifDialog.java @@ -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; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/omni/wallet/view/popupwindow/Menu1PopupWindow.java b/app/src/main/java/com/omni/wallet/view/popupwindow/Menu1PopupWindow.java index b3583ee5..56c66851 100644 --- a/app/src/main/java/com/omni/wallet/view/popupwindow/Menu1PopupWindow.java +++ b/app/src/main/java/com/omni/wallet/view/popupwindow/Menu1PopupWindow.java @@ -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; @@ -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 @@ -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) { diff --git a/app/src/main/java/com/omni/wallet/view/popupwindow/Menu2PopupWindow.java b/app/src/main/java/com/omni/wallet/view/popupwindow/Menu2PopupWindow.java index 1b41bc8a..2ed4bb65 100644 --- a/app/src/main/java/com/omni/wallet/view/popupwindow/Menu2PopupWindow.java +++ b/app/src/main/java/com/omni/wallet/view/popupwindow/Menu2PopupWindow.java @@ -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; @@ -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 @@ -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) { diff --git a/app/src/main/java/com/omni/wallet/view/popupwindow/MenuPopupWindow.java b/app/src/main/java/com/omni/wallet/view/popupwindow/MenuPopupWindow.java index ec2d74e3..a8a889fa 100644 --- a/app/src/main/java/com/omni/wallet/view/popupwindow/MenuPopupWindow.java +++ b/app/src/main/java/com/omni/wallet/view/popupwindow/MenuPopupWindow.java @@ -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; @@ -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 @@ -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) { diff --git a/app/src/main/res/layout/layout_dialog_export_wif.xml b/app/src/main/res/layout/layout_dialog_export_wif.xml new file mode 100644 index 00000000..71f494dd --- /dev/null +++ b/app/src/main/res/layout/layout_dialog_export_wif.xml @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_popupwindow_create_channel_stepone.xml b/app/src/main/res/layout/layout_popupwindow_create_channel_stepone.xml index eaea5b7c..689438e3 100644 --- a/app/src/main/res/layout/layout_popupwindow_create_channel_stepone.xml +++ b/app/src/main/res/layout/layout_popupwindow_create_channel_stepone.xml @@ -379,14 +379,41 @@ android:layout_marginTop="@dimen/main_15" android:background="@color/color_80p_transparent"> - + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + + + + + + + + + Amount Fee SLOW - unit per byte - satoshi per byte + sat/vB + sat/vB PAY INVOICE Fill invoice Check & Pay diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d806bbee..ebb73a52 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,8 +101,8 @@ Amount Fee SLOW - unit per byte - satoshi per byte + sat/vB + sat/vB PAY INVOICE Fill invoice Check & Pay diff --git a/baselibrary/src/main/java/com/omni/wallet/baselibrary/utils/ToastUtils.java b/baselibrary/src/main/java/com/omni/wallet/baselibrary/utils/ToastUtils.java index a1f2ac09..3bb50785 100644 --- a/baselibrary/src/main/java/com/omni/wallet/baselibrary/utils/ToastUtils.java +++ b/baselibrary/src/main/java/com/omni/wallet/baselibrary/utils/ToastUtils.java @@ -13,7 +13,8 @@ public class ToastUtils { // public static void showToast(Context context, CharSequence msg) { - CustomToast.showCenterShortToast(context, msg, 0); +// CustomToast.showCenterShortToast(context, msg, 0); + CustomToast.showCenterLongToast(context, msg, 0); } public static void showToast(Context context, int res) {