diff --git a/client/src/contexts/common/PlatformSettings/PlatformSettingsContext.ts b/client/src/contexts/common/PlatformSettings/PlatformSettingsContext.ts index 8d2396812..47b9240d3 100644 --- a/client/src/contexts/common/PlatformSettings/PlatformSettingsContext.ts +++ b/client/src/contexts/common/PlatformSettings/PlatformSettingsContext.ts @@ -1,13 +1,25 @@ import { createContext } from 'react'; -import { PaymentPlatformType } from './types'; +import { + PaymentPlatformType, + PaymentPlatform, + paymentPlatforms, +} from './types'; interface PlatformSettingsValues { paymentPlatform?: PaymentPlatformType; setPaymentPlatform?: React.Dispatch>; -} + PaymentPlatform: typeof PaymentPlatform; + paymentPlatforms: PaymentPlatformType[]; +}; -const PlatformSettingsContext = createContext({}); +const defaultValues: PlatformSettingsValues = { + paymentPlatforms: paymentPlatforms, + PaymentPlatform + +}; + +const PlatformSettingsContext = createContext(defaultValues); export default PlatformSettingsContext; diff --git a/client/src/contexts/common/PlatformSettings/PlatformSettingsProvider.tsx b/client/src/contexts/common/PlatformSettings/PlatformSettingsProvider.tsx index 118c1780d..2d1ce38d7 100644 --- a/client/src/contexts/common/PlatformSettings/PlatformSettingsProvider.tsx +++ b/client/src/contexts/common/PlatformSettings/PlatformSettingsProvider.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState, ReactNode } from 'react'; -import { PaymentPlatform, PaymentPlatformType } from './types'; +import { PaymentPlatform, PaymentPlatformType, paymentPlatforms } from './types'; import PlatformSettingsContext from './PlatformSettingsContext' @@ -38,7 +38,9 @@ const PlatformSettingsProvider = ({ children }: ProvidersProps) => { {children} diff --git a/client/src/contexts/venmo/Registration/RegistrationProvider.tsx b/client/src/contexts/venmo/Registration/RegistrationProvider.tsx index c8095e973..d1727a71e 100644 --- a/client/src/contexts/venmo/Registration/RegistrationProvider.tsx +++ b/client/src/contexts/venmo/Registration/RegistrationProvider.tsx @@ -142,11 +142,21 @@ const RegistrationProvider = ({ children }: ProvidersProps) => { const rampAccountData = rampAccountRaw as any; const rampAccountProcessed = rampAccountData.venmoIdHash; - setRegistrationHash(rampAccountProcessed); + if (rampAccountProcessed !== ZERO_ADDRESS) { + esl && console.log('rampAccountRaw_3'); - setShouldFetchVenmoNftId(true); + setRegistrationHash(rampAccountProcessed); + + setShouldFetchVenmoNftId(true); + } else { + esl && console.log('rampAccountRaw_4'); + + setRegistrationHash(null); + + setShouldFetchVenmoNftId(false); + } } else { - esl && console.log('rampAccountRaw_3'); + esl && console.log('rampAccountRaw_5'); setRegistrationHash(null); diff --git a/client/src/helpers/deployed_addresses.ts b/client/src/helpers/deployed_addresses.ts index e4bd1ed71..6658d5c2f 100644 --- a/client/src/helpers/deployed_addresses.ts +++ b/client/src/helpers/deployed_addresses.ts @@ -31,7 +31,7 @@ export const contractAddresses: Contracts = { "fusdc": '0x5fbdb2315678afecb367f032d93f642f64180aa3', "sendProcessor": '0x0165878a594ca255338adfa4d48449f69242eb8f', "registrationProcessor": '0x5fc8d32690cc91d4c39d9d3abcbd16989f875707', - "proofOfP2pNft": '0x0b306bf915c4d645ff596e518faf3f9669b97016', + "proofOfP2pNft": '0xa85233c63b9ee964add6f2cffe00fd84eb32338f', "hdfcRamp": '0x9A676e781A523b5d0C0e43731313A708CB607508', "hdfcSendProcessor": '0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE', "hdfcRegistrationProcessor": '0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1', diff --git a/client/src/pages/Registration.tsx b/client/src/pages/Registration.tsx index b882d2634..71af33cd2 100644 --- a/client/src/pages/Registration.tsx +++ b/client/src/pages/Registration.tsx @@ -3,6 +3,8 @@ import styled from "styled-components"; import { RegistrationForm } from "@components/RegistrationForm" import useRegistration from '@hooks/useRegistration'; +import useHdfcRegistration from '@hooks/hdfc/useHdfcRegistration'; +import usePlatformSettings from '@hooks/usePlatformSettings'; export const Registration: React.FC<{}> = (props) => { @@ -11,23 +13,46 @@ export const Registration: React.FC<{}> = (props) => { */ const { - refetchRampAccount, - shouldFetchRegistration, + refetchRampAccount: refetchVenmoAccount, + shouldFetchRegistration: shouldFetchVenmoRegistration, refetchVenmoNftId, shouldFetchVenmoNftId } = useRegistration(); + const { + refetchRampAccount: refetchHdfcAccount, + shouldFetchRegistration: shouldFetchHdfcRegistration, + } = useHdfcRegistration(); + + const { + PaymentPlatform, + paymentPlatform + } = usePlatformSettings(); + /* * Hooks */ useEffect(() => { - if (shouldFetchRegistration) { - refetchRampAccount?.(); - } + switch (paymentPlatform) { + case PaymentPlatform.VENMO: + if (shouldFetchVenmoRegistration) { + refetchVenmoAccount?.(); + } + + if (shouldFetchVenmoNftId) { + refetchVenmoNftId?.(); + } + break; + + case PaymentPlatform.HDFC: + if (shouldFetchHdfcRegistration) { + refetchHdfcAccount?.(); + } + break; - if (shouldFetchVenmoNftId) { - refetchVenmoNftId?.(); + default: + throw new Error(`Unknown payment platform: ${paymentPlatform}`); } // eslint-disable-next-line react-hooks/exhaustive-deps