Skip to content

Commit

Permalink
Refetch hdfc account on component render
Browse files Browse the repository at this point in the history
  • Loading branch information
asoong committed Dec 6, 2023
1 parent b0c11ad commit 7f6b06b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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<React.SetStateAction<PaymentPlatformType>>;
}
PaymentPlatform: typeof PaymentPlatform;
paymentPlatforms: PaymentPlatformType[];
};

const PlatformSettingsContext = createContext<PlatformSettingsValues>({});
const defaultValues: PlatformSettingsValues = {
paymentPlatforms: paymentPlatforms,
PaymentPlatform

};

const PlatformSettingsContext = createContext<PlatformSettingsValues>(defaultValues);

export default PlatformSettingsContext;
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -38,7 +38,9 @@ const PlatformSettingsProvider = ({ children }: ProvidersProps) => {
<PlatformSettingsContext.Provider
value={{
paymentPlatform,
setPaymentPlatform
setPaymentPlatform,
PaymentPlatform,
paymentPlatforms
}}
>
{children}
Expand Down
16 changes: 13 additions & 3 deletions client/src/contexts/venmo/Registration/RegistrationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion client/src/helpers/deployed_addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const contractAddresses: Contracts = {
"fusdc": '0x5fbdb2315678afecb367f032d93f642f64180aa3',
"sendProcessor": '0x0165878a594ca255338adfa4d48449f69242eb8f',
"registrationProcessor": '0x5fc8d32690cc91d4c39d9d3abcbd16989f875707',
"proofOfP2pNft": '0x0b306bf915c4d645ff596e518faf3f9669b97016',
"proofOfP2pNft": '0xa85233c63b9ee964add6f2cffe00fd84eb32338f',
"hdfcRamp": '0x9A676e781A523b5d0C0e43731313A708CB607508',
"hdfcSendProcessor": '0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE',
"hdfcRegistrationProcessor": '0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1',
Expand Down
39 changes: 32 additions & 7 deletions client/src/pages/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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
Expand Down

0 comments on commit 7f6b06b

Please sign in to comment.