Skip to content

Commit

Permalink
removed old teams services with mnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
rafijv committed Aug 28, 2024
1 parent 35b0137 commit c7754f5
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 110 deletions.
2 changes: 0 additions & 2 deletions src/app/store/slices/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { deleteDatabaseProfileAvatar } from '../../../drive/services/database.se
import { saveAvatarToDatabase } from '../../../newSettings/Sections/Account/Account/components/AvatarWrapper';
import notificationsService, { ToastType } from '../../../notifications/services/notifications.service';
import tasksService from '../../../tasks/services/tasks.service';
import { storeTeamsInfo } from '../../../teams/services/teams.service';
import { referralsActions } from '../referrals';
import { sessionActions } from '../session';
import { sessionSelectors } from '../session/session.selectors';
Expand Down Expand Up @@ -68,7 +67,6 @@ export const initializeUserThunk = createAsyncThunk<

if (user.teams) {
try {
await storeTeamsInfo();
dispatch(teamActions.initialize());
} catch (err: unknown) {
localStorageService.removeItem('xTeam');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RootState } from 'app/store';
import BaseInput from 'app/shared/components/forms/inputs/BaseInput';
import AuthButton from 'app/shared/components/AuthButton';
import BaseDialog from 'app/shared/components/BaseDialog/BaseDialog';
import { getMembers, removeMember, sendEmailTeamsMember } from '../../services/teams.service';
import { getMembers, removeMember } from '../../services/teams.service';
import { uiActions } from 'app/store/slices/ui';
import { t } from 'i18next';
import notificationsService, { ToastType } from 'app/notifications/services/notifications.service';
Expand Down Expand Up @@ -47,7 +47,6 @@ const InviteTeamMemberDialog = ({ team }: InviteTeamMemberDialogProps) => {
event?.preventDefault();
try {
if (team && team.isAdmin) {
await sendEmailTeamsMember(formData.email);
notificationsService.show({
text: t('success.teamInvitationSent', { email: formData.email }),
type: ToastType.Success,
Expand Down
91 changes: 0 additions & 91 deletions src/app/teams/services/teams.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import envService from '../../core/services/env.service';
import httpService from '../../core/services/http.service';
import localStorageService from '../../core/services/local-storage.service';
import { Workspace } from '../../core/types';
import { decryptPGP, encryptPGPInvitations } from '../../crypto/services/utilspgp';
import { InfoInvitationsMembers, TeamsSettings } from '../types';

export async function getTeamsInfo(): Promise<{ userTeam: TeamsSettings; tokenTeams: string }> {
Expand Down Expand Up @@ -36,26 +32,6 @@ export async function getKeys(mail: string): Promise<{ publicKey: string }> {
});
}

export async function storeTeamsInfo(): Promise<void> {
try {
const { userTeam, tokenTeams } = await getTeamsInfo();

if (userTeam && tokenTeams) {
const mnemonic = await decryptPGP(Buffer.from(userTeam.bridge_mnemonic, 'base64').toString());

userTeam.bridge_mnemonic = mnemonic.data.toString();

localStorageService.set('xTeam', JSON.stringify(userTeam));
localStorageService.set('xTokenTeam', tokenTeams);
} else {
localStorageService.removeItem('xTeam');
localStorageService.removeItem('xTokenTeam');
}
} catch (err: unknown) {
throw new Error('Can not get info team');
}
}

export function getMembers(): Promise<InfoInvitationsMembers[]> {
return fetch(`${process.env.REACT_APP_API_URL}/teams/members`, {
method: 'get',
Expand Down Expand Up @@ -89,76 +65,9 @@ export function removeMember(item: InfoInvitationsMembers): Promise<void> {
});
}

export async function sendEmailTeamsMember(mail: string): Promise<void> {
const { publicKey } = await getKeys(mail);
const xTeam = localStorageService.getTeams() as TeamsSettings;

//Datas
const bridgePass = xTeam.bridge_password;
const mnemonicTeam = xTeam.bridge_mnemonic;

//Encrypt
const EncryptBridgePass = await encryptPGPInvitations(bridgePass, publicKey);
const EncryptMnemonicTeam = await encryptPGPInvitations(mnemonicTeam, publicKey);

const base64bridge_password = Buffer.from(EncryptBridgePass).toString('base64');
const base64Mnemonic = Buffer.from(EncryptMnemonicTeam).toString('base64');
const bridgeuser = xTeam.bridge_user;

await fetchInvitation(mail, base64bridge_password, base64Mnemonic, bridgeuser);
}

const fetchInvitation = (email: string, bridgePass: string, mnemonicTeam: string, bridgeuser: string) => {
return fetch(`${process.env.REACT_APP_API_URL}/teams/team/invitations`, {
method: 'POST',
headers: httpService.getHeaders(true, false, true),
body: JSON.stringify({
email,
bridgePass,
mnemonicTeam,
bridgeuser,
}),
})
.then((invitation) => {
if (invitation.status !== 200) {
throw new Error('Can not invite this member');
}
return invitation.json();
})
.catch((err) => {
throw err;
});
};

function getTeamInfoStripeSuccess() {
return httpService.get<TeamsSettings>('/teams/team/info', { authWorkspace: Workspace.Individuals });
}

export async function checkSessionStripe(
sessionId: string,
): Promise<void | { userTeams: TeamsSettings; tokenTeams: string }> {
const userTeam = await getTeamInfoStripeSuccess();
const mnemonic = await decryptPGP(Buffer.from(userTeam.bridge_mnemonic, 'base64').toString());

return httpService
.post<{ checkoutSessionId: string; test: boolean; mnemonic: string }, void>(
'/teams/checkout/session',
{
checkoutSessionId: sessionId,
test: !envService.isProduction(),
mnemonic: mnemonic.data.toString(),
},
{ authWorkspace: Workspace.Individuals },
)
.then(() => storeTeamsInfo());
}

const teamsService = {
getTeamsInfo,
getKeys,
storeTeamsInfo,
sendEmailTeamsMember,
checkSessionStripe,
};

export default teamsService;
16 changes: 1 addition & 15 deletions src/app/teams/views/TeamSuccessView/TeamSuccessView.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import { match } from 'react-router';
import LoadingPulse from 'app/shared/components/LoadingPulse/LoadingPulse';

import teamsService from '../../services/teams.service';
import { useAppDispatch } from 'app/store/hooks';
import { userThunks } from 'app/store/slices/user';
import notificationsService, { ToastType } from 'app/notifications/services/notifications.service';
import { t } from 'i18next';

export default function Success(props: { match: match<{ sessionId: string }> }): JSX.Element {
const dispatch = useAppDispatch();

teamsService.checkSessionStripe(props.match.params.sessionId).then(() => {
dispatch(userThunks.logoutThunk());
notificationsService.show({ text: t('success.teamsSubscriptionRedeemed'), type: ToastType.Info });
});

export default function Success(): JSX.Element {
return (
<div className="jutify-center mt-3 flex content-center">
<LoadingPulse />
Expand Down

0 comments on commit c7754f5

Please sign in to comment.