From 74e7c7e6a9e10441e22794f449bc977ffaf0c980 Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Wed, 6 Sep 2023 12:13:29 +0200 Subject: [PATCH] MP-3362: added Toaster explorer link (#430) --- src/components/Toaster.tsx | 25 ++++++++++++++++--- .../Trade/TradeModule/SwapForm/index.tsx | 3 ++- src/constants/explorer.ts | 6 +++++ src/store/slices/broadcast.ts | 11 +++++--- src/types/interfaces/store/broadcast.d.ts | 4 +-- 5 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/constants/explorer.ts diff --git a/src/components/Toaster.tsx b/src/components/Toaster.tsx index 24c80324..fa983469 100644 --- a/src/components/Toaster.tsx +++ b/src/components/Toaster.tsx @@ -2,13 +2,16 @@ import classNames from 'classnames' import { toast as createToast, Slide, ToastContainer } from 'react-toastify' import { mutate } from 'swr' -import { CheckCircled, Cross, CrossCircled } from 'components/Icons' +import { CheckCircled, Cross, CrossCircled, ExternalLink } from 'components/Icons' import Text from 'components/Text' import { DEFAULT_SETTINGS } from 'constants/defaultSettings' +import { EXPLORER_NAME, EXPLORER_TX_URL } from 'constants/explorer' import { REDUCE_MOTION_KEY } from 'constants/localStore' import useLocalStorage from 'hooks/useLocalStorage' import useStore from 'store' +import { TextLink } from './TextLink' + export default function Toaster() { const [reduceMotion] = useLocalStorage(REDUCE_MOTION_KEY, DEFAULT_SETTINGS.reduceMotion) const toast = useStore((s) => s.toast) @@ -23,9 +26,9 @@ export default function Toaster() { isError ? 'bg-error-bg/20' : 'bg-success-bg/20', )} > -
+
- + {isError ? : }
@@ -42,6 +45,20 @@ export default function Toaster() { {toast.message} + {toast.hash && ( + + {`View on ${EXPLORER_NAME}`} + + + )}
@@ -69,7 +86,7 @@ export default function Toaster() { transition={reduceMotion ? undefined : Slide} className='p-0' toastClassName='top-[73px] z-20 m-0 mb-4 flex w-full bg-transparent p-0' - bodyClassName='p-0 m-0 w-full flex' + bodyClassName='p-0 m-0 w-full flex -z-1' /> ) } diff --git a/src/components/Trade/TradeModule/SwapForm/index.tsx b/src/components/Trade/TradeModule/SwapForm/index.tsx index e90861c6..8a6e8f76 100644 --- a/src/components/Trade/TradeModule/SwapForm/index.tsx +++ b/src/components/Trade/TradeModule/SwapForm/index.tsx @@ -172,6 +172,7 @@ export default function SwapForm(props: Props) { isMax: sellAssetAmount.isEqualTo(maxSellAmount), }) }, [ + removedLends, account?.id, buyAsset.denom, sellSideMarginThreshold, @@ -306,4 +307,4 @@ export default function SwapForm(props: Props) {
) -} \ No newline at end of file +} diff --git a/src/constants/explorer.ts b/src/constants/explorer.ts new file mode 100644 index 00000000..ff1674e8 --- /dev/null +++ b/src/constants/explorer.ts @@ -0,0 +1,6 @@ +import { IS_TESTNET } from 'constants/env' + +export const EXPLORER_NAME = 'Mintscan' +export const EXPLORER_TX_URL = IS_TESTNET + ? 'https://testnet.mintscan.io/osmosis-testnet/txs/' + : 'https://www.mintscan.io/osmosis/transactions/' diff --git a/src/store/slices/broadcast.ts b/src/store/slices/broadcast.ts index 3e0e7a31..8d4d98c4 100644 --- a/src/store/slices/broadcast.ts +++ b/src/store/slices/broadcast.ts @@ -20,7 +20,6 @@ import { formatAmountWithSymbol } from 'utils/formatters' import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse' import { BN } from 'utils/helpers' - function generateExecutionMessage( sender: string | undefined = '', contract: string, @@ -48,6 +47,7 @@ export default function createBroadcastSlice( set({ toast: { message: successMessage, + hash: response.result.hash, }, }) } else { @@ -56,6 +56,7 @@ export default function createBroadcastSlice( toast: { message: errorMessage ?? `Transaction failed: ${error}`, isError: true, + hash: response.result.hash, }, }) } @@ -136,13 +137,17 @@ export default function createBroadcastSlice( if (response.result) { set({ createAccountModal: false }) const id = getSingleValueFromBroadcastResult(response.result, 'wasm', 'token_id') - set({ fundAccountModal: true, toast: { message: `Credit Account ${id} created` } }) + set({ + fundAccountModal: true, + toast: { message: `Credit Account ${id} created`, hash: response.result.hash }, + }) return id } else { set({ createAccountModal: false, toast: { message: response.error ?? `Transaction failed: ${response.error}`, + hash: response.result.hash, isError: true, }, }) @@ -529,4 +534,4 @@ export default function createBroadcastSlice( } }, } -} \ No newline at end of file +} diff --git a/src/types/interfaces/store/broadcast.d.ts b/src/types/interfaces/store/broadcast.d.ts index 07fce14b..0654c42d 100644 --- a/src/types/interfaces/store/broadcast.d.ts +++ b/src/types/interfaces/store/broadcast.d.ts @@ -40,7 +40,7 @@ interface BroadcastSlice { slippage: number isMax?: boolean }) => ExecutableTx - toast: { message: string; isError?: boolean; title?: string } | null + toast: { message: string; isError?: boolean; title?: string; hash?: string } | null unlock: (options: { accountId: string vault: DepositedVault @@ -53,4 +53,4 @@ interface BroadcastSlice { borrow: BNCoin[] reclaims: ActionCoin[] }) => Promise -} \ No newline at end of file +}