class WalletManager {

    public Wallet getWalletByAddress(String address) {

        boolean isCacheExists = false;
        if (TextUtils.isEmpty(address)) {
            return null;
        }

        for (Wallet walletEntity : mWalletList) {
            if (walletEntity.getPrefixAddress().toLowerCase().contains(address.toLowerCase())) {

                if(walletEntity.isHD() && walletEntity.getDepth() == WalletDepth.DEPTH_ONE){
                    Wallet rootWallet = WalletManager.getInstance().getWalletInfoByUuid(walletEntity.getParentId());
                    walletEntity.setMnemonic(rootWallet.getMnemonic());
                    walletEntity.setKey(rootWallet.getKey());
                    isCacheExists = true;
                }
                return walletEntity;
            }
        }

        if(!isCacheExists){

            Wallet wallet = WalletManager.getInstance().getWalletInfoByAddress(address);
            if(wallet.isHD() && wallet.getDepth() == WalletDepth.DEPTH_ONE){
                Wallet rootWallet = WalletManager.getInstance().getWalletInfoByUuid(wallet.getParentId());
                wallet.setMnemonic(rootWallet.getMnemonic());
                wallet.setKey(rootWallet.getKey());
            }
            return wallet;
        }
        return Wallet.getNullInstance();
    }

    private  WalletManager();

}