Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
state/fee/hooks: create hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
W3stside committed Dec 9, 2020
1 parent 3753a9a commit 6ca3873
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/custom/state/fee/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useDispatch, useSelector } from 'react-redux'

import { AppDispatch, AppState } from 'state'
import { updateFee, clearFee } from './actions'
import { FeeInformationState, FeeInformation } from './reducer'

interface AddFeeParams extends ClearFeeParams {
fee: FeeInformation
}
interface ClearFeeParams {
token: string // token address
}

type AddFeeCallback = (addTokenParams: AddFeeParams) => void
type ClearFeeCallback = (clearTokenParams: ClearFeeParams) => void

export const useFee = (tokenAddress?: string): FeeInformation | undefined => {
const { feesMap } = useSelector<AppState, FeeInformationState>(state => state.fee)

return tokenAddress ? feesMap[tokenAddress]?.fee : undefined
}

export const useAddTip = (): AddFeeCallback => {
const dispatch = useDispatch<AppDispatch>()
return (addTokenParams: AddFeeParams) => dispatch(updateFee(addTokenParams))
}

export const useClearTip = (): ClearFeeCallback => {
const dispatch = useDispatch<AppDispatch>()
return (clearTokenParams: ClearFeeParams) => dispatch(clearFee(clearTokenParams))
}

0 comments on commit 6ca3873

Please sign in to comment.