From 40171399992c8ab3ca464db1e410df8e74eac802 Mon Sep 17 00:00:00 2001 From: Morgan Brown Date: Tue, 10 Dec 2024 20:25:56 +0100 Subject: [PATCH] Centralize github api client for loading funding.json --- .../steps/connect-wallet/connect-wallet.svelte | 9 +-------- .../steps/enter-git-url/enter-git-url.svelte | 8 ++------ .../steps/enter-git-url/enter-git-url.ts | 8 ++++++-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/lib/flows/claim-project-flow/steps/connect-wallet/connect-wallet.svelte b/src/lib/flows/claim-project-flow/steps/connect-wallet/connect-wallet.svelte index a76a06a44..2279ecf98 100644 --- a/src/lib/flows/claim-project-flow/steps/connect-wallet/connect-wallet.svelte +++ b/src/lib/flows/claim-project-flow/steps/connect-wallet/connect-wallet.svelte @@ -8,17 +8,10 @@ import { createEventDispatcher } from 'svelte'; import type { StepComponentEvents } from '$lib/components/stepper/types'; import Button from '$lib/components/button/button.svelte'; - // import unreachable from '$lib/utils/unreachable'; - // import { getChangedTemplate } from '../add-ethereum-address/drips-json-template'; - import { Octokit } from '@octokit/rest'; - import GitHub from '$lib/utils/github/GitHub'; import type { Writable } from 'svelte/store'; import type { State } from '../../claim-project-flow'; import { loadingFundingInfo } from '../enter-git-url/enter-git-url'; - const octokit = new Octokit(); - const github = new GitHub(octokit); - const dispatch = createEventDispatcher(); export let context: Writable; @@ -29,7 +22,7 @@ dispatch('await', { message: 'Gathering project information…', promise: async () => { - return loadingFundingInfo(context, github); + return loadingFundingInfo(context); }, }); } diff --git a/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.svelte b/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.svelte index 831bed090..d0df230a5 100644 --- a/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.svelte +++ b/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.svelte @@ -52,13 +52,8 @@ import walletStore from '$lib/stores/wallet/wallet.store'; import ArrowLeft from '$lib/components/icons/ArrowLeft.svelte'; import modal from '$lib/stores/modal'; - import { Octokit } from '@octokit/rest'; - import GitHub from '$lib/utils/github/GitHub'; import { loadingFundingInfo } from './enter-git-url'; - const octokit = new Octokit(); - const github = new GitHub(octokit); - export let context: Writable; export let projectUrl: string | undefined = undefined; @@ -219,7 +214,8 @@ $context.projectColor = seededRandomElement(possibleColors, project.account.accountId); validationState = { type: 'valid' }; - loadingFundingInfo(context, github); + // TODO: do before heading to next step? + loadingFundingInfo(context); } catch (error: unknown) { // eslint-disable-next-line no-console console.error(error); diff --git a/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.ts b/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.ts index fa365f331..dcc403d80 100644 --- a/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.ts +++ b/src/lib/flows/claim-project-flow/steps/enter-git-url/enter-git-url.ts @@ -1,11 +1,15 @@ import type { State } from '../../claim-project-flow'; import unreachable from '$lib/utils/unreachable'; import { getChangedTemplate } from '../add-ethereum-address/drips-json-template'; -import type GitHub from '$lib/utils/github/GitHub'; +import GitHub from '$lib/utils/github/GitHub'; import { get, type Writable } from 'svelte/store'; import walletStore from '$lib/stores/wallet/wallet.store'; +import { Octokit } from '@octokit/rest'; -export async function loadingFundingInfo(context: Writable, github: GitHub): Promise { +const octokit = new Octokit(); +const github = new GitHub(octokit); + +export async function loadingFundingInfo(context: Writable): Promise { const $walletStore = get(walletStore); const address = $walletStore.address ?? ''; const network = $walletStore.network.name