Skip to content

Commit

Permalink
fix: only display on TxEvent.PROPOSED event
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Aug 30, 2023
1 parent 7bd3f29 commit 092040e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
25 changes: 11 additions & 14 deletions src/hooks/Beamer/useBeamerNps.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useEffect } from 'react'

import { txSubscribe } from '@/services/tx/txEvents'
import { TxEvent, txSubscribe } from '@/services/tx/txEvents'
import { useAppSelector } from '@/store'
import { selectCookies, CookieType } from '@/store/cookiesSlice'
import { shouldShowBeamerNps } from '@/services/beamer'
import { successEvents } from '@/hooks/useTxNotifications'

export const useBeamerNps = (): void => {
const cookies = useAppSelector(selectCookies)
Expand All @@ -15,20 +14,18 @@ export const useBeamerNps = (): void => {
return
}

const unsubFns = successEvents.map((event) => {
return txSubscribe(event, () => {
// Cannot check at the top of effect as Beamer may not have loaded yet
if (shouldShowBeamerNps()) {
// We "force" the NPS banner as we have it globally disabled in Beamer to prevent it
// randomly showing on pages that we don't want it to
// Note: this is not documented but confirmed by Beamer support
window.Beamer?.forceShowNPS()
}
const unsubscribe = txSubscribe(TxEvent.PROPOSED, () => {
// Cannot check at the top of effect as Beamer may not have loaded yet
if (shouldShowBeamerNps()) {
// We "force" the NPS banner as we have it globally disabled in Beamer to prevent it
// randomly showing on pages that we don't want it to
// Note: this is not documented but confirmed by Beamer support
window.Beamer?.forceShowNPS()
}

unsubFns.forEach((unsub) => unsub())
})
unsubscribe()
})

return unsubFns.forEach((unsub) => unsub())
return unsubscribe
}, [isBeamerEnabled])
}
7 changes: 1 addition & 6 deletions src/hooks/useTxNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ enum Variant {
ERROR = 'error',
}

export const successEvents = [
TxEvent.PROPOSED,
TxEvent.SIGNATURE_PROPOSED,
TxEvent.ONCHAIN_SIGNATURE_SUCCESS,
TxEvent.SUCCESS,
]
const successEvents = [TxEvent.PROPOSED, TxEvent.SIGNATURE_PROPOSED, TxEvent.ONCHAIN_SIGNATURE_SUCCESS, TxEvent.SUCCESS]

export const getTxLink = (
txId: string,
Expand Down

0 comments on commit 092040e

Please sign in to comment.