@@ -41,6 +41,7 @@ import ErrorPopup from "src/Common/ErrorPopup/ErrorPopup";
41
41
import { APIError , handleError , SerializedError } from "@planet-sdk/common" ;
42
42
import { PaymentRequest } from "@stripe/stripe-js/types/stripe-js/payment-request" ;
43
43
import { createProjectDetails } from "src/Utils/createProjectDetails" ;
44
+ import { useDebouncedEffect } from "src/Utils/useDebouncedEffect" ;
44
45
45
46
export const QueryParamContext =
46
47
createContext < QueryParamContextInterface > ( null ) ;
@@ -346,23 +347,27 @@ const QueryParamProvider: FC = ({ children }) => {
346
347
router . query . token ,
347
348
] ) ;
348
349
349
- useEffect ( ( ) => {
350
- const regex = / ^ p c a s h _ / ;
351
- if (
352
- router . query . to &&
353
- ! regex . test ( router . query . to as string ) &&
354
- country !== undefined &&
355
- country !== "" &&
356
- router . query . to ?. toString ( ) . toLowerCase ( ) !== "planetcash"
357
- ) {
358
- const to = String ( router . query . to ) . replace ( / \/ / g, "" ) ;
359
- loadPaymentSetup ( {
360
- projectGUID : to ,
361
- paymentSetupCountry : country ,
362
- shouldSetPaymentDetails : true ,
363
- } ) ;
364
- }
365
- } , [ router . query . to , country ] ) ;
350
+ useDebouncedEffect (
351
+ ( ) => {
352
+ const regex = / ^ p c a s h _ / ;
353
+ if (
354
+ router . query . to &&
355
+ ! regex . test ( router . query . to as string ) &&
356
+ country !== undefined &&
357
+ country !== "" &&
358
+ router . query . to ?. toString ( ) . toLowerCase ( ) !== "planetcash"
359
+ ) {
360
+ const to = String ( router . query . to ) . replace ( / \/ / g, "" ) ;
361
+ loadPaymentSetup ( {
362
+ projectGUID : to ,
363
+ paymentSetupCountry : country ,
364
+ shouldSetPaymentDetails : true ,
365
+ } ) ;
366
+ }
367
+ } ,
368
+ 1000 ,
369
+ [ router . query . to , country , profile ?. slug ]
370
+ ) ;
366
371
367
372
async function loadConfig ( ) {
368
373
try {
@@ -488,11 +493,19 @@ const QueryParamProvider: FC = ({ children }) => {
488
493
paymentSetupCountry : string ;
489
494
shouldSetPaymentDetails ?: boolean ;
490
495
} ) => {
496
+ const token =
497
+ profile === null
498
+ ? null
499
+ : queryToken ||
500
+ ( router . query . token as string ) ||
501
+ ( await getAccessTokenSilently ( ) ) ;
502
+
491
503
setIsPaymentOptionsLoading ( true ) ;
492
504
try {
493
505
const requestParams = {
494
506
url : `/app/paymentOptions/${ projectGUID } ?country=${ paymentSetupCountry } ` ,
495
507
setshowErrorCard,
508
+ token,
496
509
tenant,
497
510
locale : i18n . language ,
498
511
} ;
0 commit comments