Files
actual/packages/desktop-client/src/gocardless.ts
Joel Jeremy Marquez cb5237359c Rename loot-core/platform/client/fetch to connection to match server-side package (#6943)
* 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>
2026-02-13 16:53:51 +00:00

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',
},
},
}),
);
},
});
}