Skip to content

Commit

Permalink
Merge pull request #123 from ostdotcom/develop
Browse files Browse the repository at this point in the history
OstWalletSettings UI component added.
  • Loading branch information
sachin-chauhan-dev authored Jan 23, 2020
2 parents 7f2825e + f52eb28 commit c5d2cf7
Show file tree
Hide file tree
Showing 39 changed files with 2,571 additions and 20 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# OST Wallet SDK Changelog

## Version 2.3.12
* OstWalletSettings UI component is now available in SDK. To use `OstWalletSettings`, please update downstream sdk.<br/>
iOS:`v2.3.6`<br/>
Android:`v2.3.8`

## Version 2.3.12-beta.1
* OstWalletSettings UI component is now available in SDK. To use `OstWalletSettings`, please update downstream sdk.<br/>
iOS:`v2.3.6-beta-1`<br/>
Android:`v2.3.8-beta.1`

## Version 2.3.11
### Bug Fix:
* In Android inaccurate error is thrown when application runs out of memory during recover device workflow.<br/>
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ repositories {

dependencies {
implementation 'com.facebook.react:react-native:+'
api 'com.ost:ost-wallet-sdk-android:2.3.7'
api 'com.ost:ost-wallet-sdk-android:2.3.8'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

package com.ostwalletrnsdk.sdkIntracts;

import android.os.Handler;
import android.os.Looper;

import com.ost.walletsdk.workflows.errors.OstErrors;
import com.ost.walletsdk.workflows.interfaces.*;
import com.ostwalletrnsdk.OstWorkFlowCallbackImpl;
Expand All @@ -21,6 +24,8 @@ public class BaseSdkInteract {

public static HashMap<String, BaseSdkInteract> map = new HashMap<>();

private final Handler handler;

OstBaseInterface sdkCallback;

public String getUUID() {
Expand All @@ -39,6 +44,7 @@ public String getWorkflowCallbackId() {
this.uuid = UUID.randomUUID().toString();
this.workflowCallbackId = workflowCallbackId;
this.sdkCallback = sdkCallback;
this.handler = new Handler(Looper.getMainLooper());
map.put(this.uuid, this);
}

Expand Down Expand Up @@ -71,4 +77,8 @@ public void cleanUp() {
this.sdkCallback = null;
map.remove(this.uuid);
}

protected void postOnUIThread(Runnable runnable) {
handler.post(runnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ public static OstDeviceRegisteredWrap getInstance(String uuid ){
return (OstDeviceRegisteredWrap) map.get( uuid );
}

void deviceRegistered(JSONObject jsonMethodParams) {
((OstDeviceRegisteredInterface)getSdkCallbackForAction()).deviceRegistered( jsonMethodParams );
void deviceRegistered(final JSONObject jsonMethodParams) {
postOnUIThread(new Runnable() {
@Override
public void run() {
((OstDeviceRegisteredInterface)getSdkCallbackForAction()).deviceRegistered( jsonMethodParams );
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ public static OstPassphraseAcceptor getInstance(String uuid ){
return (OstPassphraseAcceptor) map.get( uuid );
}

void setPassphrase( String passphrase ){
((OstPassphraseAcceptor)getSdkCallbackForAction()).setPassphrase( passphrase );
void setPassphrase( final String passphrase ){
postOnUIThread(new Runnable() {
@Override
public void run() {
((OstPassphraseAcceptor)getSdkCallbackForAction()).setPassphrase( passphrase );
}
});

}

public boolean messageReceived(String methodName, String passphrase ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ public static OstPinAcceptWrap getInstance(String uuid ){
return (OstPinAcceptWrap) map.get( uuid );
}

void pinEntered( UserPassphrase passphrase ){
((OstPinAcceptInterface)getSdkCallbackForAction()).pinEntered( passphrase );
void pinEntered(final UserPassphrase passphrase ){
postOnUIThread(new Runnable() {
@Override
public void run() {
((OstPinAcceptInterface)getSdkCallbackForAction()).pinEntered( passphrase );
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ public void setThemeConfig(ReadableMap themeConfig){
OstWalletUI.setThemeConfig(getReactApplicationContext(), themeConfigObject);
}

@ReactMethod
public void getThemeConfig(Callback callback){
JSONObject jsonObject = OstWalletUI.getThemeConfig(getReactApplicationContext());
ReadableMap readableMap = null;
try {
readableMap = Utils.convertJsonToMap(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
callback.invoke(readableMap);
}

@ReactMethod
public void setContentConfig(ReadableMap contentConfig) {
JSONObject contentConfigObject = null;
Expand Down
46 changes: 46 additions & 0 deletions documentation/OstTransactionConfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# OstTransaction Config

## Introduction

App developers can configure session `expiration_time` and `spending_limit` while executing transaction.

To configure the content, the sdk needs to be provided with [JSON object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON).

The default configuration can be found [here](../js/TransactionHelper/ost-transaction-config.json).

## Dictionary Data Structure

Here is the small sample json representation of the configuration.

```js
{
"session_buckets": [
{
expiration_time: 60*60*24*30*2, //2 months
spending_limit: '10'
},
{
expiration_time: 60*60*24*30, //1 months
spending_limit: '50'
},
{
expiration_time: 60*60*24, //24 hours
spending_limit: '100'
},
{
expiration_time: 60*60*1, //1 hour
spending_limit: '1000'
}
]
}
```

In the above example:

* The first-level key `session_buckets` corresponds to list of buckets for creating session. The bucket selection is
depends on `spending_limit`.
* The second-level keys
- `expiration_time` : corresponds to expiry time of session.
- `spending_limit` : corresponds to spending limit of session.

Above configuration allows user to execute transction of spending limit `1000`. SDK throws error, if user makes transaction above `1000`.
44 changes: 44 additions & 0 deletions documentation/OstTransactionHelper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# OstTransaction Helper

## Introduction

Developer can call functions of transaction helper to execute transaction and setting up config for transaction.

## Set Transaction Config

Developer can set list of buckets for creating session. For details, Please refer [this](./OstTransactionConfig.md)

```js
import {OstTransactionHelper} from "@ostdotcom/ost-wallet-sdk-react-native/js/index"

OstTransactionHelper.setTxConfig(ost-tx-config);
```

## Execute Direct Transfer

Execute direct transfer can be performed by calling

><b>Note</b> <br />
>Developer needs to create a class extends from OstWalletUIWorkflowCallback and write logic to get passphrase prefix from their application server. Please refer [this](./OstWalletUI.md) section for documentation.
```js
import {OstTransactionHelper} from "@ostdotcom/ost-wallet-sdk-react-native/js/index"

const ostUserId = <OstUserId>
const txMeta = {"type": "user_to_user", "name": "Tokens sent", "details": "Sending tokens vis direct transafer"};
const workflowCallback = new OstWalletUIWorkflowCallback()

let uuid = OstTransactionHelper.executeDirectTransfer(ostUserId, [tokenValue], [token_holder_address], txMeta, workflowCallback);

OstWalletSdkUI.subscribe(uuid, OstWalletSdkUI.EVENTS.flowComplete, (workflowContext, contextEntity) => {
//functionality for transaction success
});
OstWalletSdkUI.subscribe(uuid, OstWalletSdkUI.EVENTS.flowInterrupt, (workflowContext, ostError) => {
//functionality for transaction failed
});
OstWalletSdkUI.subscribe(uuid, OstWalletSdkUI.EVENTS.requestAcknowledged, (workflowContext, contextEntity) => {
//functionality for transaction ack.
});
```

New session will be created with appropriate bucket, if sdk won't get any active session for given spending limit.
70 changes: 70 additions & 0 deletions documentation/OstWalletSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# OstWallet Settings

## Introduction

OstWallet Settings is a pre-built UI Component available exclusively available in `ost-wallet-sdk-react-native` Sdk.
It is a wallet settings page that can be used by end-users to perfrom different wallet operations.
> <b>IMPORTANT:</b> This feature requires application to use [React Navigation](https://reactnavigation.org/docs/en/getting-started.html) package.
OstWalletSettings supports 13 workflows:

* Activate User
* Wallet Details
* Initialize Recovery
* Add Session
* Reset a User's PIN
* Get Mnemonic Phrase
* Authorize device using mnemonics
* Abort Device Recovery
* Revoke Device
* Scan QR Code to add another device
* Get Current Device QR code
* Enable Biometrics
* Disable Biometrics

## Usage

### Create wallet settings stack navigation

```js
import {OstWalletSettingsComponent} from '@ostdotcom/ost-wallet-sdk-react-native';

let settingsStack = createStackNavigator(
{
"WalletSettingScreen": OstWalletSettingsComponent
}
);
```

### Naviagte to settings page
`ostUserId` and `ostWalletUIWorkflowCallback` are mandetory parameters that need to be passed as params to the `WalletSettingScreen` screen.
```js
const ostUserId = <APPLICATION-USER-OST-USER-ID>
const delegate = new OstWalletUIWorkflowCallback(ostUserId, {})
this.props.navigation.push("WalletSettingScreen", {'ostUserId': ostUserId, 'ostWalletUIWorkflowCallback': delegate});
```

><b>Note</b> <br/>
> Developer needs to create a class extends from `OstWalletUIWorkflowCallback` and write logic to get passphrase prefix from their application server.
> Please refer [this](OstWalletUI.md#setup-your-passphrase-prefix-delegate) section for documentation.
## UI Customization

Developer can customize wallet settings by updating respective properties mentioned in image. OstTheme config shown [here](./configs/ost-sdk-theme-config.js)

![copy-framework-file](images/wallet_settings.png)
![copy-framework-file](images/wallet_details.png)

## Settings Content

Developer can modify `header` and `description` of settings options. To modify contet, [refer here](./OstWalletSettingsConfig.md).

```js
import {OstWalletSettings} from "@ostdotcom/ost-wallet-sdk-react-native/js/index";

let settingsContentConfig = {}

OstWalletSettings.setMasterConfig(settingsContentConfig)
```


77 changes: 77 additions & 0 deletions documentation/OstWalletSettingsConfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# OstWallet Settings Config

## Introduction

App developers can configure the text shown on settings page.

To configure the content, the sdk needs to be provided with [JSON object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON).

The default configuration can be found [here](../js/WalletSettings/ost-wallet-settings-config.json).

## Dictionary Data Structure

Here is the small sample json representation of the configuration.

```json
{
"item_display_order": [
"activate_user",
],
"item_configs": {
"activate_user": {
"content_config": {
"heading": "Activate User",
"description": "User is not activated yet."
},
"config": {
"spending_limit": "0",
"expiration_time": 0
}
}
}
}
```
In the above example:

* The first-level key `item_display_order` corresponds to sequence of allowed workflows.
* The first-level key `item_configs` corresponds to config for workflows.
* The second-level key `activate_user` corresponds to activate user workflow.
* The third-level key `content_config` corresponds to `heading` and `description` of workflows.
* The third-level key `config` corresponds to respective config for workflows.

## Supported Workflows

OstWalletSettings supports 13 workflows

| Configuration Keys | Workflows |
| ------------------------------------------------ |:--------------------------------------------------------------|
| activate_user | Activate User |
| wallet_details | Wallet Details |
| recover_device | Initialize Recovery |
| add_session | Add Session |
| reset_pin | Reset a User's PIN |
| show_mnemonics | Get Mnemonic Phrase |
| authorize_device_with_mnemonics | Authorize device using mnemonics |
| abort_recovery | Abort Device Recovery |
| revoke_device | Revoke Device |
| add_another_device | Scan QR Code to add another device |
| show_device_qr_code | Get current Device QR code |
| enable_biometrics | Use biometrics to authorize new Sessions and to confirm high value transactions. |
| disable_biometrics | Turn off biometrics and use PIN to authorize new Sessions and to confirm high value transactions. |

* All workflows have `content_config`.
* `config` varies workflow to workflow.

## Workflow Config

Some workflows requires additional data. It can be passed to workflow by setting it in `config`.

| Workflows | Config Keys | Config Type |
| -------------------------------------- | -------------------------------------------------- | ------------------------------- |
| activate_user | - spending_limit | String |
| | - expiration_time | Number |
| wallet_details | - ost_view_endpoint | String |
| add_session | - spending_limit | String |
| | - expiration_time | Number |


Loading

0 comments on commit c5d2cf7

Please sign in to comment.