Skip to content

Commit ca1a947

Browse files
authored
[NO-CHANGELOG] feat: primary revenue widget views - part 3 (#901)
1 parent dd9d383 commit ca1a947

File tree

10 files changed

+397
-19
lines changed

10 files changed

+397
-19
lines changed

packages/checkout/widgets-lib/src/resources/text/textConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ export const text = {
330330
heading: 'Pay with your coins',
331331
caption: 'Using the coins balance in your wallet',
332332
},
333+
button: {
334+
buyNow: 'Buy now',
335+
},
333336
},
334337
[PrimaryRevenueWidgetViews.PAY_WITH_CARD]: {
335338
header: {

packages/checkout/widgets-lib/src/widgets/primary-revenue/PrimaryRevenueWidget.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import { PrimaryRevenueWidgetViews } from '../../context/view-context/PrimaryRev
2121
import { Item } from './types';
2222
import { widgetTheme } from '../../lib/theme';
2323
import { SharedContextProvider } from './context/SharedContextProvider';
24+
import { PaymentMethods } from './views/PaymentMethods';
25+
import { PayWithCard } from './views/PayWithCard';
26+
import { PayWithCoins } from './views/PayWithCoins';
2427

2528
export interface PrimaryRevenueWidgetProps {
2629
config: StrongCheckoutWidgetsConfig;
@@ -36,15 +39,7 @@ export function PrimaryRevenueWidget(props: PrimaryRevenueWidgetProps) {
3639
config, amount, items, fromContractAddress, env, environmentId,
3740
} = props;
3841

39-
console.log(
40-
'@@@ PrimaryRevenueWidget',
41-
config,
42-
amount,
43-
items,
44-
fromContractAddress,
45-
env,
46-
environmentId,
47-
);
42+
console.log('@@@ PrimaryRevenueWidget', config, amount, items, fromContractAddress, env, environmentId);
4843

4944
const { connectLoaderState } = useContext(ConnectLoaderContext);
5045
const { checkout, provider } = connectLoaderState;
@@ -84,6 +79,7 @@ export function PrimaryRevenueWidget(props: PrimaryRevenueWidgetProps) {
8479
<ViewContext.Provider value={viewReducerValues}>
8580
<SharedContextProvider
8681
value={{
82+
config,
8783
items,
8884
amount,
8985
fromContractAddress,
@@ -101,7 +97,13 @@ export function PrimaryRevenueWidget(props: PrimaryRevenueWidgetProps) {
10197
)}
10298
{viewState.view.type
10399
=== PrimaryRevenueWidgetViews.PAYMENT_METHODS && (
104-
<div>Payment methods</div>
100+
<PaymentMethods />
101+
)}
102+
{viewState.view.type === PrimaryRevenueWidgetViews.PAY_WITH_CARD && (
103+
<PayWithCard />
104+
)}
105+
{viewState.view.type === PrimaryRevenueWidgetViews.PAY_WITH_COINS && (
106+
<PayWithCoins />
105107
)}
106108
</SharedContextProvider>
107109
</ViewContext.Provider>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { MenuItem } from '@biom3/react';
2+
import { SignedOrderProduct } from '../types';
3+
4+
export interface OrderItemProps {
5+
item: SignedOrderProduct;
6+
}
7+
8+
const CURRENCY_IMAGE_URL = {
9+
eth: 'https://design-system.immutable.com/hosted-for-ds/currency-icons/currency--eth.svg',
10+
usdc: 'https://design-system.immutable.com/hosted-for-ds/currency-icons/currency--usdc.svg',
11+
};
12+
13+
export function OrderItem(props: OrderItemProps) {
14+
const { item } = props;
15+
const currencyIcon = CURRENCY_IMAGE_URL[item.currency.toLowerCase()] || CURRENCY_IMAGE_URL.eth;
16+
17+
return (
18+
<MenuItem emphasized size="small">
19+
<MenuItem.FramedImage imageUrl={item.image} />
20+
<MenuItem.Label>{item.name}</MenuItem.Label>
21+
<MenuItem.Caption>{item.description}</MenuItem.Caption>
22+
{item.amount && (
23+
<MenuItem.PriceDisplay
24+
fiatAmount={item.amount.toString()}
25+
price={`${item.currency} ${item.amount}`}
26+
currencyImageUrl={currencyIcon}
27+
/>
28+
)}
29+
</MenuItem>
30+
);
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Box } from '@biom3/react';
2+
import { OrderItem } from './OrderItem';
3+
4+
import { SignedOrderProduct } from '../types';
5+
6+
export interface OrderListProps {
7+
items: SignedOrderProduct[] | undefined;
8+
}
9+
10+
export function OrderList(props: OrderListProps) {
11+
const { items } = props;
12+
13+
return (
14+
<Box
15+
testId="order-list"
16+
sx={{
17+
width: '100%',
18+
display: 'flex',
19+
flexDirection: 'column',
20+
justifyContent: 'center',
21+
alignItems: 'flex-start',
22+
}}
23+
>
24+
{items && items.map((item) => (
25+
<OrderItem key={`${item.name}${item.tokenId[0]}`} item={item} />
26+
))}
27+
</Box>
28+
);
29+
}

packages/checkout/widgets-lib/src/widgets/primary-revenue/context/SharedContextProvider.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import { PrimaryRevenueSuccess } from '@imtbl/checkout-widgets';
1212
import { Item, PaymentTypes, SignResponse } from '../types';
1313
import { useSignOrder } from '../hooks/useSignOrder';
1414
import { ConnectLoaderState } from '../../../context/connect-loader-context/ConnectLoaderContext';
15+
import { StrongCheckoutWidgetsConfig } from '../../../lib/withDefaultWidgetConfig';
1516

1617
type SharedContextProps = {
18+
config: StrongCheckoutWidgetsConfig;
1719
env: string;
1820
environmentId: string;
1921
items: Item[];
@@ -24,7 +26,7 @@ type SharedContextProps = {
2426
};
2527

2628
type SharedContextValues = SharedContextProps & {
27-
sign: (paymentType: PaymentTypes) => Promise<SignResponse | undefined>
29+
sign: (paymentType: PaymentTypes) => Promise<SignResponse | undefined>;
2830
execute: () => Promise<PrimaryRevenueSuccess>;
2931
recipientAddress: string;
3032
signResponse: SignResponse | undefined;
@@ -43,6 +45,7 @@ const SharedContext = createContext<SharedContextValues>({
4345
sign: () => Promise.resolve(undefined),
4446
execute: () => Promise.resolve({} as PrimaryRevenueSuccess),
4547
signResponse: undefined,
48+
config: {} as StrongCheckoutWidgetsConfig,
4649
});
4750

4851
SharedContext.displayName = 'PrimaryRevenueSharedContext';
@@ -54,7 +57,14 @@ export function SharedContextProvider(props: {
5457
const {
5558
children,
5659
value: {
57-
env, environmentId, items, amount, fromContractAddress, provider, checkout,
60+
config,
61+
env,
62+
environmentId,
63+
items,
64+
amount,
65+
fromContractAddress,
66+
provider,
67+
checkout,
5868
},
5969
} = props;
6070

@@ -84,6 +94,7 @@ export function SharedContextProvider(props: {
8494

8595
const values = useMemo(
8696
() => ({
97+
config,
8798
items,
8899
amount,
89100
fromContractAddress,
@@ -96,7 +107,18 @@ export function SharedContextProvider(props: {
96107
checkout,
97108
recipientAddress,
98109
}),
99-
[env, environmentId, items, amount, fromContractAddress, provider, checkout, recipientAddress, signResponse],
110+
[
111+
config,
112+
env,
113+
environmentId,
114+
items,
115+
amount,
116+
fromContractAddress,
117+
provider,
118+
checkout,
119+
recipientAddress,
120+
signResponse,
121+
],
100122
);
101123

102124
return (

packages/checkout/widgets-lib/src/widgets/primary-revenue/hooks/useSignOrder.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ const X_IMMUTABLE_API_KEY = 'sk_imapik-Ekz6cLnnwREtqjGn$xo6_fb97b8';
2424

2525
type SignApiResponse = {
2626
order: {
27-
currency: string;
27+
currency: {
28+
name: string;
29+
decimals: number;
30+
erc20_address: string;
31+
};
2832
currency_symbol: string;
2933
products: {
3034
detail: {
@@ -54,6 +58,22 @@ type SignApiResponse = {
5458
}[];
5559
};
5660

61+
enum SignCurrencyFilter {
62+
CONTRACT_ADDRESS = 'contract_address',
63+
CURRENCY_SYMBOL = 'currency_symbol',
64+
}
65+
66+
type SignApiRequest = {
67+
recipient_address: string
68+
currency_filter: SignCurrencyFilter;
69+
currency_value: string
70+
payment_type: string
71+
products: {
72+
product_id: string;
73+
quantity: number
74+
}[]
75+
};
76+
5777
const toSignedProduct = (
5878
product: SignApiResponse['order']['products'][0],
5979
currency: string,
@@ -77,10 +97,13 @@ const toSignResponse = (
7797

7898
return {
7999
order: {
80-
currency: order.currency,
100+
currency: {
101+
name: order.currency.name,
102+
erc20Address: order.currency.erc20_address,
103+
},
81104
products: order.products.map((product) => toSignedProduct(
82105
product,
83-
order.currency,
106+
order.currency.name,
84107
items.find((item) => item.productId === product.product_id),
85108
)),
86109
totalAmount: Number(order.total_amount),
@@ -151,10 +174,11 @@ export const useSignOrder = (input: SignOrderInput) => {
151174
return undefined;
152175
}
153176

154-
const data = {
177+
const data: SignApiRequest = {
155178
recipient_address: recipientAddress,
156-
contractAddress: fromContractAddress,
157179
payment_type: paymentType,
180+
currency_filter: SignCurrencyFilter.CONTRACT_ADDRESS,
181+
currency_value: fromContractAddress,
158182
products: items.map((item) => ({
159183
product_id: item.productId,
160184
quantity: item.qty,

packages/checkout/widgets-lib/src/widgets/primary-revenue/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export type SignedOrderProduct = {
2525
};
2626

2727
export type SignedOrder = {
28-
currency: string;
28+
currency: {
29+
name: string;
30+
erc20Address: string;
31+
};
2932
totalAmount: number;
3033
products: SignedOrderProduct[];
3134
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-console */
2+
import { BiomeCombinedProviders, Box } from '@biom3/react';
3+
import { BaseTokens, onDarkBase, onLightBase } from '@biom3/design-tokens';
4+
import { WidgetTheme } from '../../../lib';
5+
import { StrongCheckoutWidgetsConfig } from '../../../lib/withDefaultWidgetConfig';
6+
import { HeaderNavigation } from '../../../components/Header/HeaderNavigation';
7+
import { SimpleLayout } from '../../../components/SimpleLayout/SimpleLayout';
8+
import { useSharedContext } from '../context/SharedContextProvider';
9+
10+
export interface PayWithCardProps {
11+
config: StrongCheckoutWidgetsConfig;
12+
13+
}
14+
15+
export function PayWithCard() {
16+
const { config: { theme } } = useSharedContext();
17+
18+
const biomeTheme: BaseTokens = theme.toLowerCase() === WidgetTheme.LIGHT.toLowerCase()
19+
? onLightBase
20+
: onDarkBase;
21+
22+
return (
23+
<BiomeCombinedProviders theme={{ base: biomeTheme }}>
24+
<Box>
25+
<SimpleLayout
26+
header={(
27+
<HeaderNavigation
28+
showBack
29+
title="Pay with Card"
30+
onCloseButtonClick={() => {}}
31+
/>
32+
)}
33+
footerBackgroundColor="base.color.translucent.emphasis.200"
34+
>
35+
<Box>
36+
Transak Iframe
37+
</Box>
38+
</SimpleLayout>
39+
</Box>
40+
</BiomeCombinedProviders>
41+
);
42+
}

0 commit comments

Comments
 (0)