wagmi
Version:
React Hooks for Ethereum
128 lines • 3.02 kB
JavaScript
import { Actions } from '@wagmi/core/tempo';
import { useConfig } from '../../hooks/useConfig.js';
import { useMutation } from '../../utils/query.js';
/**
* Hook for transferring a TIP-20 token. By default, submits the transfer
* without showing an editable UI. Pass `editable: true` to open the
* wallet's send UI with optional pre-filled fields.
*
* @example
* ```tsx
* import { Hooks } from 'wagmi/tempo'
*
* function App() {
* const { mutate, isPending } = Hooks.wallet.useTransfer()
*
* return (
* <button
* onClick={() =>
* mutate({
* amount: '1.5',
* to: '0x...',
* token: 'pathUSD',
* })
* }
* disabled={isPending}
* >
* Transfer
* </button>
* )
* }
* ```
*
* @param parameters - Parameters.
* @returns Mutation result.
*/
export function useTransfer(parameters = {}) {
const { mutation } = parameters;
const config = useConfig(parameters);
return useMutation({
...mutation,
async mutationFn(variables) {
return Actions.wallet.transfer(config, variables);
},
mutationKey: ['wallet', 'transfer'],
});
}
/**
* Hook for opening the wallet swap flow with optional pre-filled swap fields.
*
* @example
* ```tsx
* import { Hooks } from 'wagmi/tempo'
*
* function App() {
* const { mutate, isPending } = Hooks.wallet.useSwap()
*
* return (
* <button
* onClick={() =>
* mutate({
* amount: '1.5',
* token: '0x...',
* type: 'sell',
* })
* }
* disabled={isPending}
* >
* Swap
* </button>
* )
* }
* ```
*
* @param parameters - Parameters.
* @returns Mutation result.
*/
export function useSwap(parameters = {}) {
const { mutation } = parameters;
const config = useConfig(parameters);
return useMutation({
...mutation,
async mutationFn(variables) {
return Actions.wallet.swap(config, variables);
},
mutationKey: ['wallet', 'swap'],
});
}
/**
* Hook for opening the wallet deposit flow with optional pre-filled deposit fields.
*
* @example
* ```tsx
* import { Hooks } from 'wagmi/tempo'
*
* function App() {
* const { mutate, isPending } = Hooks.wallet.useDeposit()
*
* return (
* <button
* onClick={() =>
* mutate({
* token: '0x...',
* value: '1.5',
* })
* }
* disabled={isPending}
* >
* Deposit
* </button>
* )
* }
* ```
*
* @param parameters - Parameters.
* @returns Mutation result.
*/
export function useDeposit(parameters = {}) {
const { mutation } = parameters;
const config = useConfig(parameters);
return useMutation({
...mutation,
async mutationFn(variables) {
return Actions.wallet.deposit(config, variables);
},
mutationKey: ['wallet', 'deposit'],
});
}
//# sourceMappingURL=wallet.js.map