Skip to content

Commit

Permalink
chore: code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ignaciosantise committed Jan 15, 2025
1 parent 8e26686 commit f4a4344
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 81 deletions.
97 changes: 21 additions & 76 deletions packages/core/src/controllers/BlockchainApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ import { ConstantsUtil } from '../utils/ConstantsUtil';
// -- Helpers ------------------------------------------- //
const baseUrl = CoreHelperUtil.getBlockchainApiUrl();

const getHeaders = () => {
const { sdkType, sdkVersion } = OptionsController.state;

return {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
};
};

// -- Types --------------------------------------------- //
export interface BlockchainApiControllerState {
clientId: string | null;
Expand All @@ -47,18 +57,12 @@ export const BlockchainApiController = {
state,

fetchIdentity({ address }: BlockchainApiIdentityRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiIdentityResponse>({
path: `/v1/identity/${address}`,
params: {
projectId: OptionsController.state.projectId
},
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
}
headers: getHeaders()
});
},

Expand All @@ -70,15 +74,9 @@ export const BlockchainApiController = {
signal,
cache
}: BlockchainApiTransactionsRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiTransactionsResponse>({
path: `/v1/account/${account}/history`,
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
params: {
projectId,
cursor,
Expand All @@ -90,51 +88,33 @@ export const BlockchainApiController = {
},

fetchTokenPrice({ projectId, addresses }: BlockchainApiTokenPriceRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.post<BlockchainApiTokenPriceResponse>({
path: '/v1/fungible/price',
body: {
projectId,
currency: 'usd',
addresses
},
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
}
headers: getHeaders()
});
},

fetchSwapAllowance({ projectId, tokenAddress, userAddress }: BlockchainApiSwapAllowanceRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiSwapAllowanceResponse>({
path: `/v1/convert/allowance`,
params: {
projectId,
tokenAddress,
userAddress
},
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
}
headers: getHeaders()
});
},

fetchGasPrice({ projectId, chainId }: BlockchainApiGasPriceRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiGasPriceResponse>({
path: `/v1/convert/gas-price`,
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
params: {
projectId,
chainId
Expand All @@ -150,15 +130,9 @@ export const BlockchainApiController = {
to,
gasPrice
}: BlockchainApiSwapQuoteRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiSwapQuoteResponse>({
path: `/v1/convert/quotes`,
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
params: {
projectId,
amount,
Expand All @@ -171,15 +145,9 @@ export const BlockchainApiController = {
},

fetchSwapTokens({ projectId, chainId }: BlockchainApiSwapTokensRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiSwapTokensResponse>({
path: `/v1/convert/tokens`,
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
params: {
projectId,
chainId
Expand All @@ -194,15 +162,9 @@ export const BlockchainApiController = {
to,
userAddress
}: BlockchainApiGenerateSwapCalldataRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.post<BlockchainApiGenerateSwapCalldataResponse>({
path: '/v1/convert/build-transaction',
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
body: {
amount,
eip155: {
Expand All @@ -222,15 +184,9 @@ export const BlockchainApiController = {
to,
userAddress
}: BlockchainApiGenerateApproveCalldataRequest) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiGenerateApproveCalldataResponse>({
path: `/v1/convert/build-approve`,
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
params: {
projectId,
userAddress,
Expand All @@ -241,14 +197,9 @@ export const BlockchainApiController = {
},

async getBalance(address: string, chainId?: string, forceUpdate?: string) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiBalanceResponse>({
path: `/v1/account/${address}/balance`,
headers: {
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
params: {
currency: 'usd',
projectId: OptionsController.state.projectId,
Expand All @@ -259,15 +210,9 @@ export const BlockchainApiController = {
},

async lookupEnsName(name: string) {
const { sdkType, sdkVersion } = OptionsController.state;

return state.api.get<BlockchainApiLookupEnsName>({
path: `/v1/profile/account/${name}`,
headers: {
'Content-Type': 'application/json',
'x-sdk-type': sdkType,
'x-sdk-version': sdkVersion
},
headers: getHeaders(),
params: {
projectId: OptionsController.state.projectId,
apiVersion: '2'
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/utils/ConnectionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const ConnectionUtil = {
type: 'track',
event: 'DISCONNECT_SUCCESS'
});
throw new Error('ERROR PA');
} catch (error) {
EventsController.sendEvent({
type: 'track',
Expand Down
4 changes: 0 additions & 4 deletions packages/scaffold/src/views/w3m-swap-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ export function SwapView() {
});

const getActionButtonState = () => {
// if (fetchError) {
// return 'Swap'
// }

if (!SwapController.state.sourceToken || !SwapController.state.toToken) {
return { text: 'Select token', disabled: true };
}
Expand Down

0 comments on commit f4a4344

Please sign in to comment.