Skip to content

Commit

Permalink
chore: run lint:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CumpsD committed Nov 21, 2024
1 parent e1eb1de commit b770ae0
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const chainflipApi: SwapperApi = {

const depositAddress = swapResponse.address!
step.chainflipSwapId = swapResponse.id!

const { assetReference } = fromAssetId(step.sellAsset.assetId)

const adapter = assertGetEvmChainAdapter(step.sellAsset.chainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ export const _getTradeQuote = async (
allowanceContract: '0x0', // Chainflip does not use contracts
estimatedExecutionTimeMs:
(singleQuoteResponse.boostQuote.estimatedDurationsSeconds!.deposit! +
singleQuoteResponse.boostQuote.estimatedDurationsSeconds!.swap!) * 1000,
chainflipNumberOfChunks: isStreaming
? singleQuoteResponse.boostQuote.numberOfChunks ?? undefined
singleQuoteResponse.boostQuote.estimatedDurationsSeconds!.swap!) *
1000,
chainflipNumberOfChunks: isStreaming
? singleQuoteResponse.boostQuote.numberOfChunks ?? undefined
: undefined,
chainflipChunkIntervalBlocks: isStreaming
? singleQuoteResponse.boostQuote.chunkIntervalBlocks ?? undefined
Expand Down Expand Up @@ -333,13 +334,14 @@ export const _getTradeQuote = async (
allowanceContract: '0x0', // Chainflip does not use contracts - all Txs are sends
estimatedExecutionTimeMs:
(singleQuoteResponse.estimatedDurationsSeconds!.deposit! +
singleQuoteResponse.estimatedDurationsSeconds!.swap!) * 1000,
chainflipNumberOfChunks: isStreaming
? singleQuoteResponse.numberOfChunks ?? undefined
singleQuoteResponse.estimatedDurationsSeconds!.swap!) *
1000,
chainflipNumberOfChunks: isStreaming
? singleQuoteResponse.numberOfChunks ?? undefined
: undefined,
chainflipChunkIntervalBlocks: isStreaming
? singleQuoteResponse.chunkIntervalBlocks ?? undefined
: undefined
: undefined,
},
],
}
Expand Down
4 changes: 2 additions & 2 deletions packages/swapper/src/swappers/ChainflipSwapper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { ChainflipBaasStatusSwap } from './models/ChainflipBaasStatusSwap'
export type ChainFlipStatus = {
status: {
state: 'waiting' | 'receiving' | 'swapping' | 'sending' | 'sent' | 'completed' | 'failed'
swap?: ChainflipBaasStatusSwap,
swapEgress?: ChainflipBaasStatusEgress,
swap?: ChainflipBaasStatusSwap
swapEgress?: ChainflipBaasStatusEgress
}
}

Expand Down
11 changes: 5 additions & 6 deletions packages/swapper/src/swappers/ChainflipSwapper/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ export const getChainFlipSwap = ({
refundAddress,
retryDurationInBlocks = 10,
commissionBps,
numberOfChunks = undefined,
chunkIntervalBlocks = 2
numberOfChunks = undefined,
chunkIntervalBlocks = 2,
}: GetChainFlipSwapArgs): Promise<
Result<AxiosResponse<ChainflipBaasSwapDepositAddress, any>, SwapErrorRight>
> => {
let swapUrl =
let swapUrl =
`${brokerUrl}/swap` +
`?apiKey=${apiKey}` +
`&sourceAsset=${sourceAsset}` +
Expand All @@ -117,9 +117,8 @@ export const getChainFlipSwap = ({
`&commissionBps=${commissionBps}`

if (numberOfChunks) {
swapUrl +=
`&numberOfChunks=${numberOfChunks}` +
`&chunkIntervalBlocks=${chunkIntervalBlocks}`
swapUrl += `&numberOfChunks=${numberOfChunks}`
swapUrl += `&chunkIntervalBlocks=${chunkIntervalBlocks}`
}

return chainflipService.get<ChainflipBaasSwapDepositAddress>(swapUrl)
Expand Down
6 changes: 3 additions & 3 deletions packages/swapper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ export type TradeQuoteStep = {
value: string
gasLimit: string
}
cowswapQuoteResponse?: CowSwapQuoteResponse,
chainflipSwapId?: number | undefined,
chainflipNumberOfChunks?: number | undefined,
cowswapQuoteResponse?: CowSwapQuoteResponse
chainflipSwapId?: number | undefined
chainflipNumberOfChunks?: number | undefined
chainflipChunkIntervalBlocks?: number | undefined
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import type {
TradeQuoteStep,
} from '@shapeshiftoss/swapper'
import { SwapperName } from '@shapeshiftoss/swapper'
import {
CHAINFLIP_DCA_BOOST_SWAP_SOURCE,
CHAINFLIP_DCA_SWAP_SOURCE,
} from '@shapeshiftoss/swapper/dist/swappers/ChainflipSwapper/constants'
import {
THORCHAIN_LONGTAIL_STREAMING_SWAP_SOURCE,
THORCHAIN_STREAM_SWAP_SOURCE,
} from '@shapeshiftoss/swapper/dist/swappers/ThorchainSwapper/constants'
import {
CHAINFLIP_DCA_SWAP_SOURCE,
CHAINFLIP_DCA_BOOST_SWAP_SOURCE,
} from '@shapeshiftoss/swapper/dist/swappers/ChainflipSwapper/constants'
import type { KnownChainIds } from '@shapeshiftoss/types'
import { useCallback, useMemo } from 'react'
import { useTranslate } from 'react-polyglot'
Expand All @@ -32,15 +32,14 @@ import { TransactionExecutionState } from 'state/slices/tradeQuoteSlice/types'
import { useAppSelector } from 'state/store'

import { SwapperIcon } from '../../TradeInput/components/SwapperIcon/SwapperIcon'
import { useChainflipStreamingProgress } from '../hooks/useChainflipStreamingProgress'
import { useThorStreamingProgress } from '../hooks/useThorStreamingProgress'
import { useTradeExecution } from '../hooks/useTradeExecution'
import { getChainShortName } from '../utils/getChainShortName'
import { StatusIcon } from './StatusIcon'
import { StepperStep } from './StepperStep'
import { StreamingSwap } from './StreamingSwap'

import { useThorStreamingProgress } from '../hooks/useThorStreamingProgress'
import { useChainflipStreamingProgress } from '../hooks/useChainflipStreamingProgress'

export type HopTransactionStepProps = {
swapperName: SwapperName
tradeQuoteStep: TradeQuoteStep
Expand Down Expand Up @@ -186,36 +185,37 @@ export const HopTransactionStep = ({
THORCHAIN_STREAM_SWAP_SOURCE,
THORCHAIN_LONGTAIL_STREAMING_SWAP_SOURCE,
CHAINFLIP_DCA_SWAP_SOURCE,
CHAINFLIP_DCA_BOOST_SWAP_SOURCE
CHAINFLIP_DCA_BOOST_SWAP_SOURCE,
].includes(tradeQuoteStep.source)

if (sellTxHash !== undefined && isStreamingSwap) {
const isThor = tradeQuoteStep.source == THORCHAIN_STREAM_SWAP_SOURCE || tradeQuoteStep.source == THORCHAIN_LONGTAIL_STREAMING_SWAP_SOURCE
const streamingProgress = isThor
? useThorStreamingProgress
: useChainflipStreamingProgress
const isThor =
tradeQuoteStep.source === THORCHAIN_STREAM_SWAP_SOURCE ||
tradeQuoteStep.source === THORCHAIN_LONGTAIL_STREAMING_SWAP_SOURCE
const streamingProgress = isThor ? useThorStreamingProgress : useChainflipStreamingProgress

return (
<Card width='full'>
<CardBody px={2} py={2}>
<StreamingSwap
tradeQuoteStep={tradeQuoteStep}
hopIndex={hopIndex}
activeTradeId={activeTradeId}
streamingProgress={streamingProgress} />
<StreamingSwap
tradeQuoteStep={tradeQuoteStep}
hopIndex={hopIndex}
activeTradeId={activeTradeId}
streamingProgress={streamingProgress}
/>
</CardBody>
</Card>
)
}
}, [
isActive,
swapTxState,
tradeQuoteStep.source,
sellTxHash,
handleSignTx,
isFetching,
tradeQuoteQueryData,
translate,
tradeQuoteStep,
hopIndex,
activeTradeId,
])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { WarningIcon } from '@chakra-ui/icons'
import { Progress, Stack } from '@chakra-ui/react'
import type {
TradeQuote,
TradeQuoteStep
} from '@shapeshiftoss/swapper'
import type { TradeQuote, TradeQuoteStep } from '@shapeshiftoss/swapper'
import { useMemo } from 'react'
import { useTranslate } from 'react-polyglot'
import { Row } from 'components/Row/Row'
import type { StreamingSwapFailedSwap } from 'state/slices/tradeQuoteSlice/types'

export type StreamingSwapProps = {
tradeQuoteStep: TradeQuoteStep,
tradeQuoteStep: TradeQuoteStep
hopIndex: number
activeTradeId: TradeQuote['id'],
activeTradeId: TradeQuote['id']
streamingProgress: (
tradeQuoteStep: TradeQuoteStep,
hopIndex: number,
confirmedTradeId: TradeQuote['id']
confirmedTradeId: TradeQuote['id'],
) => {
isComplete: boolean
attemptedSwapCount: number
Expand All @@ -33,7 +30,7 @@ export const StreamingSwap = (props: StreamingSwapProps) => {
const { totalSwapCount, attemptedSwapCount, isComplete, failedSwaps } = streamingProgress(
tradeQuoteStep,
hopIndex,
activeTradeId
activeTradeId,
)

const isInitializing = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export type ThornodeStreamingSwapResponse =
| ThornodeStreamingSwapResponseError

export type ChainflipStreamingSwapResponseSuccess = {
executedChunks: number,
executedChunks: number
remainingChunks: number
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
TradeQuote,
TradeQuoteStep
} from '@shapeshiftoss/swapper'
import type { TradeQuote, TradeQuoteStep } from '@shapeshiftoss/swapper'
// TODO: Is this import allowed?
import type { ChainFlipStatus } from '@shapeshiftoss/swapper/dist/swappers/ChainflipSwapper/types'
import axios from 'axios'
import { getConfig } from 'config'
import { useEffect, useMemo } from 'react'
Expand All @@ -14,12 +13,7 @@ import type {
} from 'state/slices/tradeQuoteSlice/types'
import { useAppDispatch, useAppSelector } from 'state/store'

import {
ChainflipStreamingSwapResponseSuccess
} from './types'

// TODO: Is this import allowed?
import type { ChainFlipStatus } from "@shapeshiftoss/swapper/dist/swappers/ChainflipSwapper/types";
import type { ChainflipStreamingSwapResponseSuccess } from './types'

const POLL_INTERVAL_MILLISECONDS = 30_000 // 30 seconds

Expand All @@ -32,34 +26,35 @@ const DEFAULT_STREAMING_SWAP_METADATA: StreamingSwapMetadata = {
const getChainflipStreamingSwap = async (
swapId: number | undefined,
): Promise<ChainflipStreamingSwapResponseSuccess | undefined> => {
console.log('getChainflipStreamingSwap.swapId', swapId);
if (!swapId) return;
console.log('getChainflipStreamingSwap.swapId', swapId)

if (!swapId) return

const config = getConfig()
const brokerUrl = config.REACT_APP_CHAINFLIP_API_URL
const apiKey = config.REACT_APP_CHAINFLIP_API_KEY

const { data: statusResponse } = await axios.get<ChainFlipStatus>(
`${brokerUrl}/status-by-id?apiKey=${apiKey}&swapId=${swapId}`)

`${brokerUrl}/status-by-id?apiKey=${apiKey}&swapId=${swapId}`,
)

console.log('getChainflipStreamingSwap.statusResponse', statusResponse)

if (!statusResponse) return

// TODO: Check for real errors
if ('error' in statusResponse) {
console.error('failed to fetch streaming swap data', statusResponse.error)
return
}

const dcaStatus = statusResponse.status?.swap?.dca
if (!dcaStatus) return;

if (!dcaStatus) return

return {
executedChunks: dcaStatus!.executedChunks!,
remainingChunks: dcaStatus!.remainingChunks!
remainingChunks: dcaStatus!.remainingChunks!,
}
}

Expand All @@ -70,7 +65,7 @@ const getStreamingSwapMetadata = (
const failedSwaps: StreamingSwapFailedSwap[] = []

return {
totalSwapCount: (data.executedChunks + data.remainingChunks) ?? 0,
totalSwapCount: data.executedChunks + data.remainingChunks ?? 0,
attemptedSwapCount: data.executedChunks ?? 0,
failedSwaps,
}
Expand All @@ -94,17 +89,17 @@ export const useChainflipStreamingProgress = (
hopIndex,
}
}, [confirmedTradeId, hopIndex])

const {
swap: { sellTxHash, streamingSwap: streamingSwapMeta },
} = useAppSelector(state => selectHopExecutionMetadata(state, hopExecutionMetadataFilter))

const bla = useAppSelector(state => selectHopExecutionMetadata(state, hopExecutionMetadataFilter));
console.log('useChainflipStreamingProgress.useAppSelector', bla);
const bla = useAppSelector(state => selectHopExecutionMetadata(state, hopExecutionMetadataFilter))
console.log('useChainflipStreamingProgress.useAppSelector', bla)

const swapId = tradeQuoteStep.chainflipSwapId
console.log('useChainflipStreamingProgress.chainflipSwapId', swapId);
console.log('useChainflipStreamingProgress.chainflipSwapId', swapId)

useEffect(() => {
// don't start polling until we have a tx
if (!sellTxHash) return
Expand Down Expand Up @@ -136,8 +131,8 @@ export const useChainflipStreamingProgress = (

// stop polling on dismount
return cancelPolling
}, [cancelPolling, dispatch, hopIndex, poll, sellTxHash, confirmedTradeId])
}, [cancelPolling, dispatch, hopIndex, poll, sellTxHash, confirmedTradeId, swapId])

const result = useMemo(() => {
const numSuccessfulSwaps =
(streamingSwapMeta?.attemptedSwapCount ?? 0) - (streamingSwapMeta?.failedSwaps?.length ?? 0)
Expand All @@ -152,4 +147,4 @@ export const useChainflipStreamingProgress = (
}, [streamingSwapMeta])

return result
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import type {
TradeQuote,
TradeQuoteStep
} from '@shapeshiftoss/swapper'
import type { TradeQuote, TradeQuoteStep } from '@shapeshiftoss/swapper'
import axios from 'axios'
import { getConfig } from 'config'
import { useEffect, useMemo, useRef } from 'react'
Expand Down

0 comments on commit b770ae0

Please sign in to comment.