@@ -4,9 +4,11 @@ import mockBasics from '../../../tests/mocks/evm/basics'
44import React from 'react'
55import ReactDOM from 'react-dom'
66import Blockchains from '@depay/web3-blockchains'
7- import { mock , resetMocks } from '@depay/web3-mock'
7+ import { mock , confirm , resetMocks , anything } from '@depay/web3-mock'
88import { getProvider , resetCache } from '@depay/web3-client'
99import Token from '@depay/web3-tokens'
10+ import { ethers } from 'ethers'
11+ import { routers } from '@depay/web3-payments'
1012
1113describe ( 'Payment Widget: errors' , ( ) => {
1214
@@ -208,4 +210,82 @@ describe('Payment Widget: errors', () => {
208210 } )
209211 } )
210212 } )
213+
214+ it ( 'does not render an error dialog if internal error was not critical and can be handled by the widget, if payment was already initialized' , ( ) => {
215+
216+ let errorCalled
217+ let passedError
218+
219+ fetchMock . post ( {
220+ delay : 3000 ,
221+ overwriteRoutes : true ,
222+ url : "https://public.depay.com/routes/all" ,
223+ body : {
224+ accounts : { [ blockchain ] : accounts [ 0 ] } ,
225+ accept,
226+ } ,
227+ } , 500 )
228+
229+ let mockedTransaction = mock ( {
230+ blockchain,
231+ transaction : {
232+ from : fromAddress ,
233+ to : routers [ blockchain ] . address ,
234+ api : routers [ blockchain ] . api ,
235+ method : 'pay' ,
236+ params : {
237+ payment : {
238+ amountIn : ethers . utils . parseUnits ( '20' , 18 ) ,
239+ permit2 : false ,
240+ paymentAmount : "20000000000000000000" ,
241+ feeAmount : 0 ,
242+ tokenInAddress : DEPAY ,
243+ exchangeAddress : Blockchains [ blockchain ] . zero ,
244+ tokenOutAddress : DEPAY ,
245+ paymentReceiverAddress : toAddress ,
246+ feeReceiverAddress : Blockchains [ blockchain ] . zero ,
247+ exchangeType : 0 ,
248+ receiverType : 0 ,
249+ exchangeCallData : anything ,
250+ receiverCallData : Blockchains [ blockchain ] . zero ,
251+ deadline : anything ,
252+ }
253+ } ,
254+ value : 0
255+ }
256+ } )
257+
258+ cy . visit ( 'cypress/test.html' ) . then ( ( contentWindow ) => {
259+ cy . document ( ) . then ( ( document ) => {
260+ DePayWidgets . Payment ( {
261+ document,
262+ accept : [ {
263+ blockchain : 'ethereum' ,
264+ amount : 20 ,
265+ token : '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb' ,
266+ receiver : '0x4e260bB2b25EC6F3A59B478fCDe5eD5B8D783B02'
267+ } ] ,
268+ error : ( error ) => {
269+ errorCalled = true
270+ passedError = error
271+ }
272+ } )
273+ cy . get ( '.ReactShadowDOMOutsideContainer' ) . shadow ( ) . find ( '.Card' ) . contains ( 'Detected' ) . click ( )
274+ cy . wait ( 1000 ) . then ( ( ) => {
275+ cy . get ( '.ReactShadowDOMOutsideContainer' ) . shadow ( ) . find ( '.ButtonPrimary' ) . click ( )
276+ cy . wait ( 3000 ) . then ( ( ) => {
277+ expect ( mockedTransaction . calls . count ( ) ) . to . equal ( 1 )
278+ cy . get ( 'button[title="Close dialog"]' , { includeShadowDom : true } ) . should ( 'not.exist' )
279+ confirm ( mockedTransaction )
280+ cy . get ( '.ReactShadowDOMOutsideContainer' ) . shadow ( ) . find ( '.Card' ) . should ( 'contain.text' , 'Payment performed' ) . then ( ( ) => {
281+ expect ( errorCalled ) . to . eq ( undefined )
282+ expect ( passedError ) . to . eq ( undefined )
283+ cy . get ( '.ReactShadowDOMOutsideContainer' ) . shadow ( ) . contains ( '.ErrorSnippetText' , / A l l r o u t e s c o u l d n o t b e l o a d e d ! / ) . should ( 'not.exist' )
284+ cy . get ( '.ReactShadowDOMOutsideContainer' ) . shadow ( ) . find ( '.ButtonPrimary' ) . click ( )
285+ } )
286+ } )
287+ } )
288+ } )
289+ } )
290+ } )
211291} )
0 commit comments