Skip to content

Commit 2f2112c

Browse files
authored
Merge pull request #1040 from singnet/users-development
Users development
2 parents 6ce4515 + 6bb2179 commit 2f2112c

File tree

58 files changed

+676
-1111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+676
-1111
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typings/
5858

5959
# dotenv environment variables file
6060
.env
61-
.env*.local
61+
.env*
6262

6363
# next.js build output
6464
.next

config-overrides.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const options = {
2222

2323
module.exports = function override(config) {
2424
const modifiedConfig = aliasWebpack(options)(config);
25-
const fallback = config.resolve.fallback || {};
25+
let fallback = config.resolve.fallback || {};
26+
fallback = { ...fallback, fs: false };
2627
Object.assign(fallback, {
2728
os: require.resolve("os-browserify"),
2829
url: require.resolve("url"),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"redux-thunk": "^3.1.0",
4949
"singularitynet-platform-contracts": "2.1.0",
5050
"slick-carousel": "^1.8.1",
51-
"snet-sdk-web": "4.2.2",
51+
"snet-sdk-web": "5.0.4",
5252
"utf8": "^3.0.0",
5353
"validate.js": "^0.13.1",
5454
"web3": "^4.11.1"

src/Redux/actionCreators/DatasetActions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ export const clearRecentDatasets = () => (dispatch) => {
5555
});
5656
};
5757

58-
export const getDatasetStatistic = (datasetKey) => async (dispatch) => {
58+
export const getDatasetStatistic = (datasetKey) => {
5959
const params = new URLSearchParams([["dataset_key", datasetKey]]);
6060
return DatasetClient.get(DatasetEndpoints.VALIDATE_AND_ANALIZE, { params });
6161
};
6262

63-
export const improveDataset = (datasetKey, improveOptionsList) => async (dispatch) => {
63+
export const improveDataset = (datasetKey, improveOptionsList) => {
6464
const params = {
6565
dataset_key: datasetKey,
6666
improve_options: improveOptionsList.reduce((acc, field) => {
@@ -71,7 +71,7 @@ export const improveDataset = (datasetKey, improveOptionsList) => async (dispatc
7171
return DatasetClient.post(DatasetEndpoints.IMPROVE, params);
7272
};
7373

74-
export const mergeDatasets = (mainDataset, mergeDataset) => async (dispatch) => {
74+
export const mergeDatasets = (mainDataset, mergeDataset) => {
7575
const params = {
7676
dataset_key_base: mainDataset,
7777
dataset_key_additional: mergeDataset,
@@ -85,7 +85,7 @@ export const mergeDatasets = (mainDataset, mergeDataset) => async (dispatch) =>
8585
});
8686
};
8787

88-
export const validateMergeDatasets = (mainDataset, mergeDataset) => async (dispatch) => {
88+
export const validateMergeDatasets = (mainDataset, mergeDataset) => {
8989
const params = {
9090
dataset_key_base: mainDataset,
9191
dataset_key_additional: mergeDataset,

src/Redux/actionCreators/SDKActions.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isEmpty } from "lodash";
2-
import { getWeb3Address, initSdk } from "../../utility/sdk";
2+
import { initSdk } from "../../utility/sdk";
3+
import PaymentChannelManagement from "../../utility/PaymentChannelManagement";
34

45
export const SET_SDK = "SET_SDK";
56
export const SET_SERVICE_CLIENT = "SET_SERVICE_CLIENT";
@@ -18,19 +19,20 @@ export const initializingSdk = () => async (dispatch) => {
1819
dispatch(updateSdkInstance(sdk));
1920
return sdk;
2021
} catch (error) {
22+
console.error("init sdk", error);
23+
2124
throw new Error(error);
2225
}
2326
};
2427

2528
const initializeServiceClient = (organizationId, serviceId) => async (dispatch) => {
2629
const sdk = await dispatch(getSdk());
27-
const serviceClient = await sdk.createServiceClient(organizationId, serviceId);
30+
const serviceClient = await sdk.createServiceClient({ orgId: organizationId, serviceId });
2831
// dispatch(updateServiceClient(serviceClient))
2932
return serviceClient;
3033
};
3134

3235
export const getSdk = () => async (dispatch, getState) => {
33-
await getWeb3Address();
3436
let sdk = getState().sdkReducer.sdk;
3537
if (!isEmpty(sdk)) {
3638
return sdk;
@@ -47,3 +49,13 @@ export const getServiceClient = (organizationId, serviceId) => async (dispatch,
4749
serviceClient = await dispatch(initializeServiceClient(organizationId, serviceId));
4850
return serviceClient;
4951
};
52+
53+
export const createPaymentChannelManagement = (orgId, serviceId) => async (dispatch) => {
54+
try {
55+
const sdk = await dispatch(initializingSdk());
56+
const metadataProvider = await sdk.createServiceMetadataProvider(orgId, serviceId);
57+
return new PaymentChannelManagement(sdk, metadataProvider);
58+
} catch (err) {
59+
console.error(err);
60+
}
61+
};

src/Redux/actionCreators/ServiceActions.js

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { APIEndpoints, APIPaths } from "../../config/APIEndpoints";
22
import { loaderActions, userActions } from "./";
3-
import { LoaderContent } from "../../utility/constants/LoaderContent";
43
import { getAPI, postAPI, initializeAPIOptions } from "../../utility/API";
54
import { generateOrganizationsFilterObject } from "../../utility/constants/Pagination";
65
// import { cacheS3Url } from "../../utility/image";
@@ -24,16 +23,7 @@ export const resetFilterItem = (dispatch) => {
2423
};
2524

2625
export const fetchServiceSuccess = (res) => (dispatch) => {
27-
dispatch({
28-
type: UPDATE_PAGINATION_DETAILS,
29-
payload: {
30-
total_count: res.data.total_count,
31-
},
32-
});
33-
// const enhancedResult = res.data.result.map(service => ({
34-
// ...service,
35-
// media: { ...service.media, url: service.media.url ? cacheS3Url(service.media.url) : null },
36-
// }));
26+
dispatch(updatePagination({ total_count: res.data.total_count }));
3727
dispatch({ type: UPDATE_SERVICE_LIST, payload: res.data.result });
3828
dispatch(loaderActions.stopAIServiceListLoader());
3929
};
@@ -59,8 +49,8 @@ const onlyUserOrgsFilter = () => async (dispatch) => {
5949
export const fetchService =
6050
(pagination, filters = []) =>
6151
async (dispatch) => {
52+
// env variable is string
6253
if (process.env.REACT_APP_IS_ALL_SERVICES_AVAILIBLE !== "true") {
63-
// env variable is string
6454
filters = await dispatch(onlyUserOrgsFilter());
6555
}
6656
dispatch(loaderActions.startAIServiceListLoader());
@@ -112,53 +102,17 @@ export const resetFilter =
112102
.catch(() => dispatch(loaderActions.stopAIServiceListLoader()));
113103
};
114104

115-
const fetchFeedbackAPI = (email, orgId, serviceId, token) => {
105+
const fetchFeedbackAPI = (orgId, serviceId, token) => {
116106
const apiName = APIEndpoints.USER.name;
117107
const path = `${APIPaths.FEEDBACK}?org_id=${orgId}&service_id=${serviceId}`;
118108
const apiOptions = initializeAPIOptions(token);
119109
return getAPI(apiName, path, apiOptions);
120110
};
121111

122-
const fetchAuthTokenAPI = async (serviceId, groupId, publicKey, orgId, token) => {
123-
const apiName = APIEndpoints.SIGNER_SERVICE.name;
124-
const apiPath = APIPaths.FREE_CALL_TOKEN;
125-
const queryParams = {
126-
service_id: serviceId,
127-
group_id: groupId,
128-
public_key: publicKey,
129-
org_id: orgId,
130-
};
131-
const apiOptions = initializeAPIOptions(token, null, queryParams);
132-
const authTokenRequest = await getAPI(apiName, apiPath, apiOptions);
133-
return authTokenRequest;
134-
};
135-
136-
export const downloadAuthToken = (serviceId, groupId, publicKey, orgId) => async (dispatch) => {
137-
try {
138-
dispatch(loaderActions.startAppLoader(LoaderContent.GENERATE_AUTH_TOKEN));
139-
const { token, email } = await dispatch(userActions.fetchAuthenticatedUser());
140-
141-
const { data } = await fetchAuthTokenAPI(serviceId, groupId, publicKey, orgId, token);
142-
143-
const jsonToDownload = {
144-
email,
145-
tokenToMakeFreeCall: data.token_to_make_free_call,
146-
tokenExpirationBlock: data.token_expiration_block,
147-
};
148-
const downloadBlob = new Blob([JSON.stringify(jsonToDownload)], { type: "text/json;charset=utf-8" });
149-
const downloadURL = window.URL.createObjectURL(downloadBlob);
150-
dispatch(loaderActions.stopAppLoader());
151-
return downloadURL;
152-
} catch (e) {
153-
dispatch(loaderActions.stopAppLoader());
154-
throw e;
155-
}
156-
};
157-
158112
//Username review
159113
export const fetchFeedback = (orgId, serviceId) => async (dispatch) => {
160-
const { email, token } = await dispatch(userActions.fetchAuthenticatedUser());
161-
return fetchFeedbackAPI(email, orgId, serviceId, token);
114+
const { token } = await dispatch(userActions.fetchAuthenticatedUser());
115+
return fetchFeedbackAPI(orgId, serviceId, token);
162116
};
163117

164118
const submitFeedbackAPI = (feedbackObj, token) => {

src/Redux/actionCreators/ServiceDetailsActions.js

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
import { APIEndpoints, APIPaths } from "../../config/APIEndpoints";
2-
import { getAPI, initializeAPIOptions } from "../../utility/API";
2+
import { initializeAPIOptions, postAPI } from "../../utility/API";
33
import { fetchAuthenticatedUser } from "./UserActions";
44
import { loaderActions } from "./";
55
import { LoaderContent } from "../../utility/constants/LoaderContent";
66
import { isEmpty } from "lodash";
77
import { resetCurrentModelDetails, resetModelList } from "./ServiceTrainingActions";
8+
import { createFreecallStrategy } from "../../utility/sdk";
9+
import { initializingSdk } from "./SDKActions";
810

911
export const UPDATE_SERVICE_DETAILS = "UPDATE_SERVICE_DETAILS";
1012
export const RESET_SERVICE_DETAILS = "RESET_SERVICE_DETAILS";
1113
export const UPDATE_FREE_CALLS_INFO = "UPDATE_FREE_CALLS_INFO";
1214
export const UPDATE_TRAINING_DETAILS = "UPDATE_TRAINING_DETAILS";
15+
export const UPDATE_FREECALL_SIGNATURE = "UPDATE_FREECALL_SIGNATURE";
1316

1417
const resetServiceDetails = (dispatch) => {
1518
dispatch({ type: RESET_SERVICE_DETAILS });
1619
};
1720

21+
const setFreeCallSignature = (freeCallSignature) => (dispatch) => {
22+
dispatch({ type: UPDATE_FREECALL_SIGNATURE, payload: freeCallSignature });
23+
};
24+
1825
const fetchServiceDetailsFailure = (err) => (dispatch) => {
1926
dispatch(loaderActions.stopAppLoader());
2027
};
2128

2229
const fetchServiceDetailsSuccess = (serviceDetails) => (dispatch) => {
23-
// const enhancedServiceDetails = {
24-
// ...serviceDetails,
25-
// data: { ...serviceDetails.data, media: serviceDetails.data.media.map(el => ({ ...el, url: cacheS3Url(el.url) })) },
26-
// };
2730
dispatch(loaderActions.stopAppLoader());
28-
dispatch({ type: UPDATE_SERVICE_DETAILS, payload: serviceDetails.data });
31+
dispatch({ type: UPDATE_SERVICE_DETAILS, payload: serviceDetails });
2932
};
3033

3134
const fetchServiceDetailsAPI = async (orgId, serviceId) => {
32-
const url = `${APIEndpoints.CONTRACT.endpoint}/org/${orgId}/service/${serviceId}`;
35+
const url = APIEndpoints.CONTRACT.endpoint + APIPaths.SERVICE_DETAILS(orgId, serviceId);
3336
const response = await fetch(url);
3437
return response.json();
3538
};
@@ -40,18 +43,21 @@ export const fetchServiceDetails = (orgId, serviceId) => async (dispatch) => {
4043
dispatch(resetServiceDetails);
4144
dispatch(resetCurrentModelDetails());
4245
dispatch(resetModelList());
43-
const serviceDetails = await fetchServiceDetailsAPI(orgId, serviceId);
46+
const { data: serviceDetails } = await fetchServiceDetailsAPI(orgId, serviceId);
4447
dispatch(fetchServiceDetailsSuccess(serviceDetails));
4548
} catch (error) {
4649
dispatch(fetchServiceDetailsFailure(error));
4750
throw error;
4851
}
4952
};
5053

51-
const fetchMeteringDataSuccess = (usageData) => (dispatch) => {
54+
const fetchMeteringDataSuccess = (freeCallsAvailable, freeCallsTotal) => (dispatch) => {
5255
dispatch({
5356
type: UPDATE_FREE_CALLS_INFO,
54-
payload: usageData.total_calls_made,
57+
payload: {
58+
freeCallsTotal,
59+
freeCallsAvailable,
60+
},
5561
});
5662
};
5763

@@ -75,21 +81,73 @@ export const fetchTrainingModel = (orgId, serviceId) => async (dispatch) => {
7581
dispatch(fetchTrainingModelSuccess(serviceTrainingData));
7682
};
7783

78-
const meteringAPI = (token, orgId, serviceId, groupId, userId) => {
79-
const apiName = APIEndpoints.USER.name;
80-
const apiPath = APIPaths.FREE_CALL_USAGE;
81-
const queryParams = { organization_id: orgId, service_id: serviceId, group_id: groupId, username: userId };
82-
const apiOptions = initializeAPIOptions(token, null, queryParams);
83-
return getAPI(apiName, apiPath, apiOptions);
84+
const getAvailableFreeCalls = (orgId, serviceId, groupId) => async (dispatch) => {
85+
const {
86+
signature,
87+
currentBlockNumber,
88+
userId,
89+
freeCallToken,
90+
signerAddress: address,
91+
} = await dispatch(getFreeCallSign(orgId, serviceId, groupId));
92+
93+
try {
94+
const freecallStrategy = await createFreecallStrategy(orgId, serviceId);
95+
const availableFreeCalls = await freecallStrategy.getFreeCallsAvailable({
96+
signature,
97+
currentBlockNumber,
98+
userId,
99+
token: freeCallToken,
100+
address,
101+
});
102+
return availableFreeCalls;
103+
} catch (err) {
104+
console.error("error on getting available free calls:", err);
105+
106+
throw new Error(err);
107+
}
108+
};
109+
110+
export const getFreeCallSign = (orgId, serviceId, groupId) => async (dispatch, getState) => {
111+
try {
112+
const sdk = await dispatch(initializingSdk());
113+
const currentBlock = await sdk.account.getCurrentBlockNumber();
114+
const { email, token } = await dispatch(fetchAuthenticatedUser());
115+
const freeCallSignatureDetails = getState().serviceDetailsReducer.freeCallSignature;
116+
117+
if (freeCallSignatureDetails.expirationBlock && freeCallSignatureDetails.expirationBlock < currentBlock) {
118+
return { ...freeCallSignatureDetails, userId: email };
119+
}
120+
const payload = {
121+
organization_id: orgId,
122+
service_id: serviceId,
123+
group_id: groupId,
124+
};
125+
const apiName = APIEndpoints.SIGNER_SERVICE.name;
126+
const apiOptions = initializeAPIOptions(token, payload);
127+
const { data: freeCallSignerResp } = await postAPI(apiName, APIPaths.SIGNER_FREE_CALL, apiOptions);
128+
129+
const freeCallSignature = {
130+
signature: freeCallSignerResp.signature_hex,
131+
expirationBlock: freeCallSignerResp.expiration_block_number,
132+
currentBlockNumber: freeCallSignerResp.current_block_number,
133+
freeCallToken: freeCallSignerResp.free_call_token_hex,
134+
signerAddress: freeCallSignerResp.signer_address,
135+
userId: email,
136+
};
137+
dispatch(setFreeCallSignature(freeCallSignature));
138+
return freeCallSignature;
139+
} catch (err) {
140+
console.error(err);
141+
throw err;
142+
}
84143
};
85144

86145
export const fetchMeteringData =
87-
({ orgId, serviceId, groupId }) =>
146+
({ orgId, serviceId, groupId, freeCallsTotal }) =>
88147
async (dispatch) => {
89-
const { email, token } = await dispatch(fetchAuthenticatedUser());
90-
const usageData = await meteringAPI(token, orgId, serviceId, groupId, email);
91-
dispatch(fetchMeteringDataSuccess(usageData));
92-
return usageData;
148+
const freeCallsAvailable = await dispatch(getAvailableFreeCalls(orgId, serviceId, groupId));
149+
dispatch(fetchMeteringDataSuccess(freeCallsAvailable, freeCallsTotal));
150+
return { freeCallsAvailable, freeCallsTotal };
93151
};
94152

95153
export const getIsTrainingAvailable = (detailsTraining, isLoggedIn) => {

src/Redux/actionCreators/ServiceTrainingActions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export const publishFilesToS3 = async (fileBlob, name, S3Instance, folder, email
229229
}
230230
};
231231

232-
export const getDatasetSizeFromS3 = async (fileKey, S3instance) => {
232+
export const getDatasetSizeFromS3 = (fileKey, S3instance) => {
233233
return S3instance.get(filesToS3Endpoints.DOWNLOAD, { params: { key: fileKey, action: "getsize" } })
234234
.then((response) => {
235235
return response.data.fileSize;

src/Redux/actionCreators/UiContentActions.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)