-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12adb20
commit 2819215
Showing
4 changed files
with
148 additions
and
4 deletions.
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
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,70 @@ | ||
import { useMemo } from 'react'; | ||
import type { ReactNode } from 'react'; | ||
import { useChainId } from 'wagmi'; | ||
import { useShowCallsStatus } from 'wagmi/experimental'; | ||
import { getChainExplorer } from '../../network/getChainExplorer'; | ||
import { cn, color, text } from '../../styles/theme'; | ||
import { useTransactionContext } from '../components/TransactionProvider'; | ||
|
||
export function useGetTransactionStatusAction() { | ||
const { | ||
chainId, | ||
errorMessage, | ||
onSubmit, | ||
receipt, | ||
transactionHash, | ||
transactionId, | ||
} = useTransactionContext(); | ||
const accountChainId = chainId ?? useChainId(); | ||
|
||
const { showCallsStatus } = useShowCallsStatus(); | ||
|
||
return useMemo(() => { | ||
const chainExplorer = getChainExplorer(accountChainId); | ||
|
||
let actionElement: ReactNode = null; | ||
|
||
// EOA will have txn hash | ||
if (transactionHash) { | ||
actionElement = ( | ||
<a | ||
href={`${chainExplorer}/tx/${transactionHash}`} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
<span className={cn(text.label1, color.primary)}> | ||
View transaction | ||
</span> | ||
</a> | ||
); | ||
} | ||
|
||
// SW will have txn id | ||
if (transactionId) { | ||
actionElement = ( | ||
<button | ||
onClick={() => showCallsStatus({ id: transactionId })} | ||
type="button" | ||
> | ||
<span className={cn(text.label1, color.primary)}> | ||
View transaction | ||
</span> | ||
</button> | ||
); | ||
} | ||
|
||
if (receipt) { | ||
actionElement = null; | ||
} | ||
|
||
return { actionElement }; | ||
}, [ | ||
accountChainId, | ||
errorMessage, | ||
onSubmit, | ||
receipt, | ||
showCallsStatus, | ||
transactionHash, | ||
transactionId, | ||
]); | ||
} |
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,74 @@ | ||
import { useMemo } from 'react'; | ||
import type { ReactNode } from 'react'; | ||
import { useChainId } from 'wagmi'; | ||
import { useShowCallsStatus } from 'wagmi/experimental'; | ||
import { getChainExplorer } from '../../network/getChainExplorer'; | ||
import { cn, color, text } from '../../styles/theme'; | ||
import { useTransactionContext } from '../components/TransactionProvider'; | ||
|
||
export function useGetTransactionToastAction() { | ||
const { | ||
chainId, | ||
errorMessage, | ||
onSubmit, | ||
receipt, | ||
transactionHash, | ||
transactionId, | ||
} = useTransactionContext(); | ||
const accountChainId = chainId ?? useChainId(); | ||
|
||
const { showCallsStatus } = useShowCallsStatus(); | ||
|
||
return useMemo(() => { | ||
const chainExplorer = getChainExplorer(accountChainId); | ||
|
||
let actionElement: ReactNode = null; | ||
|
||
// EOA will have txn hash | ||
if (transactionHash) { | ||
actionElement = ( | ||
<a | ||
href={`${chainExplorer}/tx/${transactionHash}`} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
<span className={cn(text.label1, color.primary)}> | ||
View transaction | ||
</span> | ||
</a> | ||
); | ||
} | ||
|
||
// SW will have txn id | ||
if (transactionId) { | ||
actionElement = ( | ||
<button | ||
onClick={() => showCallsStatus({ id: transactionId })} | ||
type="button" | ||
> | ||
<span className={cn(text.label1, color.primary)}> | ||
View transaction | ||
</span> | ||
</button> | ||
); | ||
} | ||
|
||
if (errorMessage) { | ||
actionElement = ( | ||
<button type="button" onClick={onSubmit}> | ||
<span className={cn(text.label1, color.primary)}>Try again</span> | ||
</button> | ||
); | ||
} | ||
|
||
return { actionElement }; | ||
}, [ | ||
accountChainId, | ||
errorMessage, | ||
onSubmit, | ||
receipt, | ||
showCallsStatus, | ||
transactionHash, | ||
transactionId, | ||
]); | ||
} |