From 2ce5f1a433a41a16b4795b2337141b0eaca5e3e4 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 21 May 2024 20:32:49 -0700 Subject: [PATCH] chore: save progress --- app/app.nix | 2 +- app/package-lock.json | 26 ++++++++++ app/package.json | 2 + app/src/lib/graphql/client.ts | 18 ++++++- app/src/lib/utilities/index.ts | 12 +++++ app/src/routes/+page.svelte | 82 +++++++++++++----------------- app/src/routes/faucet/+page.svelte | 23 +++------ app/src/styles/index.css | 4 +- dictionary.txt | 1 + 9 files changed, 104 insertions(+), 66 deletions(-) diff --git a/app/app.nix b/app/app.nix index 986ebc1bec..d2d9978811 100644 --- a/app/app.nix +++ b/app/app.nix @@ -9,7 +9,7 @@ { packages = { app = unstablePkgs.buildNpmPackage { - npmDepsHash = "sha256-sUUs9Z0f03cZXRYvnIC09OetVH50xzFQa4UzoGctOMY="; + npmDepsHash = "sha256-33VI+y9QxErD4gqy9d26+KIMwZbtRgDK9Aq+VhAC+n4="; src = ./.; sourceRoot = "app"; npmFlags = [ "--legacy-peer-deps" ]; diff --git a/app/package-lock.json b/app/package-lock.json index 90fe74fb83..6bdc5ac2b3 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -22,6 +22,8 @@ "@union/client": "npm:@jsr/union__client@^0.0.1-rc.9", "@urql/exchange-graphcache": "^7.1.0", "@urql/exchange-persisted": "^4.3.0", + "@urql/exchange-refocus": "^1.1.0", + "@urql/exchange-request-policy": "^1.2.0", "@urql/exchange-retry": "^1.3.0", "@urql/svelte": "^4.2.0", "@wagmi/connectors": "^5.0.3", @@ -3465,6 +3467,30 @@ "@urql/core": "^5.0.0" } }, + "node_modules/@urql/exchange-refocus": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@urql/exchange-refocus/-/exchange-refocus-1.1.0.tgz", + "integrity": "sha512-tMgIqXUGIuNBeEoXDNOZ48Kut2m85etNIorwBG89tQZHDLxJM52N6A0eLm0Mv9BJFb0U94i3drwlD55He+9Uvw==", + "dependencies": { + "@urql/core": "^5.0.0", + "wonka": "^6.3.2" + }, + "peerDependencies": { + "@urql/core": "^5.0.0" + } + }, + "node_modules/@urql/exchange-request-policy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@urql/exchange-request-policy/-/exchange-request-policy-1.2.0.tgz", + "integrity": "sha512-30CwS5/YzX0YWVATg19rrDhruDCRIu96xUz6HGlhJPUw22M7njRldl44fmoU11ZbIemg01t8ysq6+0rdktYBgg==", + "dependencies": { + "@urql/core": "^5.0.0", + "wonka": "^6.3.2" + }, + "peerDependencies": { + "@urql/core": "^5.0.0" + } + }, "node_modules/@urql/exchange-retry": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@urql/exchange-retry/-/exchange-retry-1.3.0.tgz", diff --git a/app/package.json b/app/package.json index 6f30875ea3..04f439ae04 100644 --- a/app/package.json +++ b/app/package.json @@ -33,6 +33,8 @@ "@union/client": "npm:@jsr/union__client@^0.0.1-rc.9", "@urql/exchange-graphcache": "^7.1.0", "@urql/exchange-persisted": "^4.3.0", + "@urql/exchange-refocus": "^1.1.0", + "@urql/exchange-request-policy": "^1.2.0", "@urql/exchange-retry": "^1.3.0", "@urql/svelte": "^4.2.0", "@wagmi/connectors": "^5.0.3", diff --git a/app/src/lib/graphql/client.ts b/app/src/lib/graphql/client.ts index 90c78a007c..04d5849bb0 100644 --- a/app/src/lib/graphql/client.ts +++ b/app/src/lib/graphql/client.ts @@ -9,8 +9,10 @@ import { import { URLS } from "$lib/constants" import { devtoolsExchange } from "@urql/devtools" import { retryExchange } from "@urql/exchange-retry" +import { refocusExchange } from "@urql/exchange-refocus" import type { TadaPersistedDocumentNode } from "gql.tada" import { persistedExchange } from "@urql/exchange-persisted" +import { requestPolicyExchange } from "@urql/exchange-request-policy" import { createClient as createWSClient, type SubscribePayload } from "graphql-ws" const isDevelopment = import.meta.env.DEV @@ -50,7 +52,19 @@ export const graphqlClient = new Client({ requestPolicy: import.meta.env.DEV ? "network-only" : "cache-and-network", exchanges: [ devtoolsExchange, - ...productionOnlyExchanges, + refocusExchange(), + requestPolicyExchange({ + ttl: 60 * 1_000, // 1 minute + shouldUpgrade: operation => operation.context.requestPolicy !== "cache-first" + }), + cacheExchange, + persistedExchange({ + enableForMutation: true, + enableForSubscriptions: true, + enforcePersistedQueries: true, + preferGetForPersistedQueries: true, + generateHash: async (_, document) => (document as TadaPersistedDocumentNode).documentId + }), fetchExchange, subscriptionExchange({ forwardSubscription: operation => ({ @@ -64,7 +78,7 @@ export const graphqlClient = new Client({ maxDelayMs: 15_000, maxNumberAttempts: 2, initialDelayMs: 1_000, - retryIf: error => !!error?.networkError?.message + retryIf: error => !!error?.networkError }), debugExchange ], diff --git a/app/src/lib/utilities/index.ts b/app/src/lib/utilities/index.ts index ceaf3f3967..553557fcd6 100644 --- a/app/src/lib/utilities/index.ts +++ b/app/src/lib/utilities/index.ts @@ -2,6 +2,18 @@ export function raise(error: unknown): never { throw typeof error === "string" ? new Error(error) : error } +// remove duplicates from an array of objects by a key +export const removeArrayDuplicates = (array: Array, key: keyof T): Array => + array.reduce( + (accumulator, current) => { + if (!accumulator.find(item => item[key] === current[key])) { + accumulator.push(current) + } + return accumulator + }, + [] as Array + ) + export const elementHasFocus = (element: Element | null): element is HTMLElement => element === document.activeElement diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index c39a5275d1..f229fef3fa 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -1,54 +1,39 @@