11import { TransferStepDetails } from '@avalabs/fusion-sdk'
2+ import { isAvalancheChainId } from 'services/network/utils/isAvalancheNetwork'
3+ import { getChainIdFromCaip2 } from 'utils/caip2ChainIds'
24import { RequestContext } from 'store/rpc/types'
35import { buildRequestContext } from './buildRequestContext'
46
7+ jest . mock ( 'services/network/utils/isAvalancheNetwork' , ( ) => ( {
8+ isAvalancheChainId : jest . fn ( )
9+ } ) )
10+ jest . mock ( 'utils/caip2ChainIds' , ( ) => ( {
11+ getChainIdFromCaip2 : jest . fn ( )
12+ } ) )
13+
14+ const mockIsAvalancheChainId = isAvalancheChainId as jest . Mock
15+ const mockGetChainIdFromCaip2 = getChainIdFromCaip2 as jest . Mock
16+
517const AVAX_CHAIN_ID = 'eip155:43114'
618const BTC_CHAIN_ID = 'bip122:000000000019d6689c085ae165831e93'
19+ const SOLANA_CHAIN_ID = 'solana:mainnet'
720
821function makeStepDetails (
922 overrides : Partial <
@@ -16,8 +29,8 @@ function makeStepDetails(
1629 const {
1730 currentSignature = 1 ,
1831 requiredSignatures = 1 ,
19- sourceChainId = AVAX_CHAIN_ID ,
20- targetChainId = AVAX_CHAIN_ID
32+ sourceChainId = SOLANA_CHAIN_ID ,
33+ targetChainId = SOLANA_CHAIN_ID
2134 } = overrides
2235
2336 return {
@@ -32,26 +45,33 @@ function makeStepDetails(
3245}
3346
3447describe ( 'buildRequestContext' , ( ) => {
35- describe ( `${ RequestContext . TOASTS_AND_CONFETTI_DISABLED } ` , ( ) => {
36- it ( 'is false for a single-step same-chain swap' , ( ) => {
48+ beforeEach ( ( ) => {
49+ // Default: Solana — getChainIdFromCaip2 returns undefined for non-EVM chains,
50+ // so isAvalancheChainId is never reached (short-circuit in the implementation)
51+ mockGetChainIdFromCaip2 . mockReturnValue ( undefined )
52+ mockIsAvalancheChainId . mockReset ( )
53+ } )
54+
55+ describe ( `${ RequestContext . SUPPRESS_TX_FEEDBACK } ` , ( ) => {
56+ it ( 'is absent for a single-step same-chain swap' , ( ) => {
3757 const ctx = buildRequestContext (
3858 makeStepDetails ( { currentSignature : 1 , requiredSignatures : 1 } )
3959 )
40- expect ( ctx [ RequestContext . TOASTS_AND_CONFETTI_DISABLED ] ) . toBe ( false )
60+ expect ( ctx [ RequestContext . SUPPRESS_TX_FEEDBACK ] ) . toBeUndefined ( )
4161 } )
4262
4363 it ( 'is true for an intermediate step (currentSignature < requiredSignatures)' , ( ) => {
4464 const ctx = buildRequestContext (
4565 makeStepDetails ( { currentSignature : 1 , requiredSignatures : 2 } )
4666 )
47- expect ( ctx [ RequestContext . TOASTS_AND_CONFETTI_DISABLED ] ) . toBe ( true )
67+ expect ( ctx [ RequestContext . SUPPRESS_TX_FEEDBACK ] ) . toBe ( true )
4868 } )
4969
50- it ( 'is false for the final step of a multi-step same-chain swap' , ( ) => {
70+ it ( 'is absent for the final step of a multi-step same-chain swap' , ( ) => {
5171 const ctx = buildRequestContext (
5272 makeStepDetails ( { currentSignature : 2 , requiredSignatures : 2 } )
5373 )
54- expect ( ctx [ RequestContext . TOASTS_AND_CONFETTI_DISABLED ] ) . toBe ( false )
74+ expect ( ctx [ RequestContext . SUPPRESS_TX_FEEDBACK ] ) . toBeUndefined ( )
5575 } )
5676
5777 it ( 'is true for a cross-chain swap (final step)' , ( ) => {
@@ -63,7 +83,7 @@ describe('buildRequestContext', () => {
6383 targetChainId : BTC_CHAIN_ID
6484 } )
6585 )
66- expect ( ctx [ RequestContext . TOASTS_AND_CONFETTI_DISABLED ] ) . toBe ( true )
86+ expect ( ctx [ RequestContext . SUPPRESS_TX_FEEDBACK ] ) . toBe ( true )
6787 } )
6888
6989 it ( 'is true for a cross-chain intermediate step' , ( ) => {
@@ -75,7 +95,118 @@ describe('buildRequestContext', () => {
7595 targetChainId : BTC_CHAIN_ID
7696 } )
7797 )
78- expect ( ctx [ RequestContext . TOASTS_AND_CONFETTI_DISABLED ] ) . toBe ( true )
98+ expect ( ctx [ RequestContext . SUPPRESS_TX_FEEDBACK ] ) . toBe ( true )
99+ } )
100+ } )
101+
102+ describe ( `${ RequestContext . IMMEDIATE_SENT_TOAST } ` , ( ) => {
103+ it ( 'is true for a non-Avalanche same-chain final step' , ( ) => {
104+ const ctx = buildRequestContext ( makeStepDetails ( ) )
105+ expect ( ctx [ RequestContext . IMMEDIATE_SENT_TOAST ] ) . toBe ( true )
106+ } )
107+
108+ it ( 'is absent for an Avalanche same-chain final step (ApprovalController handles it)' , ( ) => {
109+ mockGetChainIdFromCaip2 . mockReturnValue ( 43114 )
110+ mockIsAvalancheChainId . mockReturnValue ( true )
111+
112+ const ctx = buildRequestContext (
113+ makeStepDetails ( {
114+ sourceChainId : AVAX_CHAIN_ID ,
115+ targetChainId : AVAX_CHAIN_ID
116+ } )
117+ )
118+ expect ( ctx [ RequestContext . IMMEDIATE_SENT_TOAST ] ) . toBeUndefined ( )
119+ } )
120+
121+ it ( 'is absent for a cross-chain swap (SUPPRESS_TX_FEEDBACK handles it)' , ( ) => {
122+ const ctx = buildRequestContext (
123+ makeStepDetails ( {
124+ sourceChainId : AVAX_CHAIN_ID ,
125+ targetChainId : BTC_CHAIN_ID
126+ } )
127+ )
128+ expect ( ctx [ RequestContext . IMMEDIATE_SENT_TOAST ] ) . toBeUndefined ( )
129+ } )
130+
131+ it ( 'is absent for an intermediate step (SUPPRESS_TX_FEEDBACK handles it)' , ( ) => {
132+ const ctx = buildRequestContext (
133+ makeStepDetails ( { currentSignature : 1 , requiredSignatures : 2 } )
134+ )
135+ expect ( ctx [ RequestContext . IMMEDIATE_SENT_TOAST ] ) . toBeUndefined ( )
136+ } )
137+ } )
138+
139+ describe ( `${ RequestContext . CONFETTI_DISABLED } ` , ( ) => {
140+ it ( 'is true for a non-Avalanche same-chain final step' , ( ) => {
141+ const ctx = buildRequestContext ( makeStepDetails ( ) )
142+ expect ( ctx [ RequestContext . CONFETTI_DISABLED ] ) . toBe ( true )
143+ } )
144+
145+ it ( 'is absent for an Avalanche same-chain final step (confetti fires in onTransactionPending)' , ( ) => {
146+ mockGetChainIdFromCaip2 . mockReturnValue ( 43114 )
147+ mockIsAvalancheChainId . mockReturnValue ( true )
148+
149+ const ctx = buildRequestContext (
150+ makeStepDetails ( {
151+ sourceChainId : AVAX_CHAIN_ID ,
152+ targetChainId : AVAX_CHAIN_ID
153+ } )
154+ )
155+ expect ( ctx [ RequestContext . CONFETTI_DISABLED ] ) . toBeUndefined ( )
156+ } )
157+
158+ it ( 'is absent for a cross-chain swap (SUPPRESS_TX_FEEDBACK handles it)' , ( ) => {
159+ const ctx = buildRequestContext (
160+ makeStepDetails ( {
161+ sourceChainId : AVAX_CHAIN_ID ,
162+ targetChainId : BTC_CHAIN_ID
163+ } )
164+ )
165+ expect ( ctx [ RequestContext . CONFETTI_DISABLED ] ) . toBeUndefined ( )
166+ } )
167+
168+ it ( 'is absent for an intermediate step (SUPPRESS_TX_FEEDBACK handles it)' , ( ) => {
169+ const ctx = buildRequestContext (
170+ makeStepDetails ( { currentSignature : 1 , requiredSignatures : 2 } )
171+ )
172+ expect ( ctx [ RequestContext . CONFETTI_DISABLED ] ) . toBeUndefined ( )
173+ } )
174+ } )
175+
176+ describe ( `${ RequestContext . SUCCESS_TOAST_DISABLED } ` , ( ) => {
177+ it ( 'is true for a non-Avalanche same-chain final step' , ( ) => {
178+ const ctx = buildRequestContext ( makeStepDetails ( ) )
179+ expect ( ctx [ RequestContext . SUCCESS_TOAST_DISABLED ] ) . toBe ( true )
180+ } )
181+
182+ it ( 'is absent for an Avalanche same-chain final step (ApprovalController handles it)' , ( ) => {
183+ mockGetChainIdFromCaip2 . mockReturnValue ( 43114 )
184+ mockIsAvalancheChainId . mockReturnValue ( true )
185+
186+ const ctx = buildRequestContext (
187+ makeStepDetails ( {
188+ sourceChainId : AVAX_CHAIN_ID ,
189+ targetChainId : AVAX_CHAIN_ID
190+ } )
191+ )
192+ expect ( ctx [ RequestContext . SUCCESS_TOAST_DISABLED ] ) . toBeUndefined ( )
193+ } )
194+
195+ it ( 'is absent for a cross-chain swap (SUPPRESS_TX_FEEDBACK handles it)' , ( ) => {
196+ const ctx = buildRequestContext (
197+ makeStepDetails ( {
198+ sourceChainId : AVAX_CHAIN_ID ,
199+ targetChainId : BTC_CHAIN_ID
200+ } )
201+ )
202+ expect ( ctx [ RequestContext . SUCCESS_TOAST_DISABLED ] ) . toBeUndefined ( )
203+ } )
204+
205+ it ( 'is absent for an intermediate step (SUPPRESS_TX_FEEDBACK handles it)' , ( ) => {
206+ const ctx = buildRequestContext (
207+ makeStepDetails ( { currentSignature : 1 , requiredSignatures : 2 } )
208+ )
209+ expect ( ctx [ RequestContext . SUCCESS_TOAST_DISABLED ] ) . toBeUndefined ( )
79210 } )
80211 } )
81212} )
0 commit comments