-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: chainflip explorer link (#8529)
- Loading branch information
1 parent
8bd7ccf
commit d690560
Showing
5 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import type { Csp } from '../types' | ||
|
||
export const csp: Csp = { | ||
'connect-src': ['https://chainflip-broker.io/'], | ||
'connect-src': [ | ||
'https://explorer-service-processor.chainflip.io/graphql', | ||
'https://chainflip-broker.io/', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { SwapSource } from '@shapeshiftoss/swapper' | ||
import { SwapperName } from '@shapeshiftoss/swapper' | ||
import type { UseQueryResult } from '@tanstack/react-query' | ||
import { skipToken, useQuery } from '@tanstack/react-query' | ||
import axios from 'axios' | ||
|
||
type UseChainflipSwapIdArgs = { | ||
txHash: string | undefined | ||
swapperName: SwapSource | undefined | ||
} | ||
|
||
type SwapIdResponse = { | ||
data: { | ||
txRefs: { | ||
nodes: { | ||
swap: { | ||
nativeId: string | undefined | ||
} | ||
}[] | ||
} | ||
} | ||
} | ||
|
||
const nativeSwapIdQuery = ` | ||
query GetStringSearchResults($searchString: String!) { | ||
txRefs: allTransactionRefs(filter: {ref: {equalTo: $searchString}}) { | ||
nodes { | ||
swap: swapRequestBySwapRequestId { | ||
nativeId | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
export const useChainflipSwapIdQuery = ({ | ||
txHash, | ||
swapperName, | ||
}: UseChainflipSwapIdArgs): UseQueryResult<string | undefined, Error> => { | ||
return useQuery({ | ||
queryKey: ['chainflipSwapId', { txHash }], | ||
queryFn: | ||
txHash && swapperName?.includes(SwapperName.Chainflip) | ||
? () => | ||
// Yes, this is ugly, just another day in "we're doing inline raw GraphQL queries with http" | ||
// Note, this is undocumented but is actually the exact same query fragment CF UI uses to go from Tx hash to swap ID (though only a fragment of it, | ||
// actually stripped out to the bare minimum here vs. cf UI) | ||
axios.post<SwapIdResponse>('https://explorer-service-processor.chainflip.io/graphql', { | ||
query: nativeSwapIdQuery, | ||
variables: { | ||
searchString: txHash, | ||
}, | ||
}) | ||
: skipToken, | ||
select: ({ data: { data } }) => data.txRefs.nodes[0].swap.nativeId, | ||
// Long-poll until swap by initiating Txid is indexed | ||
refetchInterval: 10_000, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters