Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfolch-redeemeum committed Jan 16, 2025
1 parent be5a01c commit 43efd68
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ export type RedeemWhatsNextProps = {
requestShipmentProps:
| Pick<
RequestShipmentModalProps,
| "postDeliveryInfoUrl"
| "deliveryInfoHandler"
| "redemptionSubmittedHandler"
| "redemptionConfirmedHandler"
| "forcedAccount"
| "parentOrigin"
| "signatures"
"forcedAccount" | "parentOrigin" | "signatures"
>
| undefined;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import { getHasBuyerTransferInfos } from "../../../../lib/offer/filter";
import { BuyerTransferInfo } from "../../../../lib/bundle/const";
import { Form, Formik, FormikProps } from "formik";
import { FormModel } from "../Redeem/RedeemFormModel";
import {
RedemptionContextProps,
useRedemptionContext
} from "../../../widgets/redemption/provider/RedemptionContext";
import { useRedemptionContext } from "../../../widgets/redemption/provider/RedemptionContext";
import { mockedDeliveryAddress } from "../../../widgets/redemption/const";
import { checkSignatures } from "../Redeem/checkSignatures";
import Loading from "../../../ui/loading/LoadingWrapper";
Expand All @@ -40,13 +37,7 @@ enum ActiveStep {
REDEEM_FORM_CONFIRMATION,
REDEEM_SUCESS
}
export type RequestShipmentModalProps = Pick<
RedemptionContextProps,
| "postDeliveryInfoUrl"
| "deliveryInfoHandler"
| "redemptionSubmittedHandler"
| "redemptionConfirmedHandler"
> & {
export type RequestShipmentModalProps = {
exchange: subgraph.ExchangeFieldsFragment;
forcedAccount?: string;
parentOrigin?: string | null;
Expand All @@ -57,11 +48,7 @@ export const RequestShipmentModal = ({
exchange,
parentOrigin,
signatures,
forcedAccount,
deliveryInfoHandler,
postDeliveryInfoUrl,
redemptionConfirmedHandler,
redemptionSubmittedHandler
forcedAccount
}: RequestShipmentModalProps) => {
const { offer } = exchange;
const offerId = offer.id;
Expand Down Expand Up @@ -115,7 +102,13 @@ export const RequestShipmentModal = ({
formRef.current.validateForm();
}
}, [step]);
const { deliveryInfo: initialDeliveryInfo } = useRedemptionContext();
const {
deliveryInfo: initialDeliveryInfo,
postDeliveryInfoUrl,
deliveryInfoHandler,
redemptionConfirmedHandler,
redemptionSubmittedHandler
} = useRedemptionContext();
const doFetchSellersFromSellerIds = !!sellerId;
const sellerIds = useMemo(() => [sellerId], [sellerId]);
const {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-kit/src/hooks/connection/connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable react-hooks/rules-of-hooks */
// source: https://wagmi.sh/react/ethers-adapters

import { useMemo } from "react";
import { useUser } from "../../components/magicLink/UserContext";
import {
Expand Down Expand Up @@ -52,6 +49,7 @@ export function useChainId(): number | undefined {
let magicChainId: number | undefined;
let magicError: unknown;
try {
// eslint-disable-next-line react-hooks/rules-of-hooks
magicChainId = useMagicChainId();
} catch (error) {
magicError = error; // error if the provider is not there
Expand Down Expand Up @@ -90,6 +88,7 @@ export function useProvider():
throw error;
}
try {
// eslint-disable-next-line react-hooks/rules-of-hooks
magicProvider = useMagicProvider();
} catch (magicError) {
error = magicError; // error if the provider is not there
Expand All @@ -116,6 +115,7 @@ export function useSigner(): Signer | undefined {
let magicProvider: providers.Web3Provider | undefined, magicError: unknown;

try {
// eslint-disable-next-line react-hooks/rules-of-hooks
magicProvider = useMagicProvider();
} catch (err) {
magicError = err; // error if the provider is not there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "./useLocalStorage";

export type GetItemFromStorageKey =
| "wagmi.store"
| "isChainUnsupported"
| "tracing-url"
| "isConnectWalletFromCommit"
Expand Down
65 changes: 19 additions & 46 deletions packages/react-kit/src/stories/widgets/Redemption.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { ComponentMeta, ComponentStory, Story } from "@storybook/react";
import React, { ReactElement } from "react";
import { Meta } from "@storybook/react";

import {
RedemptionWidget,
Expand All @@ -15,21 +15,18 @@ import { RedemptionWidgetAction } from "../../components/widgets";
export default {
title: "Widgets/Redemption",
component: RedemptionWidget
} as ComponentMeta<typeof RedemptionWidget>;
} as Meta<typeof RedemptionWidget>;

// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Template: ComponentStory<typeof RedemptionWidget> = (args) => (
<RedemptionWidget {...args} />
);
const Template = (args) => <RedemptionWidget {...args} />;

const wrapper = (Story: Story) => (
const wrapper = (Story: () => ReactElement) => (
<div>
<Story />
</div>
);

export const Redemption: ComponentStory<typeof RedemptionWidget> =
Template.bind({});
export const Redemption = Template.bind({});

const envName =
(process.env.STORYBOOK_DATA_ENV_NAME as EnvironmentType) || "testing";
Expand Down Expand Up @@ -77,8 +74,7 @@ Redemption.args = {

Redemption.decorators = [(Story) => wrapper(Story)];

export const RedemptionCallbacks: ComponentStory<typeof RedemptionWidget> =
Template.bind({});
export const RedemptionCallbacks = Template.bind({});

RedemptionCallbacks.args = {
...Redemption.args,
Expand All @@ -94,9 +90,7 @@ RedemptionCallbacks.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionCallbacksThenClose: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionCallbacksThenClose = Template.bind({});

RedemptionCallbacksThenClose.args = {
...Redemption.args,
Expand All @@ -107,9 +101,7 @@ RedemptionCallbacksThenClose.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionCallbacksRedeemConfirm: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionCallbacksRedeemConfirm = Template.bind({});

RedemptionCallbacksRedeemConfirm.args = {
...Redemption.args,
Expand All @@ -126,9 +118,7 @@ RedemptionCallbacksRedeemConfirm.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionCallbacksFailure: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionCallbacksFailure = Template.bind({});

RedemptionCallbacksFailure.args = {
...Redemption.args,
Expand All @@ -139,9 +129,7 @@ RedemptionCallbacksFailure.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionCallbacksFailure2: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionCallbacksFailure2 = Template.bind({});

RedemptionCallbacksFailure2.args = {
...Redemption.args,
Expand All @@ -155,9 +143,7 @@ RedemptionCallbacksFailure2.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionCallbacksFailure3: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionCallbacksFailure3 = Template.bind({});

RedemptionCallbacksFailure3.args = {
...Redemption.args,
Expand All @@ -181,9 +167,7 @@ RedemptionCallbacksFailure3.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionCallbacksFailure4: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionCallbacksFailure4 = Template.bind({});

RedemptionCallbacksFailure4.args = {
...Redemption.args,
Expand All @@ -207,8 +191,7 @@ RedemptionCallbacksFailure4.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionHandlers: ComponentStory<typeof RedemptionWidget> =
Template.bind({});
export const RedemptionHandlers = Template.bind({});

RedemptionHandlers.args = {
...Redemption.args,
Expand Down Expand Up @@ -238,9 +221,7 @@ RedemptionHandlers.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionHandlersNoResume: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionHandlersNoResume = Template.bind({});

RedemptionHandlersNoResume.args = {
...Redemption.args,
Expand All @@ -255,9 +236,7 @@ RedemptionHandlersNoResume.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionHandlersFailure1: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionHandlersFailure1 = Template.bind({});

RedemptionHandlersFailure1.args = {
...Redemption.args,
Expand All @@ -272,9 +251,7 @@ RedemptionHandlersFailure1.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionHandlersFailure2: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionHandlersFailure2 = Template.bind({});

RedemptionHandlersFailure2.args = {
...Redemption.args,
Expand All @@ -285,9 +262,7 @@ RedemptionHandlersFailure2.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionHandlersFailure3: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionHandlersFailure3 = Template.bind({});

RedemptionHandlersFailure3.args = {
...Redemption.args,
Expand All @@ -307,9 +282,7 @@ RedemptionHandlersFailure3.args = {
...BASE_ARGS
} satisfies RedemptionWidgetProps;

export const RedemptionHandlersFailure4: ComponentStory<
typeof RedemptionWidget
> = Template.bind({});
export const RedemptionHandlersFailure4 = Template.bind({});

RedemptionHandlersFailure4.args = {
...Redemption.args,
Expand Down

0 comments on commit 43efd68

Please sign in to comment.