From 8c437191b01ff2383b0f0ce21c0411f1fca26564 Mon Sep 17 00:00:00 2001 From: plondon Date: Thu, 2 Mar 2023 14:19:02 -0500 Subject: [PATCH 1/7] fix(steps): add min step --- jest/__mocks__/gqlMocks.ts | 1 + src/preview.tsx | 5 ++-- src/providers/Store/index.tsx | 3 ++ src/steps/EnterAmount/index.tsx | 8 +---- .../PaymentMethod/PaymentMethod.test.tsx | 30 +++++++++++++++++++ src/steps/index.tsx | 6 ++-- 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/jest/__mocks__/gqlMocks.ts b/jest/__mocks__/gqlMocks.ts index ed7299a3..f8aa50cc 100644 --- a/jest/__mocks__/gqlMocks.ts +++ b/jest/__mocks__/gqlMocks.ts @@ -21,6 +21,7 @@ export const mocks: MockedResponse[] = [ getAssetsForOrgMock({ currency: 'USD', limit: 10, offset: 0 }), getAssetsForOrgMock({ currency: 'USD', limit: 10, offset: 0 }), getAssetsForOrgMock({ assetId: 'satoshi123' }), + getAssetsForOrgMock({ assetId: 'elon123' }), getAssetsForOrgMock({ address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', }), diff --git a/src/preview.tsx b/src/preview.tsx index c19535df..e6fbf6a8 100644 --- a/src/preview.tsx +++ b/src/preview.tsx @@ -20,8 +20,9 @@ root.render( }, }, selection: { - assetId: '6b562c23-d79f-4a34-a47f-cc7b28726821', - paymentMethod: 'binance-pay', + amount: '10000', + assetId: '53adbb94-6a68-4eeb-af49-6b6d9e84a1f4', + fiat: 'USD', }, style: { theme: 'dark', diff --git a/src/providers/Store/index.tsx b/src/providers/Store/index.tsx index 49f6bbc2..1bfa457b 100644 --- a/src/providers/Store/index.tsx +++ b/src/providers/Store/index.tsx @@ -66,6 +66,7 @@ type State = { fiat?: string; fiatDisplaySymbol?: string; method?: PaymentMethod & { description?: string }; + minStep: number; network?: Network; prebuiltTx: { data?: { @@ -219,6 +220,7 @@ const initialState: State = { destinationNetwork: undefined, fiat: undefined, method: undefined, + minStep: Steps.AssetSelection, network: undefined, prebuiltTx: { data: undefined, @@ -572,6 +574,7 @@ export const Store: React.FC< embed, fiat, fiatDisplaySymbol, + minStep: step, network, requiredAmount, requiredPaymentMethod, diff --git a/src/steps/EnterAmount/index.tsx b/src/steps/EnterAmount/index.tsx index 4a857865..303c04cb 100644 --- a/src/steps/EnterAmount/index.tsx +++ b/src/steps/EnterAmount/index.tsx @@ -2,13 +2,7 @@ import { Badge } from '@map3xyz/components'; import { ethers } from 'ethers'; import { AnimatePresence, motion } from 'framer-motion'; import React, { useContext, useEffect, useRef, useState } from 'react'; -import { - isChrome, - isEdge, - isFirefox, - isMobile, - isOpera, -} from 'react-device-detect'; +import { isChrome, isEdge, isFirefox, isOpera } from 'react-device-detect'; import { useTranslation } from 'react-i18next'; import ErrorWrapper from '../../components/ErrorWrapper'; diff --git a/src/steps/PaymentMethod/PaymentMethod.test.tsx b/src/steps/PaymentMethod/PaymentMethod.test.tsx index 5081d222..b23246e5 100644 --- a/src/steps/PaymentMethod/PaymentMethod.test.tsx +++ b/src/steps/PaymentMethod/PaymentMethod.test.tsx @@ -82,6 +82,36 @@ describe('Payment Selection', () => { }); }); +describe('Payment Selection', () => { + beforeEach(() => { + render( + {}} + /> + ); + }); + const testingUtils = generateTestingUtils({ providerType: 'MetaMask' }); + beforeAll(() => { + global.window.ethereum = testingUtils.getProvider(); + global.window.ethereum.providers = [testingUtils.getProvider()]; + }); + afterEach(() => { + testingUtils.clearAllMocks(); + }); + it('doesnt allow the user to go back beyond min step', async () => { + const back = await screen.findByLabelText('Back'); + expect(back).toHaveClass('invisible'); + }); +}); + describe('Payment Method Errors', () => { it('renders', () => { render(); diff --git a/src/steps/index.tsx b/src/steps/index.tsx index 3bc9a134..cc533fdc 100644 --- a/src/steps/index.tsx +++ b/src/steps/index.tsx @@ -29,7 +29,7 @@ export const ANIMATION_VARIANTS = { const Map3SdkSteps: React.FC = ({ onClose, plan }) => { const [state, dispatch] = useContext(Context); - const { step, steps } = state; + const { minStep, step, steps } = state; useChainWatcher(); @@ -51,7 +51,9 @@ const Map3SdkSteps: React.FC = ({ onClose, plan }) => {