Skip to content

Commit

Permalink
feat: include tx info in OnTxSuccess (#441)
Browse files Browse the repository at this point in the history
* feat: include tx info in OnTxSuccess

* fix: move type def to .d.ts
  • Loading branch information
just-toby authored Feb 1, 2023
1 parent e65f52e commit 4feae82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hooks/transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function useIsPendingApproval(token?: Token): boolean {
}

export type OnTxSubmit = (hash: string, tx: Transaction) => void
export type OnTxSuccess = (hash: string, receipt: TransactionReceipt) => void
export type OnTxSuccess = (hash: string, tx: WithRequired<Transaction, 'receipt'>) => void
export type OnTxFail = (hash: string, receipt: TransactionReceipt) => void

export interface TransactionEventHandlers {
Expand Down Expand Up @@ -102,10 +102,13 @@ export function TransactionsUpdater({ onTxSubmit, onTxSuccess, onTxFail }: Trans
if (receipt.status === 0) {
onTxFail?.(hash, receipt)
} else {
onTxSuccess?.(hash, receipt)
onTxSuccess?.(hash, {
...currentPendingTxs[hash],
receipt,
})
}
},
[updateTxs, onTxFail, onTxSuccess]
[updateTxs, onTxFail, onTxSuccess, currentPendingTxs]
)

const oldPendingTxs = useRef({})
Expand Down
2 changes: 2 additions & 0 deletions src/widgets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ declare module '*.svg' {
const src: string
export default src
}

type WithRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>

1 comment on commit 4feae82

@vercel
Copy link

@vercel vercel bot commented on 4feae82 Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

widgets – ./

widgets-seven-tau.vercel.app
widgets-uniswap.vercel.app
widgets-git-main-uniswap.vercel.app

Please sign in to comment.