Skip to content

Commit

Permalink
refactor: replace convert word to swap (#2182)
Browse files Browse the repository at this point in the history
Co-authored-by: Sven <[email protected]>
  • Loading branch information
enesozturk and svenvoskamp authored Apr 30, 2024
1 parent 4c9aa55 commit 9be77e2
Show file tree
Hide file tree
Showing 34 changed files with 763 additions and 785 deletions.
7 changes: 2 additions & 5 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ export type { EventsControllerState } from './src/controllers/EventsController.j
export { TransactionsController } from './src/controllers/TransactionsController.js'
export type { TransactionsControllerState } from './src/controllers/TransactionsController.js'

export { ConvertController } from './src/controllers/ConvertController.js'
export type {
ConvertControllerState,
ConvertInputTarget
} from './src/controllers/ConvertController.js'
export { SwapController } from './src/controllers/SwapController.js'
export type { SwapControllerState, SwapInputTarget } from './src/controllers/SwapController.js'

export { SendController } from './src/controllers/SendController.js'
export type { SendControllerState } from './src/controllers/SendController.js'
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/controllers/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { CaipAddress, ConnectedWalletInfo } from '../utils/TypeUtil.js'
import type { Balance } from '@web3modal/common'
import { BlockchainApiController } from './BlockchainApiController.js'
import { SnackController } from './SnackController.js'
import { ConvertController } from './ConvertController.js'
import { ConvertApiUtil } from '../utils/ConvertApiUtil.js'
import { SwapController } from './SwapController.js'
import { SwapApiUtil } from '../utils/SwapApiUtil.js'
import type { W3mFrameTypes } from '@web3modal/wallet'

// -- Types --------------------------------------------- //
Expand Down Expand Up @@ -105,7 +105,7 @@ export const AccountController = {
const response = await BlockchainApiController.getBalance(state.address)

this.setTokenBalance(response.balances)
ConvertController.setBalances(ConvertApiUtil.mapBalancesToConvertTokens(response.balances))
SwapController.setBalances(SwapApiUtil.mapBalancesToSwapTokens(response.balances))
}
} catch (error) {
SnackController.showError('Failed to fetch token balance')
Expand Down
30 changes: 13 additions & 17 deletions packages/core/src/controllers/BlockchainApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { FetchUtil } from '../utils/FetchUtil.js'
import type {
BlockchainApiTransactionsRequest,
BlockchainApiTransactionsResponse,
BlockchainApiConvertTokensRequest,
BlockchainApiConvertTokensResponse,
BlockchainApiGenerateConvertCalldataRequest,
BlockchainApiGenerateConvertCalldataResponse,
BlockchainApiSwapTokensRequest,
BlockchainApiSwapTokensResponse,
BlockchainApiGenerateSwapCalldataRequest,
BlockchainApiGenerateSwapCalldataResponse,
BlockchainApiGenerateApproveCalldataRequest,
BlockchainApiGenerateApproveCalldataResponse,
BlockchainApiConvertAllowanceRequest,
BlockchainApiConvertAllowanceResponse,
BlockchainApiSwapAllowanceRequest,
BlockchainApiSwapAllowanceResponse,
BlockchainApiGasPriceRequest,
BlockchainApiGasPriceResponse,
BlockchainApiTokenPriceRequest,
Expand Down Expand Up @@ -136,8 +136,8 @@ export const BlockchainApiController = {
})
},

fetchConvertTokens({ projectId, chainId }: BlockchainApiConvertTokensRequest) {
return api.get<BlockchainApiConvertTokensResponse>({
fetchSwapTokens({ projectId, chainId }: BlockchainApiSwapTokensRequest) {
return api.get<BlockchainApiSwapTokensResponse>({
path: `/v1/convert/tokens?projectId=${projectId}&chainId=${chainId}`
})
},
Expand All @@ -156,14 +156,10 @@ export const BlockchainApiController = {
})
},

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

return api.get<BlockchainApiConvertAllowanceResponse>({
return api.get<BlockchainApiSwapAllowanceResponse>({
path: `/v1/convert/allowance?projectId=${projectId}&tokenAddress=${tokenAddress}&userAddress=${userAddress}`,
headers: {
'Content-Type': 'application/json',
Expand All @@ -186,14 +182,14 @@ export const BlockchainApiController = {
})
},

generateConvertCalldata({
generateSwapCalldata({
amount,
from,
projectId,
to,
userAddress
}: BlockchainApiGenerateConvertCalldataRequest) {
return api.post<BlockchainApiGenerateConvertCalldataResponse>({
}: BlockchainApiGenerateSwapCalldataRequest) {
return api.post<BlockchainApiGenerateSwapCalldataResponse>({
path: '/v1/convert/build-transaction',
headers: {
'Content-Type': 'application/json'
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/controllers/RouterController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { subscribeKey as subKey } from 'valtio/vanilla/utils'
import { proxy } from 'valtio/vanilla'
import type { CaipNetwork, Connector, WcWallet } from '../utils/TypeUtil.js'
import type { ConvertInputTarget } from './ConvertController.js'
import type { SwapInputTarget } from './SwapController.js'

// -- Types --------------------------------------------- //
type TransactionAction = {
Expand Down Expand Up @@ -47,17 +47,17 @@ export interface RouterControllerState {
| 'WhatIsANetwork'
| 'WhatIsAWallet'
| 'WhatIsABuy'
| 'Convert'
| 'ConvertSelectToken'
| 'ConvertPreview'
| 'Swap'
| 'SwapSelectToken'
| 'SwapPreview'
history: RouterControllerState['view'][]
data?: {
connector?: Connector
wallet?: WcWallet
network?: CaipNetwork
email?: string
newEmail?: string
target?: ConvertInputTarget
target?: SwapInputTarget
}
transactionStack: TransactionAction[]
}
Expand Down
Loading

0 comments on commit 9be77e2

Please sign in to comment.