Skip to content

Commit

Permalink
Merge pull request #927 from singnet/update-payment-system
Browse files Browse the repository at this point in the history
Update payment system
  • Loading branch information
MarinaFedy authored Jul 5, 2024
2 parents 1ddb095 + 9f359b9 commit 7c83fb8
Show file tree
Hide file tree
Showing 89 changed files with 961 additions and 958 deletions.
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
crossorigin="anonymous"
/>
<link href="https://fonts.googleapis.com/css?family=Muli:200,200i,300,300i,400,400i,600,600i,700,800&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Muli:200,200i,300,300i,400,400i,600,600i,700,800&display=swap" rel="preload" as="font">
<!-- <link href="https://fonts.googleapis.com/css?family=Muli:200,200i,300,300i,400,400i,600,600i,700,800&display=swap" rel="preload" as="font"> -->
<link href="https://fonts.googleapis.com/css?family=Space+Mono:400,700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Space+Mono:400,700&display=swap" rel="preload" as="font">
<!-- <link href="https://fonts.googleapis.com/css?family=Space+Mono:400,700&display=swap" rel="preload" as="font"> -->
<!-- Prefetch external resource -->
<link rel="dns-prefetch" href="//static.hotjar.com">
<link rel="dns-prefetch" href="//www.google-analytics.com">
Expand Down
2 changes: 1 addition & 1 deletion src/Redux/actionCreators/LoaderActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const startAppLoader = (loaderContent) => (dispatch) => {
return dispatch({ type: START_APP_LOADER, payload: { app: { loading: true, ...loaderContent } } });
};

export const stopAppLoader = (dispatch) => {
export const stopAppLoader = () => (dispatch) => {
return dispatch({ type: STOP_APP_LOADER, payload: { app: { loading: false, loaderHeader: "", loaderText: "" } } });
};

Expand Down
2 changes: 1 addition & 1 deletion src/Redux/actionCreators/PaymentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const initiatePayment = (paymentObj) => async (dispatch) => {
}
window.location.replace(data.payment.payment_url);
} catch (error) {
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
throw error;
}
};
Expand Down
27 changes: 27 additions & 0 deletions src/Redux/actionCreators/SDKActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { isEmpty } from "lodash";
import { initSdk } from "../../utility/sdk";

export const SET_SDK = "SET_SDK";

export const updateSdkInstance = (sdkInstance) => (dispatch) => {
dispatch({ type: SET_SDK, payload: { ...sdkInstance } });
};

export const initializingSdk = (ethereumWalletAddress) => async (dispatch) => {
try {
const sdk = await initSdk(ethereumWalletAddress);
dispatch(updateSdkInstance(sdk));
return sdk;
} catch (error) {
throw new Error(error);
}
};

export const getSdk = () => async (dispatch, getState) => {
let sdk = getState().sdkReducer.sdk;
if (!isEmpty(sdk)) {
return sdk;
}
sdk = await dispatch(initializingSdk());
return sdk;
};
4 changes: 2 additions & 2 deletions src/Redux/actionCreators/ServiceActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ export const downloadAuthToken = (serviceId, groupId, publicKey, orgId) => async
};
const downloadBlob = new Blob([JSON.stringify(jsonToDownload)], { type: "text/json;charset=utf-8" });
const downloadURL = window.URL.createObjectURL(downloadBlob);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
return downloadURL;
} catch (e) {
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
throw e;
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/Redux/actionCreators/ServiceDetailsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ const resetServiceDetails = (dispatch) => {
};

const fetchServiceDetailsFailure = (err) => (dispatch) => {
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

const fetchServiceDetailsSuccess = (serviceDetails) => (dispatch) => {
// const enhancedServiceDetails = {
// ...serviceDetails,
// data: { ...serviceDetails.data, media: serviceDetails.data.media.map(el => ({ ...el, url: cacheS3Url(el.url) })) },
// };
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
dispatch({ type: UPDATE_SERVICE_DETAILS, payload: serviceDetails.data });
};

Expand Down
90 changes: 57 additions & 33 deletions src/Redux/actionCreators/UserActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import moment from "moment";

import { APIEndpoints, APIPaths } from "../../config/APIEndpoints";
import { parseError } from "../../utility/ErrorHandling";
import { userActions, errorActions, loaderActions } from "./";
import { sdkActions, errorActions, loaderActions } from "./";
import { LoaderContent } from "../../utility/constants/LoaderContent";
import { initializeAPIOptions } from "../../utility/API";
import Routes from "../../utility/constants/Routes";
Expand All @@ -30,7 +30,7 @@ export const UPDATE_TRANSACTION_HISTORY = "UPDATE_TRANSACTION_HISTORY";
export const UPDATE_FIRST_TIME_FETCH_WALLET = "FIRST_TIME_FETCH_WALLET";
export const SET_JWT_EXP = "SET_JWT_EXP";

let walletPollingInterval = false;
// let walletPollingInterval = false;

export const walletTypes = {
GENERAL: "GENERAL",
Expand Down Expand Up @@ -61,7 +61,7 @@ export const fetchAuthenticatedUser = () => async (dispatch, getState) => {

export const appInitializationSuccess = (dispatch) => {
dispatch({ type: APP_INITIALIZATION_SUCCESS, payload: { isInitialized: true } });
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

export const updateNickname = (nickname) => (dispatch) => {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const fetchUserTransactions = async (dispatch) => {
dispatch(loaderActions.startAppLoader(LoaderContent.TRANSACTION_HISTORY));
const response = await fetchUserTransactionsAPI(token);
dispatch(fetchUserTransactionsSuccess(response));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

const fetchUserTransactionsSuccess = (response) => (dispatch) => {
Expand Down Expand Up @@ -157,13 +157,13 @@ const fetchUserDetailsSuccess = (isEmailVerified, email, nickname) => (dispatch)
nickname,
},
});
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

const fetchUserDetailsError = (err) => (dispatch) => {
if (err === "No current user") {
dispatch(noAuthenticatedUser);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
}
dispatch(appInitializationSuccess);
};
Expand Down Expand Up @@ -194,12 +194,12 @@ export const updateUserProfileInit = (token, updatedUserData) => {

const updateUserProfileSuccess = (token) => (dispatch) => {
dispatch(fetchUserProfile(token));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

const updateUserProfileFailure = (err) => (dispatch) => {
dispatch(errorActions.updateProfileSettingsError(String(err)));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

export const updateUserProfile = (updatedUserData) => async (dispatch) => {
Expand Down Expand Up @@ -228,7 +228,7 @@ export const loginSuccess =
({ res, history, route }) =>
async (dispatch) => {
const userDetails = {
type: userActions.LOGIN_SUCCESS,
type: LOGIN_SUCCESS,
payload: {
login: { isLoggedIn: true },
email: res.attributes.email,
Expand All @@ -239,7 +239,7 @@ export const loginSuccess =
dispatch(userDetails);
history.push(route);
await dispatch(fetchUserProfile(res.signInUserSession.idToken.jwtToken));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

export const login =
Expand All @@ -255,26 +255,26 @@ export const login =
if (err.code === "PasswordResetRequiredException") {
dispatch(updateEmail(email));
history.push(`/${Routes.RESET_PASSWORD}`);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
return;
} else if (err.code === "UserNotConfirmedException") {
dispatch(updateEmail(email));
userDetails = {
type: userActions.LOGIN_SUCCESS,
type: LOGIN_SUCCESS,
payload: { login: { isLoggedIn: true } },
};
dispatch(userDetails);
history.push(`/${Routes.ONBOARDING}`);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
return;
}
const error = parseError(err);
userDetails = {
type: userActions.LOGIN_ERROR,
type: LOGIN_ERROR,
payload: { login: { error } },
};
dispatch(userDetails);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
throw err;
});
};
Expand Down Expand Up @@ -315,7 +315,7 @@ export const signOut = (dispatch) => {
})
.finally(() => {
dispatch(userDetails);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
});
};

Expand Down Expand Up @@ -352,13 +352,13 @@ const deleteUserFromCognito =
user.deleteUser((error) => {
if (error) {
reject(error);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
}
resolve();
});
}).then(() => {
dispatch(userDeleted({ history, route }));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
});
};

Expand All @@ -381,12 +381,12 @@ const forgotPasswordSuccessfull =
(dispatch) => {
dispatch(updateEmail(email));
history.push(route);
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

const forgotPasswordFailure = (error) => (dispatch) => {
dispatch(errorActions.updateForgotPasswordError(error));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

export const forgotPassword =
Expand All @@ -411,13 +411,13 @@ const forgotPasswordSubmitSuccessfull =
({ email, history, route }) =>
(dispatch) => {
dispatch(updateEmail(email));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
history.push(route);
};

const forgotPasswordSubmitFailure = (error) => (dispatch) => {
dispatch(errorActions.updateForgotPasswordSubmitError(error));
dispatch(loaderActions.stopAppLoader);
dispatch(loaderActions.stopAppLoader());
};

export const forgotPasswordSubmit =
Expand Down Expand Up @@ -451,6 +451,24 @@ const fetchWalletSuccess = (response) => (dispatch) => {
}
};

export const updateChannelBalanceAPI =
(orgId, serviceId, groupId, authorizedAmount, fullAmount, channelId, nonce) => async (dispatch) => {
const { token } = await dispatch(fetchAuthenticatedUser());
const apiName = APIEndpoints.CONTRACT.name;
const apiPath = APIPaths.UPDATE_CHANNEL_BALANCE(channelId);
const payload = {
OrganizationID: orgId,
ServiceID: serviceId,
GroupID: groupId,
AuthorizedAmount: authorizedAmount,
FullAmount: fullAmount,
ChannelId: channelId,
Nonce: nonce,
};
const apiOptions = initializeAPIOptions(token, payload);
return API.post(apiName, apiPath, apiOptions);
};

const fetchWalletAPI = (token, orgId, groupId) => {
const apiName = APIEndpoints.ORCHESTRATOR.name;
const apiPath = APIPaths.WALLET;
Expand Down Expand Up @@ -488,17 +506,7 @@ export const fetchWalletLinkedProviders = async (address) => {
};

export const startWalletDetailsPolling = (orgId, groupId) => (dispatch) => {
if (!walletPollingInterval) {
walletPollingInterval = setInterval(() => dispatch(fetchWallet(orgId, groupId)), 15000);
return dispatch(fetchWallet(orgId, groupId));
}
};

export const stopWalletDetailsPolling = () => {
if (walletPollingInterval) {
clearInterval(walletPollingInterval);
walletPollingInterval = false;
}
return dispatch(fetchWallet(orgId, groupId));
};

const updateDefaultWalletAPI = (token, address) => {
Expand Down Expand Up @@ -536,3 +544,19 @@ export const registerWallet = (address, type) => async (dispatch) => {
console.log("error registerWallet");
}
};

export const updateMetamaskWallet = () => async (dispatch, getState) => {
const sdk = await dispatch(sdkActions.getSdk());
const address = await sdk.account.getAddress();
if (getState().userReducer.wallet.value === address) {
return;
}
const availableUserWallets = await dispatch(fetchAvailableUserWallets());
const addressAlreadyRegistered = availableUserWallets.some(
(wallet) => wallet.address.toLowerCase() === address.toLowerCase()
);
if (!addressAlreadyRegistered) {
await dispatch(registerWallet(address, walletTypes.METAMASK));
}
dispatch(updateWallet({ type: walletTypes.METAMASK, address }));
};
2 changes: 2 additions & 0 deletions src/Redux/actionCreators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import * as loaderActions from "./LoaderActions";
import * as stylesActions from "./StylesActions";
import * as paymentActions from "./PaymentActions";
import * as uiContentActions from "./UiContentActions";
import * as sdkActions from "./SDKActions";

export {
sdkActions,
userActions,
serviceActions,
serviceDetailsActions,
Expand Down
18 changes: 18 additions & 0 deletions src/Redux/reducers/SDKReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { sdkActions } from "../actionCreators";

const InitialState = {
sdk: {},
};

const sdkReducer = (state = InitialState, action) => {
switch (action.type) {
case sdkActions.SET_SDK: {
return { ...state, ...action.payload };
}
default: {
return state;
}
}
};

export default sdkReducer;
5 changes: 2 additions & 3 deletions src/Redux/reducers/UserReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { userActions } from "../actionCreators";
import { walletTypes, RESET_LOGIN_ERROR } from "../actionCreators/UserActions";
import { cogsToAgi } from "../../utility/PricingStrategy";

export const initialWallet = { value: walletTypes.DEFAULT, type: walletTypes.DEFAULT };
export const initialWallet = { value: walletTypes.DEFAULT, type: walletTypes.METAMASK };
const InitialUserDetails = {
login: {
isLoggedIn: false,
Expand Down Expand Up @@ -127,11 +127,10 @@ const userReducer = (state = InitialUserDetails, action) => {
};

export const channelInfo = (state) => {
const { walletList } = state.userReducer;
const { walletList } = userReducer;
if (isEmpty(walletList)) {
return {};
}

const walletWithChannel = walletList.find(
(wallet) => wallet.type === walletTypes.GENERAL && !isEmpty(wallet.channels[0])
);
Expand Down
2 changes: 2 additions & 0 deletions src/Redux/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import loaderReducer from "./LoaderReducer";
import stylesReducer from "./StylesReducer";
import paymentReducer from "./PaymentReducer";
import uiContentReducer from "./UiContentReducer";
import sdkReducer from "./SDKReducer";

const rootReducer = combineReducers({
userReducer,
Expand All @@ -17,6 +18,7 @@ const rootReducer = combineReducers({
stylesReducer,
paymentReducer,
uiContentReducer,
sdkReducer,
});

export default rootReducer;
Loading

0 comments on commit 7c83fb8

Please sign in to comment.