Skip to content

Commit

Permalink
fix: rpc with jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
MGrgr committed Jan 20, 2023
1 parent 849f6f9 commit bc0022e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 deletions.
11 changes: 8 additions & 3 deletions src/config/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/store/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface Endpoint {
url: string;
stakePoolAddress: string;
stakeLimit?: number;
wsEndpoint?: string;
getToken?: () => Promise<string>;
}

Expand All @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export * from './connection';
export * from './debounce';
export * from './format';
export * from './web3';
export * from './rpc';
36 changes: 2 additions & 34 deletions src/utils/gengo.ts → src/utils/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,10 @@
* The developer of this program can be contacted at <[email protected]>.
*/

import { API_URL } from '@/config';
import axios from 'axios';
import { debounceAsync } from '@/utils/index';

const getCsrfToken = debounceAsync<() => Promise<string>, 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<string>;

// 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;
// }
2 changes: 1 addition & 1 deletion types/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit bc0022e

Please sign in to comment.