Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: swap successful redirect #11247

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/common/Notification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const props = withDefaults(
action?: MaybeRef<NotificationAction | undefined>
holdTimer?: Ref<boolean>
icon?: Ref<NeoMessageIconVariant | undefined>
footer?: Ref<Omit<NotificationAction, 'url'> | undefined>
footer?: NotificationFooter
}>(),
{
variant: 'success',
Expand Down
13 changes: 8 additions & 5 deletions components/swap/review.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@

<script setup lang="ts">
import { NeoIcon, NeoButton } from '@kodadot1/brick'
import { SwapStep } from '@/components/swap/types'
import { successMessage } from '@/utils/notification'

const router = useRouter()
const { $i18n } = useNuxtApp()
const { transaction, isLoading, status, blockNumber } = useTransaction()
const { transaction, isLoading, status, blockNumber } = useTransaction({ disableSuccessNotification: true })
const { urlPrefix } = usePrefix()
const { accountId } = useAuth()
const swapStore = useAtomicSwapStore()
const { swap } = storeToRefs(swapStore)

Expand All @@ -134,14 +135,16 @@ const submit = () => {
duration: swap.value.duration,
surcharge: swap.value.surcharge,
urlPrefix: urlPrefix.value,
successMessage: $i18n.t('swap.created'),
})
}

watchEffect(async () => {
watch([status, blockNumber], () => {
if (status.value === TransactionStatus.Finalized && blockNumber.value) {
successMessage($i18n.t('swap.created'), {
footer: { icon: 'circle-info', label: $i18n.t('general.updateOnWebsiteSoon') },
})
swapStore.updateSwap({ blockNumber: blockNumber.value })
await navigateTo({ name: getSwapStepRouteName(SwapStep.COUNTERPARTY) })
navigateTo(`/${urlPrefix.value}/u/${accountId.value}?tab=swaps&filter=outgoing`)
}
})
</script>
7 changes: 5 additions & 2 deletions utils/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import MessageNotify from '@/components/MessageNotify.vue'

export type NotificationAction = { label: string, url: string, icon?: string }

export type NotificationFooter = MaybeRef<Omit<NotificationAction, 'url'> | undefined>

type Params = {
variant: NeoMessageVariant
duration?: number
Expand Down Expand Up @@ -50,7 +52,7 @@ export const showNotification = ({
action?: MaybeRef<NotificationAction | undefined>
holdTimer?: Ref<boolean>
icon?: Ref<NeoMessageIconVariant | undefined>
footer?: Ref<Omit<NotificationAction, 'url'> | undefined>
footer?: NotificationFooter
}) => {
if (params === notificationTypes.danger) {
consola.error('[Notification Error]', message)
Expand Down Expand Up @@ -120,11 +122,12 @@ export const infoMessage = (
})
}

export const successMessage = message =>
export const successMessage = (message: string, extraConfig?: { footer?: NotificationFooter }) =>
showNotification({
title: 'Success',
message: message,
params: notificationTypes.success,
...extraConfig,
})

export const getReportIssueAction = (message: string) => {
Expand Down
Loading