Skip to content

Commit

Permalink
fix: adjust integration to default to locally stored data (#276)
Browse files Browse the repository at this point in the history
This is to avoid having empty integrations if the network is slow
  • Loading branch information
kelsos authored Feb 11, 2025
1 parent 4d0929c commit ea2b87d
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions composables/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import { IntegrationData, type IntegrationItem } from '~/types/integrations';
import LocalIntegrationData from '~/public/integrations/all.json';

export const useIntegrationsData = createSharedComposable(() => {
const defaultData = () => ({
blockchains: [],
exchanges: [],
protocols: [],
});

const { public: { isDev, testing } } = useRuntimeConfig();

const getRemoteIntegrationData = async (): Promise<IntegrationData | null> => {
Expand Down Expand Up @@ -57,16 +51,15 @@ export const useIntegrationsData = createSharedComposable(() => {
};

const data = asyncComputed<IntegrationData>(async () => {
if (isDev)
return filterDuplicateData(LocalIntegrationData);

const remoteData = await getRemoteIntegrationData();

if (remoteData)
return filterDuplicateData(remoteData);

return defaultData();
}, defaultData());
let data: IntegrationData;
if (isDev) {
data = LocalIntegrationData;
}
else {
data = await getRemoteIntegrationData() ?? LocalIntegrationData;
}
return filterDuplicateData(data);
}, filterDuplicateData(LocalIntegrationData));

return {
data,
Expand Down

0 comments on commit ea2b87d

Please sign in to comment.