From d06411c8c6f02e23551902d21b6c5d4163c8d215 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:23:50 -0400 Subject: [PATCH 01/10] simplify logic and remove cookie set --- explorer/src/providers/ChainProvider.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/explorer/src/providers/ChainProvider.tsx b/explorer/src/providers/ChainProvider.tsx index d1d67f69..786f099c 100644 --- a/explorer/src/providers/ChainProvider.tsx +++ b/explorer/src/providers/ChainProvider.tsx @@ -12,7 +12,6 @@ import { import { RetryLink } from '@apollo/client/link/retry' import { NetworkId } from '@autonomys/auto-utils' import { Indexer, defaultIndexer } from 'constants/indexers' -import Cookies from 'js-cookie' import { FC, ReactNode, createContext, useCallback, useMemo, useState } from 'react' export type ChainContextValue = { @@ -63,14 +62,11 @@ export const SelectedChainProvider: FC = ({ indexerSet, chil export const ChainProvider: FC = ({ children }) => { const [indexerSet, _setIndexerSet] = useState(defaultIndexer) - const [network, setNetwork] = useState(defaultIndexer.network) const [section, setSection] = useState(Routes.consensus) const setIndexerSet = useCallback( (indexer: Indexer) => { - Cookies.set('selected-network', indexer.network, { expires: 1 }) _setIndexerSet(indexer) - setNetwork(indexer.network) }, [_setIndexerSet], ) @@ -79,7 +75,7 @@ export const ChainProvider: FC = ({ children }) => { Date: Wed, 28 Aug 2024 13:24:32 -0400 Subject: [PATCH 02/10] use next callback urk to retrieve network instead --- explorer/src/utils/queryGraphqlServer.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index 9447d55e..78f621e3 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -5,11 +5,17 @@ export const queryGraphqlServer = async (query: string, variables: object) => { try { // Get the selected chain from the cookies const { get } = cookies() - const selectedNetwork = get('selected-network') - if (!selectedNetwork) throw new Error('No selected network') + const callbackUrlCookie = get('next-auth.callback-url') + if (!callbackUrlCookie) throw new Error('No callback URL cookie') + + // Extract the network ID from the callback URL + const callbackUrl = decodeURIComponent(callbackUrlCookie.value) + const url = new URL(callbackUrl) + const networkId = url.pathname.split('/')[1] // The network ID is the second part of the path + if (!networkId) throw new Error('No network ID found in callback URL') // Find the selected chain api - const api = indexers.find((indexer) => indexer.network === selectedNetwork.value) + const api = indexers.find((indexer) => indexer.network === networkId) if (!api) throw new Error('No selected chain api') // Fetch the data from the api From cedf2a323396a1096d670d35197c47bd34f7a8aa Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:31:08 -0400 Subject: [PATCH 03/10] remove js-cookie --- explorer/package.json | 2 -- explorer/yarn.lock | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/explorer/package.json b/explorer/package.json index 73c0153b..4be4b8d9 100644 --- a/explorer/package.json +++ b/explorer/package.json @@ -56,7 +56,6 @@ "faunadb": "^4.8.0", "formik": "^2.4.5", "graphql": "^16.6.0", - "js-cookie": "^3.0.5", "jsonwebtoken": "^9.0.2", "lodash": "^4.17.21", "lottie-react": "^2.4.0", @@ -89,7 +88,6 @@ "@next/eslint-plugin-next": "^14.1.3", "@svgr/webpack": "^8.1.0", "@types/jest": "^29.5.12", - "@types/js-cookie": "^3.0.6", "@types/jsonwebtoken": "^9.0.3", "@types/node": "^20.11.24", "@types/react": "^18.2.63", diff --git a/explorer/yarn.lock b/explorer/yarn.lock index f91c9045..6d3c061c 100644 --- a/explorer/yarn.lock +++ b/explorer/yarn.lock @@ -3554,11 +3554,6 @@ expect "^29.0.0" pretty-format "^29.0.0" -"@types/js-cookie@^3.0.6": - version "3.0.6" - resolved "https://registry.yarnpkg.com/@types/js-cookie/-/js-cookie-3.0.6.tgz#a04ca19e877687bd449f5ad37d33b104b71fdf95" - integrity sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ== - "@types/js-yaml@^4.0.0": version "4.0.9" resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.9.tgz#cd82382c4f902fed9691a2ed79ec68c5898af4c2" @@ -6963,11 +6958,6 @@ jose@^5.0.0: resolved "https://registry.yarnpkg.com/jose/-/jose-5.2.3.tgz#071c87f9fe720cff741a403c8080b69bfe13164a" integrity sha512-KUXdbctm1uHVL8BYhnyHkgp3zDX5KW8ZhAKVFEfUbU2P8Alpzjb+48hHvjOdQIyPshoblhzsuqOwEEAbtHVirA== -js-cookie@^3.0.5: - version "3.0.5" - resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-3.0.5.tgz#0b7e2fd0c01552c58ba86e0841f94dc2557dcdbc" - integrity sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw== - "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -8980,7 +8970,16 @@ string-env-interpolation@^1.0.1: resolved "https://registry.yarnpkg.com/string-env-interpolation/-/string-env-interpolation-1.0.1.tgz#ad4397ae4ac53fe6c91d1402ad6f6a52862c7152" integrity sha512-78lwMoCcn0nNu8LszbP1UA7g55OeE4v7rCeWnM5B453rnNr4aq+5it3FEYtZrSEiMvHZOZ9Jlqb0OD0M2VInqg== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -9068,7 +9067,14 @@ stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -10022,7 +10028,7 @@ workbox-window@6.6.1, workbox-window@^6.5.4: "@types/trusted-types" "^2.0.2" workbox-core "6.6.1" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -10040,6 +10046,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From f31c3dd1595c76bae7e247748c1342958abd62a4 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 16:21:28 -0400 Subject: [PATCH 04/10] add log --- explorer/src/utils/queryGraphqlServer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index 78f621e3..a7a9739b 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -5,6 +5,7 @@ export const queryGraphqlServer = async (query: string, variables: object) => { try { // Get the selected chain from the cookies const { get } = cookies() + console.log('all-cookies', cookies()) const callbackUrlCookie = get('next-auth.callback-url') if (!callbackUrlCookie) throw new Error('No callback URL cookie') From 26a4a81e21164b8fef8563e288f70cdc31df5084 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 16:27:34 -0400 Subject: [PATCH 05/10] support secure cookie callback --- explorer/src/utils/queryGraphqlServer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index a7a9739b..bfe839b8 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -6,7 +6,8 @@ export const queryGraphqlServer = async (query: string, variables: object) => { // Get the selected chain from the cookies const { get } = cookies() console.log('all-cookies', cookies()) - const callbackUrlCookie = get('next-auth.callback-url') + const callbackUrlCookie = + get('next-auth.callback-url') || get('__Secure-next-auth.callback-url') if (!callbackUrlCookie) throw new Error('No callback URL cookie') // Extract the network ID from the callback URL From 4dd2b81976cbfc773b6ca6425d86ec735e11bd2d Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 16:28:26 -0400 Subject: [PATCH 06/10] add more log --- explorer/src/utils/queryGraphqlServer.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index bfe839b8..ecbe267e 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -13,7 +13,9 @@ export const queryGraphqlServer = async (query: string, variables: object) => { // Extract the network ID from the callback URL const callbackUrl = decodeURIComponent(callbackUrlCookie.value) const url = new URL(callbackUrl) + console.log('url', url) const networkId = url.pathname.split('/')[1] // The network ID is the second part of the path + console.log('networkId', networkId) if (!networkId) throw new Error('No network ID found in callback URL') // Find the selected chain api From c647fe9d4faffa7b4f4d54a72a315cba01d8f769 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 16:37:07 -0400 Subject: [PATCH 07/10] add fallback with default network --- explorer/src/utils/queryGraphqlServer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index ecbe267e..518204ec 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -1,4 +1,4 @@ -import { indexers } from 'constants/indexers' +import { defaultIndexer, indexers } from 'constants/indexers' import { cookies } from 'next/headers' export const queryGraphqlServer = async (query: string, variables: object) => { @@ -14,7 +14,7 @@ export const queryGraphqlServer = async (query: string, variables: object) => { const callbackUrl = decodeURIComponent(callbackUrlCookie.value) const url = new URL(callbackUrl) console.log('url', url) - const networkId = url.pathname.split('/')[1] // The network ID is the second part of the path + const networkId = url.pathname.split('/')[1] ?? defaultIndexer.network console.log('networkId', networkId) if (!networkId) throw new Error('No network ID found in callback URL') From 0d337b20890fdfde6e703bde6a9c04091facdf6e Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 16:45:15 -0400 Subject: [PATCH 08/10] change logic --- explorer/src/utils/queryGraphqlServer.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index 518204ec..c8e21775 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -14,9 +14,12 @@ export const queryGraphqlServer = async (query: string, variables: object) => { const callbackUrl = decodeURIComponent(callbackUrlCookie.value) const url = new URL(callbackUrl) console.log('url', url) - const networkId = url.pathname.split('/')[1] ?? defaultIndexer.network + let networkId = url.pathname.split('/')[1] + console.log('networkId', networkId) + if (!networkId) { + networkId = defaultIndexer.network + } console.log('networkId', networkId) - if (!networkId) throw new Error('No network ID found in callback URL') // Find the selected chain api const api = indexers.find((indexer) => indexer.network === networkId) From 16a4f0396c54a99778f6d20de8c9a49e427d1aea Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Wed, 28 Aug 2024 16:53:21 -0400 Subject: [PATCH 09/10] remove log --- explorer/src/utils/queryGraphqlServer.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index c8e21775..90f6735b 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -5,7 +5,6 @@ export const queryGraphqlServer = async (query: string, variables: object) => { try { // Get the selected chain from the cookies const { get } = cookies() - console.log('all-cookies', cookies()) const callbackUrlCookie = get('next-auth.callback-url') || get('__Secure-next-auth.callback-url') if (!callbackUrlCookie) throw new Error('No callback URL cookie') @@ -13,13 +12,10 @@ export const queryGraphqlServer = async (query: string, variables: object) => { // Extract the network ID from the callback URL const callbackUrl = decodeURIComponent(callbackUrlCookie.value) const url = new URL(callbackUrl) - console.log('url', url) let networkId = url.pathname.split('/')[1] - console.log('networkId', networkId) if (!networkId) { networkId = defaultIndexer.network } - console.log('networkId', networkId) // Find the selected chain api const api = indexers.find((indexer) => indexer.network === networkId) From 117d138d0ea684b16d5f03112b71697ae46e2a89 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:38:35 -0400 Subject: [PATCH 10/10] simplify logic --- explorer/src/utils/queryGraphqlServer.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/explorer/src/utils/queryGraphqlServer.ts b/explorer/src/utils/queryGraphqlServer.ts index 90f6735b..c398b360 100644 --- a/explorer/src/utils/queryGraphqlServer.ts +++ b/explorer/src/utils/queryGraphqlServer.ts @@ -1,24 +1,9 @@ import { defaultIndexer, indexers } from 'constants/indexers' -import { cookies } from 'next/headers' export const queryGraphqlServer = async (query: string, variables: object) => { try { - // Get the selected chain from the cookies - const { get } = cookies() - const callbackUrlCookie = - get('next-auth.callback-url') || get('__Secure-next-auth.callback-url') - if (!callbackUrlCookie) throw new Error('No callback URL cookie') - - // Extract the network ID from the callback URL - const callbackUrl = decodeURIComponent(callbackUrlCookie.value) - const url = new URL(callbackUrl) - let networkId = url.pathname.split('/')[1] - if (!networkId) { - networkId = defaultIndexer.network - } - // Find the selected chain api - const api = indexers.find((indexer) => indexer.network === networkId) + const api = indexers.find((indexer) => indexer.network === defaultIndexer.network) if (!api) throw new Error('No selected chain api') // Fetch the data from the api