Skip to content

Commit

Permalink
chore: refactor env usage (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
0Xsolcreator authored Feb 16, 2025
1 parent d8dc927 commit 290bb1f
Show file tree
Hide file tree
Showing 27 changed files with 71 additions and 155 deletions.
6 changes: 3 additions & 3 deletions src/api/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class ApiClient {
private walletClient: AxiosInstance;

constructor() {
const authServiceUrl = process.env.AUTH_SERVICE_URL;
const dataServiceUrl = process.env.DATA_SERVICE_URL;
const walletServiceUrl = process.env.WALLET_SERVICE_URL;
const authServiceUrl = import.meta.env.VITE_AUTH_SERVICE_URL;
const dataServiceUrl = import.meta.env.VITE_DATA_SERVICE_URL;
const walletServiceUrl = import.meta.env.VITE_WALLET_SERVICE_URL;

if (!authServiceUrl) {
throw new Error('AUTH_SERVICE_URL environment variable is not defined');
Expand Down
7 changes: 3 additions & 4 deletions src/components/ui/RenderBlinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ function RenderBlinks({ actionName }: RenderBlinksProps) {
return <div>Invalid action name</div>;
}

const rpc = process.env.SOLANA_RPC || 'https://api.mainnet-beta.solana.com';
const rpc =
import.meta.env.VITE_SOLANA_RPC || 'https://api.mainnet-beta.solana.com';
// eslint-disable-next-line react-hooks/rules-of-hooks
const { adapter } = useActionSolanaWalletAdapter(rpc);
// eslint-disable-next-line react-hooks/rules-of-hooks
Expand All @@ -29,9 +30,7 @@ function RenderBlinks({ actionName }: RenderBlinksProps) {
{!isLoading && action ? (
<Blink action={action} adapter={adapter} />
) : (
<div className="text-primaryDark text-sm">
Loading blinks
</div>
<div className="text-primaryDark text-sm">Loading blinks</div>
)}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLuloActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useWalletHandler } from '../models/WalletHandler.ts';

export const useLuloActions = () => {
const { currentWallet } = useWalletHandler();
const rpc = process.env.SOLANA_RPC;
const rpc = import.meta.env.VITE_SOLANA_RPC;
const { handleAddMessage } = useChatHandler();
const { setMessageList } = useRoomStore();

Expand Down
2 changes: 1 addition & 1 deletion src/lib/solana/limitOrderTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../types/jupiter';
import { apiClient, ApiClient } from '../../api/ApiClient';

const wallet_service_url = process.env.WALLET_SERVICE_URL;
const wallet_service_url = import.meta.env.VITE_WALLET_SERVICE_URL;

export async function limitOrderTx(
params: LimitOrderParams,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/solana/lst_data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LSTData } from '../../types/data_types';
import { apiClient, ApiClient } from '../../api/ApiClient';

const data_service_url = process.env.DATA_SERVICE_URL;
const data_service_url = import.meta.env.VITE_DATA_SERVICE_URL;

export async function getLstDataHandler(): Promise<LSTData[] | null> {
let resp = await apiClient.get<LSTData[]>(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/solana/lulo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../../types/lulo';
import { VersionedTransaction } from '@solana/web3.js';

const wallet_service_url = process.env.WALLET_SERVICE_URL;
const wallet_service_url = import.meta.env.VITE_WALLET_SERVICE_URL;

export async function getAssetsLulo(
params: AssetsParams,
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function withdrawLuloTx(
wallet_service_url + 'api/wallet/lulo/withdraw',
params,
);

if (ApiClient.isApiError(response)) {
console.error('Error during withdraw:', response.errors);
return null;
Expand Down
86 changes: 0 additions & 86 deletions src/lib/solana/magiceden.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/lib/solana/rugCheck.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApiClient from '../../api/ApiClient';
import { ApiClient } from '../../api/ApiClient';
import { RugCheck } from '../../types/data_types';

const data_service_url = process.env.DATA_SERVICE_URL;
const data_service_url = import.meta.env.VITE_DATA_SERVICE_URL;

export async function getRugCheck(token: string): Promise<RugCheck | null> {
const resp = await ApiClient.get<RugCheck>(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/solana/sns.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from '@solana/web3.js';
import { getDomainKeySync, NameRegistryState } from '@bonfida/spl-name-service';

const RPC = process.env.SOLANA_RPC;
const RPC = import.meta.env.VITE_SOLANA_RPC;

function isValidDomainNamee(domainName: string): boolean {
const regex = /^[a-zA-Z0-9_-]+\.sol$/;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/solana/swapLst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SwapParams, SwapResponse } from '../../types/jupiter';
import ApiClient from '../../api/ApiClient';
import { VersionedTransaction } from '@solana/web3.js';

const wallet_service_url = process.env.WALLET_SERVICE_URL;
const wallet_service_url = import.meta.env.VITE_WALLET_SERVICE_URL;

export async function swapLST(
params: SwapParams,
Expand All @@ -23,4 +23,4 @@ export async function swapLST(
console.error('Error during swap:', error);
return null;
}
}
}
2 changes: 1 addition & 1 deletion src/lib/solana/swapTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SwapParams, SwapResponse } from '../../types/jupiter';
import { ApiClient, apiClient } from '../../api/ApiClient';
import { VersionedTransaction } from '@solana/web3.js';

const wallet_service_url = process.env.WALLET_SERVICE_URL;
const wallet_service_url = import.meta.env.VITE_WALLET_SERVICE_URL;

export async function swapTx(
params: SwapParams,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/solana/tokenGate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import { TokenGate } from '../../types/token_data';

const url = process.env.WALLET_SERVICE_URL;
const url = ;

export const tokenGate = async (address: string) => {
try {
Expand Down
6 changes: 2 additions & 4 deletions src/lib/solana/transferSpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import {
} from '@solana/web3.js';
import bs58 from 'bs58';

const rpc = process.env.SOLANA_RPC;
const sola_ata_keypair = process.env.ATA_PRIV_KEY;


const rpc = import.meta.env.VITE_SOLANA_RPC;
const sola_ata_keypair = import.meta.env.VITE_ATA_PRIV_KEY;

export async function transferSplTx(
senderAddress: string,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/solana/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const helius_api_key = process.env.HELIUS_API_KEY;
const helius_api_key = import.meta.env.VITE_HELIUS_API_KEY;
const url = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;

export const fetchFilteredAssets = async (
Expand All @@ -9,7 +9,7 @@ export const fetchFilteredAssets = async (
console.log('No address provided');
return [];
}
if (!process.env.HELIUS_API_KEY) {
if (import.meta.env.VITE_HELIUS_API_KEY) {
console.log('Helius API key not found');
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/marketMacro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ApiClient from '../../api/ApiClient';

const url = process.env.DATA_SERVICE_URL;
const url = import.meta.env.VITE_DATA_SERVICE_URL;

export const getMarketData = async () => {
if (!url) {
Expand Down
6 changes: 3 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useIsMobile from './utils/isMobile.tsx';

// Sentry Initialization
Sentry.init({
enabled: process.env.ENVIORNMENT === 'production',
enabled: import.meta.env.VITE_ENVIRONMENT === 'production',
dsn: 'https://9b7886f252a8435b9083cf088a03039d@o4508596709097472.ingest.us.sentry.io/4508601347866624',
integrations: [
Sentry.browserTracingIntegration(),
Expand Down Expand Up @@ -41,9 +41,9 @@ const RootApp = () => {

return (
<Router>
{process.env.PRVI_APP_ID && (
{import.meta.env.VITE_PRIVY_APP_ID && (
<PrivyProvider
appId={process.env.PRVI_APP_ID}
appId={import.meta.env.VITE_PRIVY_APP_ID}
config={{
loginMethods: ['email', 'wallet'],
externalWallets: {
Expand Down
4 changes: 2 additions & 2 deletions src/models/WalletHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toast } from 'sonner';
import { Connection, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
import { NFTAsset, TokenAsset, WalletAssets } from '../types/wallet.ts';

let connection = new Connection(process.env.SOLANA_RPC!, 'confirmed');
let connection = new Connection(import.meta.env.VITE_SOLANA_RPC!, 'confirmed');

interface WalletHandler {
currentWallet: ConnectedSolanaWallet | null; // The current wallet that the user is using
Expand Down Expand Up @@ -33,7 +33,7 @@ export const useWalletHandler = create<WalletHandler>((set, get) => {
if (get().status === 'paused') return;

try {
const response = await fetch(process.env.SOLANA_RPC!, {
const response = await fetch(import.meta.env.VITE_SOLANA_RPC!, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions src/models/provider/SessionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export const SessionProvider: FC<SessionProviderProps> = ({ children }) => {
const dataChannel = peerConnection.createDataChannel('oai-events');
const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);
if (!process.env.OPENAI_API_URL) {
if (!import.meta.env.VITE_OPENAI_API_URL) {
throw new Error('OPENAI_API_URL is not set');
}
const sdpResponse = await fetch(process.env.OPENAI_API_URL, {
const sdpResponse = await fetch(import.meta.env.VITE_OPENAI_API_URL, {
method: 'POST',
body: offer.sdp,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/depositLulo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function handleDepositLulo(args: {
id: 0,
createdAt: new Date().toISOString(),
});
const rpc = process.env.SOLANA_RPC;
const rpc = import.meta.env.VITE_SOLANA_RPC;

if (!args.currentWallet) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/limitOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { limitOrderTx } from '../lib/solana/limitOrderTx.ts';
import { TransactionChatContent } from '../types/chatItem.ts';
import { TransactionDataMessageItem } from '../components/ui/message_items/TransactionCard.tsx';

const rpc = process.env.SOLANA_RPC;
const rpc = import.meta.env.VITE_SOLANA_RPC;

const functionDescription =
'Creates a limit order to buy or sell a token at a specified price.';
Expand Down
2 changes: 1 addition & 1 deletion src/tools/swapTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function swapTokensFunction(args: {
response: string;
props?: SwapChatContent;
}> {
let rpc = process.env.SOLANA_RPC;
let rpc = import.meta.env.VITE_SOLANA_RPC;
if (!rpc) {
return {
status: 'error',
Expand Down
16 changes: 8 additions & 8 deletions src/tools/transferSolTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Transaction,
} from '@solana/web3.js';
import { Tool } from '../types/tool';
import { TransactionChatContent} from '../types/chatItem';
import { TransactionChatContent } from '../types/chatItem';
import { TransferChatItem } from '../components/ui/message_items/TransferMessageItem.tsx';

const functionDescription =
Expand Down Expand Up @@ -46,15 +46,15 @@ export async function transferSolTxFunction(args: {
}): Promise<{
status: 'success' | 'error';
response: string;
props?: TransactionChatContent ;
props?: TransactionChatContent;
}> {
if (args.currentWallet === null) {
return {
status: 'error',
response: 'No wallet connected',
};
}
const rpc = process.env.SOLANA_RPC;
const rpc = import.meta.env.VITE_SOLANA_RPC;
if (rpc === undefined) {
return {
status: 'error',
Expand All @@ -78,18 +78,18 @@ export async function transferSolTxFunction(args: {
const signature = await connection.sendRawTransaction(
transaction.serialize(),
);
let title = `Transfer ${amount} SOL to ${recipientAddress}`
let link = signature
let title = `Transfer ${amount} SOL to ${recipientAddress}`;
let link = signature;

const data: TransactionChatContent = {
const data: TransactionChatContent = {
response_id: 'temp',
sender: 'assistant',
type: 'transfer_sol',
data: {
title,
link,
status:"success"
}
status: 'success',
},
};

return {
Expand Down
Loading

0 comments on commit 290bb1f

Please # to comment.