From bc0022e03cac6f68208dced4adfcd64573b9869d Mon Sep 17 00:00:00 2001 From: MGrgr Date: Fri, 20 Jan 2023 12:00:49 +0300 Subject: [PATCH] fix: rpc with jwt --- src/config/connection.ts | 11 ++++++++--- src/store/connection.ts | 2 ++ src/utils/index.ts | 1 + src/utils/{gengo.ts => rpc.ts} | 36 ++-------------------------------- types/components.d.ts | 2 +- 5 files changed, 14 insertions(+), 38 deletions(-) rename src/utils/{gengo.ts => rpc.ts} (61%) diff --git a/src/config/connection.ts b/src/config/connection.ts index 350c1f4..a3b2a62 100644 --- a/src/config/connection.ts +++ b/src/config/connection.ts @@ -28,7 +28,7 @@ import { Endpoint } from '@/store'; import { Commitment, clusterApiUrl } from '@solana/web3.js'; -// import { getGengoToken } from '@/utils/gengo'; +import { getJFRpcToken } from '@/utils/rpc'; const mode = import.meta.env.MODE; const isDev = mode == 'development'; @@ -46,10 +46,15 @@ export const ENDPOINTS: Endpoint[] = [ id: 'jpool-mainnet', name: 'Jpool RPC', cluster: 'mainnet-beta', - url: 'https://rpc.jfactory.ch/', + url: import.meta.env.DEV + ? 'https://restless-blue-valley.solana-mainnet.quiknode.pro/388d47063172de995210b42f44a3483d4269dcf9/' + : 'https://rpc.jfactory.ch/', + wsEndpoint: import.meta.env.DEV + ? undefined + : 'wss://sleek-solemn-rain.solana-mainnet.quiknode.pro/1bac3b4146d57810e23b4263129fda9dbff83fe9/', stakePoolAddress: MAIN_STAKE_POOL_ADDRESS, stakeLimit: MAIN_STAKE_LIMIT, - // getToken: getGengoToken, + getToken: getJFRpcToken, }, { id: 'serum-mainnet', diff --git a/src/store/connection.ts b/src/store/connection.ts index 4f3f815..6dbf949 100644 --- a/src/store/connection.ts +++ b/src/store/connection.ts @@ -41,6 +41,7 @@ export interface Endpoint { url: string; stakePoolAddress: string; stakeLimit?: number; + wsEndpoint?: string; getToken?: () => Promise; } @@ -58,6 +59,7 @@ export const useConnectionStore = defineStore({ connection(state): Connection { return new Connection(this.endpoint.url, { confirmTransactionInitialTimeout: state.confirmTransactionInitialTimeout, + wsEndpoint: this.endpoint.wsEndpoint, commitment: state.commitment, fetchMiddleware: this.endpoint.getToken ? tokenAuthFetchMiddleware({ diff --git a/src/utils/index.ts b/src/utils/index.ts index 9987eaa..f75113c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -31,3 +31,4 @@ export * from './connection'; export * from './debounce'; export * from './format'; export * from './web3'; +export * from './rpc'; diff --git a/src/utils/gengo.ts b/src/utils/rpc.ts similarity index 61% rename from src/utils/gengo.ts rename to src/utils/rpc.ts index d9ee795..244ba45 100644 --- a/src/utils/gengo.ts +++ b/src/utils/rpc.ts @@ -26,42 +26,10 @@ * The developer of this program can be contacted at . */ -import { API_URL } from '@/config'; import axios from 'axios'; import { debounceAsync } from '@/utils/index'; -const getCsrfToken = debounceAsync<() => Promise, string>( - async () => - axios(`${API_URL}/auth/csrf`, { - withCredentials: true, - }).then(({ data }) => data.token), - 250, -); - -export const getGengoToken = debounceAsync(async () => { - const token = await getCsrfToken(); - if (!token) { - throw 'Invalid token'; - } - const res = await axios(`${API_URL}/auth/genesysgo`, { - withCredentials: true, - headers: { - 'X-XSRF-TOKEN': token, - }, - }); +export const getJFRpcToken = debounceAsync(async () => { + const res = await axios('https://jwt.jfactory.workers.dev', {}); return res.data.access_token; }, 250) as () => Promise; - -// export async function getGengoToken() { -// const token = await getCsrfToken(); -// if (!token) { -// throw 'Invalid token'; -// } -// const res = await axios(`${API_URL}/auth/genesysgo`, { -// withCredentials: true, -// headers: { -// 'X-XSRF-TOKEN': token, -// }, -// }); -// return res.data.access_token; -// } diff --git a/types/components.d.ts b/types/components.d.ts index 2be8222..617ae7a 100644 --- a/types/components.d.ts +++ b/types/components.d.ts @@ -18,7 +18,7 @@ declare module '@vue/runtime-core' { RoiCalculatorBtn: typeof import('./../src/components/staking/RoiCalculatorBtn.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] - SolSvg: typeof import('./../src/components/icons/SolSvg.vue')['default'] + SolSvg: typeof import('./../src/components/Icons/SolSvg.vue')['default'] StakeBox: typeof import('./../src/components/staking/stake/StakeBox.vue')['default'] StakeSuccessDialog: typeof import('./../src/components/staking/stake/StakeSuccessDialog.vue')['default'] ThemeModeSelector: typeof import('./../src/components/ThemeModeSelector.vue')['default']