1 import { put, takeEvery } from 'redux-saga/effects';
3 import { createVault } from '@proton/pass/lib/vaults/vault.requests';
4 import { vaultCreationFailure, vaultCreationIntent, vaultCreationSuccess } from '@proton/pass/store/actions';
5 import type { ShareType } from '@proton/pass/types';
6 import { type Share } from '@proton/pass/types';
8 function* createVaultWorker({ payload, meta }: ReturnType<typeof vaultCreationIntent>) {
9 const { callback: onCreateVaultProcessed } = meta;
11 const share: Share<ShareType.Vault> = yield createVault({ content: payload.content });
13 const vaultCreationSuccessAction = vaultCreationSuccess(meta.request.id, { share });
14 yield put(vaultCreationSuccessAction);
16 onCreateVaultProcessed?.(vaultCreationSuccessAction);
18 const vaultCreationFailureAction = vaultCreationFailure(meta.request.id, payload, e);
19 yield put(vaultCreationFailureAction);
21 onCreateVaultProcessed?.(vaultCreationFailureAction);
25 export default function* watcher() {
26 yield takeEvery(vaultCreationIntent.match, createVaultWorker);