Search in sources :

Example 1 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class Utils method getWalletName.

/**
 * Name to get the wallet
 * @ param context context Wallet name name is empty
 */
public static String getWalletName(Context context) {
    int index = 1;
    String walletName;
    while (true) {
        walletName = context.getString(R.string.account) + index;
        boolean foundSameName = false;
        for (StorableWallet storableWallet : WalletStorage.getInstance(context).get()) {
            if (walletName.equals(storableWallet.getWalletName())) {
                foundSameName = true;
                break;
            }
        }
        if (foundSameName) {
            index++;
        } else {
            break;
        }
    }
    return walletName;
}
Also used : StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet)

Example 2 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class WalletCreateActivity method onClick.

// 
@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.clearWalletName:
            walletName.setText("");
            break;
        case R.id.isShowPass:
            isShowPassWorld = !isShowPassWorld;
            if (isShowPassWorld) {
                /*  */
                walletPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                isShowPass.setImageResource(R.drawable.eye_open);
            } else {
                /* */
                walletPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                isShowPass.setImageResource(R.drawable.eye_close);
            }
            break;
        case R.id.createWallet:
            if (walletName.length() > 12 || walletName.length() <= 0) {
                showToast(getString(R.string.wallet_name_warning));
                return;
            }
            if (walletPwd.length() > 16 || walletPwd.length() < 6) {
                showToast(getString(R.string.wallet_pwd_warning));
                return;
            }
            String password = walletPwd.getText().toString().trim();
            String name = walletName.getText().toString().trim();
            String pwdInfo = walletPwdInfo.getText().toString().trim();
            if (TextUtils.equals(password, walletAgainPwd.getText().toString().trim())) {
                for (StorableWallet storableWallet : WalletStorage.getInstance(getApplicationContext()).get()) {
                    if (name.equals(storableWallet.getWalletName())) {
                        showToast(getString(R.string.account_name_exist));
                        return;
                    }
                }
                LoadingDialog.show(WalletCreateActivity.this, getString(R.string.wallet_create_ing));
                new WalletThread(mHandler, getApplicationContext(), name, password, pwdInfo, null, 0).start();
            } else {
                showToast(getString(R.string.account_pwd_again_warning));
            }
            break;
        default:
            super.onClick(v);
    }
}
Also used : StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet)

Example 3 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class WalletScanFragment method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.importWallet:
            String address = walletAddress.getText().toString();
            if (TextUtils.isEmpty(address) || address.length() != 42 || !address.startsWith("0x")) {
                MyToast.showToast(getActivity(), getString(R.string.wallet_scan_warning));
                return;
            }
            address = address.substring(2);
            boolean exists = WalletStorage.getInstance(getActivity().getApplicationContext()).checkExists(address);
            if (!exists) {
                StorableWallet storableWallet = new StorableWallet();
                storableWallet.setPublicKey(address);
                storableWallet.setWalletType(1);
                storableWallet.setWalletName(Utils.getWalletName(getActivity()));
                if (WalletStorage.getInstance(getActivity().getApplicationContext()).get().size() <= 0) {
                    storableWallet.setSelect(true);
                }
                WalletStorage.getInstance(getActivity().getApplicationContext()).add(storableWallet, getActivity());
                MyToast.showToast(getActivity(), getString(R.string.notification_wallimp_finished));
                Utils.sendBroadcastReceiver(getActivity(), new Intent(Constants.WALLET_SUCCESS), false);
                startActivity(new Intent(getActivity(), MainFragmentUI.class));
                getActivity().setResult(Activity.RESULT_OK);
                getActivity().finish();
            } else {
                MyToast.showToast(getActivity(), getString(R.string.notification_wallimp_repeat));
            }
            break;
        case R.id.walletQrImg:
            Intent i = new Intent(getActivity(), CaptureActivity.class);
            i.putExtra("type", 2);
            startActivityForResult(i, 100);
            break;
    }
}
Also used : StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) Intent(android.content.Intent) MainFragmentUI(com.lingtuan.firefly.ui.MainFragmentUI)

Example 4 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class WalletStorage method addWalletArray.

/**
 * load wallet list
 * @param context context
 * @param walletArray wallet json array
 */
private void addWalletArray(Context context, JSONArray walletArray, boolean needAdd) {
    if (walletArray == null) {
        return;
    }
    for (int i = 0; i < walletArray.length(); i++) {
        JSONObject walletObj = walletArray.optJSONObject(i);
        StorableWallet storableWallet = new StorableWallet();
        storableWallet.setPublicKey(walletObj.optString(Constants.WALLET_ADDRESS));
        storableWallet.setWalletName(walletObj.optString(Constants.WALLET_NAME));
        storableWallet.setCanExportPrivateKey(walletObj.optInt(Constants.WALLET_EXTRA));
        storableWallet.setBackup(walletObj.optBoolean(Constants.WALLET_BACKUP));
        if (i == 0) {
            storableWallet.setSelect(true);
        } else {
            storableWallet.setSelect(false);
        }
        File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), storableWallet.getPublicKey());
        if (!destination.exists()) {
            storableWallet.setWalletType(1);
        }
        if (needAdd) {
            addWalletToList(NextApplication.mContext, storableWallet);
        }
        mapdb.add(storableWallet);
    }
}
Also used : JSONObject(org.json.JSONObject) StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) File(java.io.File)

Example 5 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class WalletStorage method load.

/**
 * Read in json
 */
@SuppressWarnings("unchecked")
public synchronized void load(Context context) throws IOException, ClassNotFoundException {
    String walletList = MySharedPrefs.readWalletList(context);
    if (TextUtils.isEmpty(walletList)) {
        return;
    }
    try {
        JSONObject object = new JSONObject(walletList);
        JSONArray walletArray = object.optJSONArray("data");
        for (int i = 0; i < walletArray.length(); i++) {
            JSONObject walletObj = walletArray.optJSONObject(i);
            StorableWallet storableWallet = new StorableWallet();
            storableWallet.setPublicKey(walletObj.optString(Constants.WALLET_ADDRESS));
            storableWallet.setWalletName(walletObj.optString(Constants.WALLET_NAME));
            storableWallet.setCanExportPrivateKey(walletObj.optInt(Constants.WALLET_EXTRA));
            storableWallet.setBackup(walletObj.optBoolean(Constants.WALLET_BACKUP));
            if (i == 0) {
                storableWallet.setSelect(true);
            }
            File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), storableWallet.getPublicKey());
            if (!destination.exists()) {
                storableWallet.setWalletType(1);
            }
            mapdb.add(storableWallet);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) JSONException(org.json.JSONException) File(java.io.File)

Aggregations

StorableWallet (com.lingtuan.firefly.wallet.vo.StorableWallet)15 Intent (android.content.Intent)5 File (java.io.File)5 JSONObject (org.json.JSONObject)4 SuppressLint (android.annotation.SuppressLint)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 MainFragmentUI (com.lingtuan.firefly.ui.MainFragmentUI)2 Handler (android.os.Handler)1 Message (android.os.Message)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 OptionPicker (com.lingtuan.firefly.custom.picker.OptionPicker)1 WheelView (com.lingtuan.firefly.custom.picker.WheelView)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 ArrayList (java.util.ArrayList)1 CipherException (org.web3j.crypto.CipherException)1