Skip to content

Commit

Permalink
feat: update base url
Browse files Browse the repository at this point in the history
  • Loading branch information
snaildarter committed Mar 31, 2024
1 parent df3829c commit b29721f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
42 changes: 32 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { HealthRes, AuthRes, EntryPointRes, StrategyRes, UserOp, TryPayUserOpRes } from '@/types/response'
import { HealthRes, AuthRes, EntryPointRes, StrategyRes, UserOpReq, TryPayUserOpRes } from '@/types/response'
import Path from "@utils/path";

/**
Expand All @@ -8,15 +8,24 @@ import Path from "@utils/path";
* @param isProdUrl is production url
*/
export function init(isProdUrl = true) {
axios.defaults.baseURL = isProdUrl ? "https://EthPaymaster.org" : "https://dev.EthPaymaster.org";
axios.defaults.baseURL = isProdUrl ? "https://EthPaymaster.org" : "https://relay-ethpaymaster-pr-20.onrender.com";
axios.interceptors.response.use(function (response) {
// return data value
if (response?.data?.token && response?.data?.expire) {
axios.defaults.headers.common['Authorization'] = 'Bearer ' + response?.data?.token;
}
return response?.data || response;
}, function (error) {
return Promise.reject(error);
});
}

/**
*
* @returns server is health or not
*/
export const health = (): Promise<HealthRes | any> => {
return axios.get(Path.Health)
return axios.get(Path.Health)
}

/**
Expand All @@ -25,20 +34,33 @@ export const health = (): Promise<HealthRes | any> => {
* @returns
*/
export const auth = (apiKey: string): Promise<AuthRes | any> => {
return axios.post(Path.Auth, { apiKey: apiKey });
return axios.post(Path.Auth, { data: { apiKey: apiKey } });
}


export const getSupportEntryPointV1 = (network = "Network"): Promise<EntryPointRes | any> => {
return axios.get(Path.GetSupportEntryPointV1, { params: { network } })
return axios.get(Path.GetSupportEntryPointV1, { params: { network } })
}

export const getSupportStrategyV1 = (network = 'ethereum'): Promise<StrategyRes | any> => {
return axios.get(Path.GetSupportStrategyV1, { params: { network } })
return axios.get(Path.GetSupportStrategyV1, { params: { network } })
}

export const tryPayUserOperationV1 = (userOp: UserOp): Promise<TryPayUserOpRes | any> => {
return axios.post(Path.TryPayUserOperationV1, {
data: userOp
})
export const tryPayUserOperationV1 = (data: UserOpReq): Promise<TryPayUserOpRes | any> => {
return axios.post(Path.TryPayUserOperationV1, {
data: {
force_strategy_id: data.forceStrategyId,
user_operation: {
call_data: data.userOperation.callData,
call_gas_limit: data.userOperation.callGasLimit,
max_priority_fee_per_gas: data.userOperation.maxPriorityFeePerGas,
nonce: data.userOperation.nonce,
pre_verification_gas: data.userOperation.preVerificationGas,
sender: data.userOperation.sender,
signature: data.userOperation.signature,
verification_gas_limit: data.userOperation.verificationGasLimit,
paymaster_and_data: data.userOperation.paymasterAndData
}
}
})
}
17 changes: 15 additions & 2 deletions src/types/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ export interface TryPayUserOpRes extends BaseRes {
}


export interface UserOp {
sender: string;
export interface UserOpReq {
forceStrategyId: string;
userOperation: {
callData: string;
callGasLimit: string;
initCode: string;
maxFeePerGas: string;
maxPriorityFeePerGas: string;
nonce: string;
preVerificationGas: string;
sender: string;
signature: string;
verificationGasLimit: string;
paymasterAndData: string;
}
}

0 comments on commit b29721f

Please sign in to comment.