dex.usePlaceFlip
Places a flip order that automatically flips to the opposite side when filled.
Usage
ts
import { } from 'wagmi/tempo'
import { } from 'viem'
import { } from 'viem/tempo'
const = ..()
// Call `mutate` in response to user action (e.g. button click, form submission)
.({
: ('100', 6),
: .('1.01'),
: .('0.99'),
: '0x20c0000000000000000000000000000000000001',
: 'buy',
})
.('Flip order ID:', .?.)
Flip order ID: 456nts
import { createConfig, http } from 'wagmi'
import { tempoTestnet } from 'wagmi/chains'
import { KeyManager, webAuthn } from 'wagmi/tempo'
export const config = createConfig({
connectors: [
webAuthn({
keyManager: KeyManager.localStorage(),
}),
],
chains: [tempoTestnet],
multiInjectedProviderDiscovery: false,
transports: {
[tempoTestnet.id]: http(),
},
})Asynchronous Usage
The example above uses a *Sync variant of the action, that will wait for the transaction to be included before returning.
If you are optimizing for performance, you should use the non-sync dex.placeFlip action and wait for inclusion manually:
ts
import { Hooks } from 'wagmi/tempo'
import { Actions } from 'viem/tempo'
import { parseUnits } from 'viem'
import { Tick } from 'viem/tempo'
import { useWaitForTransactionReceipt } from 'wagmi'
const placeFlip = Hooks.dex.usePlaceFlip()
const { data: receipt } = useWaitForTransactionReceipt({ hash: placeFlip.data })
// Call `mutate` in response to user action (e.g. button click, form submission)
placeFlip.mutate({
amount: parseUnits('100', 6),
flipTick: Tick.fromPrice('1.01'),
tick: Tick.fromPrice('0.99'),
token: '0x20c0000000000000000000000000000000000001',
type: 'buy',
})
if (receipt) {
const { args: { orderId } }
= Actions.dex.placeFlip.extractEvent(receipt.logs)Return Type
See TanStack Query mutation docs for more info hook return types.
data
See Wagmi Action dex.placeFlip Return Type
mutate/mutateAsync
See Wagmi Action dex.placeFlip Parameters
Parameters
config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
mutation
See the TanStack Query mutation docs for more info hook parameters.