Skip to content

Commit

Permalink
Merge pull request #135 from ostdotcom/develop
Browse files Browse the repository at this point in the history
Preparing for release v2.3.4
  • Loading branch information
AniketAyachit authored Oct 3, 2019
2 parents 73ec85f + 05280b5 commit 955d93e
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# OST Wallet SDK Changelog

## Version 2.3.4
### Bug Fixes:
* Device list inconsistency fix in manage devices.
* User entity current device caching fix.
* Converted Toast error message of enter mnemonics view to inline error message

## Version 2.3.3
### Changes:
* Proguard usage to remove verbose and debug logs.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ compileOptions {

```
dependencies {
implementation 'com.ost:ost-wallet-sdk-android:2.3.3'
implementation 'com.ost:ost-wallet-sdk-android:2.3.4'
...
...
...
Expand Down
4 changes: 2 additions & 2 deletions ostsdk/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
# org.gradle.parallel=true

#Increase version when publishing.
VERSION_NAME=2.3.3
VERSION_NAME=2.3.4
#Increase version code when publishing.
VERSION_CODE=38
VERSION_CODE=43

#Everything else.
GROUP=com.ost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class OstDeviceManagerModelRepository extends OstBaseModelCacheRepository implements OstDeviceManagerModel {

private static final int LRU_CACHE_SIZE = 5;
private static final int LRU_CACHE_SIZE = 150;
private OstDeviceManagerDao mOstDeviceManagerDao;

OstDeviceManagerModelRepository() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class OstSessionModelRepository extends OstBaseModelCacheRepository implements OstSessionModel {

private static final int LRU_CACHE_SIZE = 5;
private static final int LRU_CACHE_SIZE = 150;
private OstSessionDao mOstSessionDao;

OstSessionModelRepository() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class OstTransactionModelRepository extends OstBaseModelCacheRepository implements OstTransactionModel {

private static final int LRU_CACHE_SIZE = 5;
private static final int LRU_CACHE_SIZE = 150;
private OstTransactionDao mOstTransactionDao;

OstTransactionModelRepository() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static String getIdentifier() {
}

@Ignore
private OstDevice currentDevice = null;
private String mCurrentDeviceAddress = null;

public static OstUser getById(String id) {
return OstModelFactory.getUserModel().getEntityById(id);
Expand All @@ -75,14 +75,17 @@ public static OstUser init(String id, String tokenId) {
}

public OstDevice getCurrentDevice() {
if (null == currentDevice) {
OstDevice currentDevice = null;
if (null == mCurrentDeviceAddress) {
OstKeyManager ostKeyManager = new OstKeyManager(getId());
String currentDeviceAddress = ostKeyManager.getDeviceAddress();
if (null != currentDeviceAddress) {
currentDevice = OstDevice.getById(currentDeviceAddress);
Log.d(TAG, String.format("currentDeviceAddress: %s", currentDeviceAddress));
mCurrentDeviceAddress = ostKeyManager.getDeviceAddress();
if (null == mCurrentDeviceAddress) {
Log.e(TAG, "Current Device address is null, seems like device has been revoked");
return null;
}
}
Log.d(TAG, String.format("currentDeviceAddress: %s", mCurrentDeviceAddress));
currentDevice = OstDevice.getById(mCurrentDeviceAddress);
return currentDevice;
}

Expand Down Expand Up @@ -289,7 +292,7 @@ public boolean isActivating() {
}

public void flushCurrentDevice() {
this.currentDevice = null;
this.mCurrentDeviceAddress = null;
}

public UserStatus getUserStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.ost.walletsdk.ui.sdkInteract.SdkInteract;
import com.ost.walletsdk.ui.sdkInteract.WorkFlowListener;
import com.ost.walletsdk.ui.uicomponents.AppBar;
import com.ost.walletsdk.ui.uicomponents.OstTextView;
import com.ost.walletsdk.ui.uicomponents.uiutils.content.ContentConfig;
import com.ost.walletsdk.ui.uicomponents.uiutils.content.StringConfig;

Expand All @@ -45,6 +46,8 @@ public class EnterMnemonicsFragment extends BaseFragment implements EnterMnemoni
EnterMnemonicsPresenter mEnterMnemonicsPresenter = EnterMnemonicsPresenter.getInstance();

JSONObject contentConfig = ContentConfig.getInstance().getStringConfig("add_current_device_with_mnemonics").optJSONObject("provide_mnemonics");
private OstTextView mErrorMessage;

public EnterMnemonicsFragment() {
// Required empty public constructor
}
Expand Down Expand Up @@ -110,6 +113,8 @@ public void onClick(View v) {
}
});

mErrorMessage = viewGroup.findViewById(R.id.otv_error_message);

mEnterMnemonicsPresenter.attachView(this);
AppBar appBar = AppBar.newInstance(getContext(), false);
setUpAppBar(viewGroup, appBar);
Expand All @@ -121,4 +126,13 @@ public void onDestroyView() {
mEnterMnemonicsPresenter.detachView();
mEnterMnemonicsPresenter = null;
}

@Override
public void showErrorMessage(boolean show) {
if (show) {
mErrorMessage.setVisibility(View.VISIBLE);
} else {
mErrorMessage.setVisibility(View.INVISIBLE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ void recoverWallet(String mnemonicsPhrase) {
//mnemonics validation
String[] mnemonicsArray = mnemonicsPhrase.split(" ");
if (mnemonicsArray.length != 12) {
getMvpView().showToastMessage("Mnemonics length should be of 12 words", false);
getMvpView().showErrorMessage(true);
return;
}
getMvpView().showErrorMessage(false);

getMvpView().showProgress(true, StringConfig.instance(contentConfig.optJSONObject("initial_loader")).getString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
import com.ost.walletsdk.ui.BaseView;

interface EnterMnemonicsView extends BaseView {

void showErrorMessage(boolean show);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class DeviceListFragment extends BaseFragment implements DeviceListView {
private static final String ACTION_NAME = "action_name";
private static final String INITIATED_RECOVERY = "initiate_recovery";
private static final String MANAGE_DEVICE = "manage_device";
private static final int SCROLL_ITEM_THRESHOLD = 5;
public JSONObject contentConfig = new JSONObject();

private DeviceListRecyclerViewAdapter.OnDeviceListInteractionListener mListener;
Expand Down Expand Up @@ -148,8 +149,8 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = layoutManager.getItemCount();
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
if (!paginationRequestSent && dy > 0 && (visibleItemCount + firstVisibleItemPosition) >=
totalItemCount && firstVisibleItemPosition >= 0) {
if (!paginationRequestSent && dy > 0 && (SCROLL_ITEM_THRESHOLD + firstVisibleItemPosition) >=
totalItemCount) {
paginationRequestSent = true;
mDeviceListPresenter.updateDeviceList(false);
}
Expand Down Expand Up @@ -197,5 +198,6 @@ public void notifyDataSetChanged() {
@Override
public void setRefreshing(boolean refreshing) {
mPullToRefresh.setRefreshing(refreshing);
paginationRequestSent = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@

class DeviceListPresenter extends BasePresenter<DeviceListView> {
private static final String LOG_TAG = "OstDeviceListPresenter";
private static final int MINIMUM_DEVICES = 5;
private String mUserId;
private String currentDeviceAddress;
private String mLoaderString = "Loading...";
private boolean mRunningLoader = false;
private boolean mClearDeviceList;

private DeviceListPresenter() {}

Expand All @@ -59,57 +61,72 @@ public void attachView(DeviceListView mvpView) {
updateDeviceList(true);
}

void updateDeviceList(Boolean clearList) {
void updateDeviceList(boolean clearList) {
if(httpRequestPending){
return;
}
httpRequestPending = true;
if(clearList){
mClearDeviceList = true;
nextPayload = new JSONObject();
} else if(!hasMoreData){
return;
}
httpRequestPending = true;
showProgress(true);
getDeviceList();
}

private void getDeviceList() {
Map<String ,Object> mapPayload = new HashMap<>();
try {
mapPayload = new CommonUtils().convertJsonToMap(nextPayload);
} catch (JSONException e) {
Log.e(LOG_TAG, "Exception while converting payload map", e);
}
showProgress(true);
OstJsonApi.getDeviceList(mUserId, mapPayload, new OstJsonApiCallback() {
@Override
public void onOstJsonApiSuccess(@Nullable JSONObject dataJSONObject) {
showLoaderProgress(false);
showProgress(false);
if (null == dataJSONObject) {
httpRequestPending = false;
return;
}
try {
JSONObject meta = dataJSONObject.optJSONObject("meta");
if (null != meta) nextPayload = meta.optJSONObject("next_page_payload");

hasMoreData = (nextPayload != null && !nextPayload.toString().equals("{}"));
JSONArray deviceJSONArray = (JSONArray) dataJSONObject.get(dataJSONObject.getString(OstConstants.RESULT_TYPE));

if (clearList) ostDeviceList.clear();
for (int i = 0; i < deviceJSONArray.length(); i++) {
JSONObject deviceJSONObject = deviceJSONArray.getJSONObject(i);
Device device = Device.newInstance(deviceJSONObject);
if (device.isAuthorized() && !device.getDeviceAddress().equalsIgnoreCase(currentDeviceAddress)) {
ostDeviceList.add(device);
if (null != dataJSONObject) {
try {
JSONObject meta = dataJSONObject.optJSONObject("meta");
if (null != meta) nextPayload = meta.optJSONObject("next_page_payload");


hasMoreData = (nextPayload != null && !nextPayload.toString().equals("{}"));
JSONArray deviceJSONArray = (JSONArray) dataJSONObject.get(dataJSONObject.getString(OstConstants.RESULT_TYPE));

//Clear list if new device request received
if (mClearDeviceList) {
ostDeviceList.clear();
mClearDeviceList = false;
}

//Populate authorized device in the list
for (int i = 0; i < deviceJSONArray.length(); i++) {
JSONObject deviceJSONObject = deviceJSONArray.getJSONObject(i);
Device device = Device.newInstance(deviceJSONObject);
if (device.isAuthorized() && !device.getDeviceAddress().equalsIgnoreCase(currentDeviceAddress)) {
ostDeviceList.add(device);
}
}

if (ostDeviceList.isEmpty()) {
ostDeviceList.add(Device.newInstance(new JSONObject()));
}

// Make request if did not get enough devices
if (hasMoreData && ostDeviceList.size() < MINIMUM_DEVICES) {
getDeviceList();
return;
}
} catch (JSONException e) {
//Exception not expected
}
if (ostDeviceList.isEmpty()) {
ostDeviceList.add(Device.newInstance(new JSONObject()));
}
} catch (JSONException e) {
//Exception not expected
}
getMvpView().notifyDataSetChanged();

httpRequestPending = false;
showLoaderProgress(false);
showProgress(false);
getMvpView().notifyDataSetChanged();
}

@Override
Expand All @@ -122,7 +139,6 @@ public void onOstJsonApiError(@NonNull OstError err, @Nullable JSONObject respon
}
});
}

private void showProgress(boolean show) {
if (mRunningLoader) return;
if (null != getMvpView()) getMvpView().setRefreshing(show);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.ost.walletsdk.ui.sdkInteract.SdkInteract;
import com.ost.walletsdk.ui.sdkInteract.WorkFlowListener;
import com.ost.walletsdk.workflows.OstWorkflowContext;
import com.ost.walletsdk.workflows.errors.OstError;
import com.ost.walletsdk.workflows.errors.OstErrors;

class RecoveryPresenter extends BasePresenter<RecoveryView> {

Expand Down Expand Up @@ -46,7 +48,9 @@ public void setPassphrase(String passphrase) {
@Override
public void cancelFlow() {
Log.d("getPinSalt", "Exception in fetching Pin Salt.");
recoverySaltFetchFailed();
getMvpView().showProgress(false);
OstError error = new OstError("ws_wsp_cf", OstErrors.ErrorCode.WORKFLOW_CANCELLED);
workFlowListener.flowInterrupt(getWorkFlowContext(), error);
}
});
}
Expand All @@ -59,12 +63,6 @@ void startWorkFlow(String ostUserId, UserPassphrase currentUserPassPhrase, Strin

}

private void recoverySaltFetchFailed(){
getMvpView().showProgress(false);
getMvpView().gotoDashboard(null);
getMvpView().showToastMessage("Recovery could not be initiated. Please try after sometime.", false);
}

public void setArguments(String userId, String workflowId, String deviceAddress) {
this.mUserId = userId;
this.mWorkflowId = workflowId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.ost.walletsdk.ui.uicomponents.uiutils.content.ContentConfig;
import com.ost.walletsdk.ui.uicomponents.uiutils.content.StringConfig;
import com.ost.walletsdk.workflows.OstWorkflowContext;
import com.ost.walletsdk.workflows.errors.OstError;
import com.ost.walletsdk.workflows.errors.OstErrors;

import org.json.JSONObject;

Expand Down Expand Up @@ -81,8 +83,8 @@ public void setPassphrase(String passphrase) {
public void cancelFlow() {
Log.d("getPinSalt", "Exception in fetching Pin Salt.");
getMvpView().showProgress(false);
getMvpView().showToastMessage("Reset PIN failed. Please try after sometime.", false);
getMvpView().gotoDashboard(null);
OstError error = new OstError("rpp_ope_cf", OstErrors.ErrorCode.WORKFLOW_CANCELLED);
workFlowListener.flowInterrupt(new OstWorkflowContext(OstWorkflowContext.WORKFLOW_TYPE.RESET_PIN), error);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.ost.walletsdk.workflows.OstContextEntity;
import com.ost.walletsdk.workflows.OstWorkflowContext;
import com.ost.walletsdk.workflows.errors.OstError;
import com.ost.walletsdk.workflows.errors.OstErrors;

import org.json.JSONObject;

Expand Down Expand Up @@ -107,7 +108,8 @@ public void setPassphrase(String passphrase) {
@Override
public void cancelFlow() {
getMvpView().showProgress(false);
getMvpView().showToastMessage("User Activation failed. Please try after sometime.", false);
OstError error = new OstError("ws_swf_cf", OstErrors.ErrorCode.WORKFLOW_CANCELLED);
workFlowListener.flowInterrupt(new OstWorkflowContext(OstWorkflowContext.WORKFLOW_TYPE.ACTIVATE_USER), error);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public void onResultString(Intent data) {
} catch (JSONException e) {
Log.e(LOG_TAG, "Exception in Data;");
showProgress(false);
showToastMessage("QR Reading failed.. Try Again", false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void onResultString(Intent data) {
} catch (JSONException e) {
Log.e(LOG_TAG, "Exception in Data;");
showProgress(false);
showToastMessage("QR Reading failed.. Try Again", false);
}
}
}
Expand Down
Loading

0 comments on commit 955d93e

Please sign in to comment.