mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 20:44:32 -05:00
77 lines
1.8 KiB
TypeScript
77 lines
1.8 KiB
TypeScript
import { send } from 'loot-core/platform/client/fetch';
|
|
import { type GoCardlessToken } from 'loot-core/types/models';
|
|
|
|
import { pushModal } from './modals/modalsSlice';
|
|
import { type AppDispatch } from './redux/store';
|
|
|
|
function _authorize(
|
|
dispatch: AppDispatch,
|
|
{
|
|
onSuccess,
|
|
onClose,
|
|
fileId,
|
|
password,
|
|
}: {
|
|
onSuccess: (data: GoCardlessToken) => Promise<void>;
|
|
onClose?: () => void;
|
|
fileId?: string;
|
|
password?: string;
|
|
},
|
|
) {
|
|
dispatch(
|
|
pushModal({
|
|
modal: {
|
|
name: 'gocardless-external-msg',
|
|
options: {
|
|
fileId,
|
|
onMoveExternal: async ({ institutionId }) => {
|
|
const resp = await send('gocardless-create-web-token', {
|
|
institutionId,
|
|
accessValidForDays: 90,
|
|
...(fileId ? { fileId } : {}),
|
|
...(password ? { password } : {}),
|
|
});
|
|
|
|
if ('error' in resp) return resp;
|
|
const { link, requisitionId } = resp;
|
|
window.Actual.openURLInBrowser(link);
|
|
|
|
return send('gocardless-poll-web-token', {
|
|
requisitionId,
|
|
...(fileId ? { fileId } : {}),
|
|
...(password ? { password } : {}),
|
|
});
|
|
},
|
|
onClose,
|
|
onSuccess,
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
}
|
|
|
|
export async function authorizeBank(
|
|
dispatch: AppDispatch,
|
|
fileId?: string,
|
|
password?: string,
|
|
) {
|
|
_authorize(dispatch, {
|
|
fileId,
|
|
password,
|
|
onSuccess: async data => {
|
|
dispatch(
|
|
pushModal({
|
|
modal: {
|
|
name: 'select-linked-accounts',
|
|
options: {
|
|
externalAccounts: data.accounts,
|
|
requisitionId: data.id,
|
|
syncSource: 'goCardless',
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
},
|
|
});
|
|
}
|