mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-29 19:14:22 -05:00
* Rename loot-core/platform/client/fetch package to connection to match the server side package name. Also to avoid confusion with the native fetch package. * Update connection/init method to not receive any parameter to so browser and default implementation have the same signature * Add release notes for PR #6943 * Fix names * Fix imports --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { send } from 'loot-core/platform/client/connection';
|
|
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,
|
|
}: {
|
|
onSuccess: (data: GoCardlessToken) => Promise<void>;
|
|
onClose?: () => void;
|
|
},
|
|
) {
|
|
dispatch(
|
|
pushModal({
|
|
modal: {
|
|
name: 'gocardless-external-msg',
|
|
options: {
|
|
onMoveExternal: async ({ institutionId }) => {
|
|
const resp = await send('gocardless-create-web-token', {
|
|
institutionId,
|
|
accessValidForDays: 90,
|
|
});
|
|
|
|
if ('error' in resp) return resp;
|
|
const { link, requisitionId } = resp;
|
|
window.Actual.openURLInBrowser(link);
|
|
|
|
return send('gocardless-poll-web-token', {
|
|
requisitionId,
|
|
});
|
|
},
|
|
onClose,
|
|
onSuccess,
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
}
|
|
|
|
export async function authorizeBank(dispatch: AppDispatch) {
|
|
_authorize(dispatch, {
|
|
onSuccess: async data => {
|
|
dispatch(
|
|
pushModal({
|
|
modal: {
|
|
name: 'select-linked-accounts',
|
|
options: {
|
|
externalAccounts: data.accounts,
|
|
requisitionId: data.id,
|
|
syncSource: 'goCardless',
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
},
|
|
});
|
|
}
|