Skip to content

Commit bc774cb

Browse files
committed
refactor: migrate NewTransaction Deliverable component (WIP)
1 parent baa32a3 commit bc774cb

File tree

9 files changed

+43
-166
lines changed

9 files changed

+43
-166
lines changed

web/src/global.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@
3737
--spacing-fluid-8-32-300: clamp(8px, calc(8px + (32 - 8) * (100vw - 300px) / (1250 - 300)), 32px);
3838
--spacing-fluid-12-32-300: clamp(12px, calc(12px + (32 - 12) * (100vw - 300px) / (1250 - 300)), 32px);
3939
--spacing-fluid-20-24: clamp(20px, calc(20px + (24 - 20) * (100vw - 375px) / (1250 - 375)), 24px);
40+
--spacing-fluid-24-18: clamp(18px, calc(24px + (18 - 24) * (100vw - 375px) / (1250 - 375)), 24px);
4041
--spacing-fluid-100-130: clamp(100px, calc(100px + (130 - 100) * (100vw - 375px) / (1250 - 375)), 130px);
4142
--spacing-fluid-300-424-300: clamp(300px, calc(300px + (424 - 300) * (100vw - 300px) / (1250 - 300)), 424px);
4243
--spacing-fluid-300-480: clamp(300px, calc(300px + (480 - 300) * (100vw - 375px) / (1250 - 375)), 480px);
4344
--spacing-fluid-342-500: clamp(342px, calc(342px + (500 - 342) * (100vw - 375px) / (1250 - 375)), 500px);
45+
--spacing-fluid-342-574: clamp(342px, calc(342px + (574 - 342) * (100vw - 375px) / (1250 - 375)), 574px);
4446
--spacing-fluid-342-618: clamp(342px, calc(342px + (618 - 342) * (100vw - 375px) / (1250 - 375)), 618px);
47+
--spacing-fluid-342-699: clamp(342px, calc(342px + (699 - 342) * (100vw - 375px) / (1250 - 375)), 699px);
4548
}
4649

4750
.dark {

web/src/hooks/useIsDesktop.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { useMemo } from "react";
22

33
import { useWindowSize } from "react-use";
4-
5-
import { BREAKPOINT_LANDSCAPE } from "styles/landscapeStyle";
4+
import { LG_BREAKPOINT } from "src/styles/breakpoints";
65

76
const useIsDesktop = () => {
87
const { width } = useWindowSize();
9-
return useMemo(() => width > BREAKPOINT_LANDSCAPE, [width]);
8+
return useMemo(() => width > LG_BREAKPOINT, [width]);
109
};
1110

1211
export default useIsDesktop;

web/src/pages/NewTransaction/Terms/Deliverable/index.tsx

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,15 @@
11
import React from "react";
2-
import styled, { css } from "styled-components";
3-
import { landscapeStyle } from "styles/landscapeStyle";
42
import { errorToast } from "utils/wrapWithToast";
53
import { FileUploader } from "@kleros/ui-components-library";
64
import MarkdownEditor from "components/MarkdownEditor";
75
import { useNewTransactionContext } from "context/NewTransactionContext";
8-
import { responsiveSize } from "styles/responsiveSize";
96
import NavigationButtons from "../../NavigationButtons";
107
import TokenTransaction from "../Payment/TokenTransaction";
118
import Header from "pages/NewTransaction/Header";
129
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
1310
import { getFileUploaderMsg } from "src/utils";
1411
import useIsDesktop from "hooks/useIsDesktop";
1512

16-
const Container = styled.div`
17-
display: flex;
18-
flex-direction: column;
19-
align-items: center;
20-
`;
21-
22-
const MarkdownEditorContainer = styled.div`
23-
width 84vw;
24-
25-
${landscapeStyle(
26-
() => css`
27-
width: ${responsiveSize(342, 699)};
28-
`
29-
)}
30-
`;
31-
32-
const StyledFileUploader = styled(FileUploader)`
33-
width: 84vw;
34-
margin-top: 16px;
35-
margin-bottom: ${responsiveSize(130, 72)};
36-
37-
small {
38-
white-space: pre-line;
39-
text-align: start;
40-
}
41-
42-
${landscapeStyle(
43-
() => css`
44-
width: ${responsiveSize(342, 699)};
45-
`
46-
)}
47-
`;
48-
4913
const Deliverable: React.FC = () => {
5014
const {
5115
escrowType,
@@ -79,18 +43,19 @@ const Deliverable: React.FC = () => {
7943
(getFileUploaderMsg(Roles.Policy, roleRestrictions) ?? "");
8044

8145
return (
82-
<Container>
46+
<div className="flex flex-col items-center">
8347
{escrowType === "general" ? (
8448
<>
8549
<Header text="Contract Terms" />
86-
<MarkdownEditorContainer>
50+
<div className="w-[84vw] mb-4 lg:w-fluid-342-699">
8751
<MarkdownEditor
88-
value={deliverableText}
89-
onChange={handleWrite}
90-
placeholder="eg. I should receive a website created in React with the following specification: x,y,z."
52+
value={deliverableText}
53+
onChange={handleWrite}
54+
placeholder="eg. I should receive a website created in React with the following specification: x,y,z."
9155
/>
92-
</MarkdownEditorContainer>
93-
<StyledFileUploader
56+
</div>
57+
<FileUploader
58+
className="w-[84vw] lg:w-fluid-342-699 [&_small]:whitespace-pre-line"
9459
callback={handleAttachFile}
9560
variant={isDesktop ? "info" : undefined}
9661
msg={fileFootMessage}
@@ -110,7 +75,7 @@ const Deliverable: React.FC = () => {
11075
setRecipientAddress={setBuyerAddress}
11176
/>
11277
)}
113-
</Container>
78+
</div>
11479
);
11580
};
11681

web/src/pages/NewTransaction/Terms/Payment/DestinationAddress.tsx

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
11
import React, { useState, useEffect, useMemo } from "react";
2-
import styled, { css } from "styled-components";
3-
import { responsiveSize } from "styles/responsiveSize";
4-
import { landscapeStyle } from "styles/landscapeStyle";
5-
import { Field } from "@kleros/ui-components-library";
2+
import { TextField } from "@kleros/ui-components-library";
63
import { useDebounce } from "react-use";
74
import { useEnsAddress } from "wagmi";
85
import { useNewTransactionContext } from "context/NewTransactionContext";
96
import { ensDomainPattern, validateAddress } from "utils/validateAddress";
107
import { isEmpty } from "src/utils";
118

12-
const StyledField = styled(Field)`
13-
margin-bottom: ${responsiveSize(68, 40)};
14-
15-
small {
16-
margin-top: 6px;
17-
svg {
18-
margin-top: 8px;
19-
}
20-
}
21-
22-
input {
23-
font-size: 16px;
24-
}
25-
26-
${landscapeStyle(
27-
() => css`
28-
width: ${responsiveSize(342, 574)};
29-
`
30-
)}
31-
`;
32-
339
interface IDestinationAddress {
3410
recipientAddress: string;
3511
setRecipientAddress: (value: string) => void;
@@ -54,11 +30,6 @@ const DestinationAddress: React.FC<IDestinationAddress> = ({ recipientAddress, s
5430
}
5531
}, [debouncedRecipientAddress, ensResult.data, setIsRecipientAddressResolved]);
5632

57-
const handleWrite = (event: React.ChangeEvent<HTMLInputElement>) => {
58-
const input = event.target.value;
59-
setRecipientAddress(input);
60-
};
61-
6233
const message = useMemo(() => {
6334
if (isEmpty(debouncedRecipientAddress) || isValid) {
6435
return "The ETH address or ENS of the person/entity that will receive the funds.";
@@ -74,10 +45,10 @@ const DestinationAddress: React.FC<IDestinationAddress> = ({ recipientAddress, s
7445
}, [debouncedRecipientAddress, isValid]);
7546

7647
return (
77-
<StyledField
78-
type="text"
48+
<TextField
49+
className="lg:w-fluid-342-574"
7950
value={recipientAddress}
80-
onChange={handleWrite}
51+
onChange={(value) => setRecipientAddress(value)}
8152
placeholder="eg. 0x123ABC... or john.eth"
8253
variant={variant}
8354
message={message}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import React from "react";
2-
import styled from "styled-components";
3-
4-
const Container = styled.h1`
5-
margin-bottom: 26px;
6-
`;
72

83
const ToDivider: React.FC = () => {
9-
return <Container>to</Container>;
4+
return <h1 className="mb-6">to</h1>;
105
};
116
export default ToDivider;

web/src/pages/NewTransaction/Terms/Payment/TokenTransaction/TokenAndAmount/AmountField.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

web/src/pages/NewTransaction/Terms/Payment/TokenTransaction/TokenAndAmount/Token.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
import React from "react";
2-
import styled, { css } from "styled-components";
3-
import { landscapeStyle } from "styles/landscapeStyle";
4-
import { responsiveSize } from "styles/responsiveSize";
5-
import AmountField from "./AmountField";
6-
import Token from "./Token";
7-
8-
const Container = styled.div`
9-
display: flex;
10-
flex-direction: column;
11-
gap: 24px;
12-
align-items: center;
13-
margin-bottom: ${responsiveSize(24, 18)};
14-
15-
${landscapeStyle(
16-
() => css`
17-
flex-direction: row;
18-
`
19-
)}
20-
`;
2+
import { DropdownSelect, NumberField } from "@kleros/ui-components-library";
213

224
interface ITokenAndAmount {
235
quantity: string;
@@ -28,10 +10,27 @@ interface ITokenAndAmount {
2810

2911
const TokenAndAmount: React.FC<ITokenAndAmount> = ({ quantity, setQuantity, token, setToken }) => {
3012
return (
31-
<Container>
32-
<AmountField quantity={quantity} setQuantity={setQuantity} />
33-
<Token token={token} setToken={setToken} />
34-
</Container>
13+
<div className="flex flex-col gap-6 items-center mb-fluid-24-18 lg:flex-row">
14+
<NumberField
15+
placeholder="eg. 3.6"
16+
value={Number(quantity) ?? 0}
17+
minValue={0}
18+
onChange={(value) => setQuantity(value.toString())}
19+
formatOptions={{
20+
//Prevent automatic rounding of very small amounts
21+
minimumFractionDigits: 0,
22+
maximumFractionDigits: 18,
23+
}}
24+
/>
25+
<DropdownSelect
26+
defaultSelectedKey={token}
27+
items={[
28+
{ id: "xDAI", text: "xDAI", dot: "red", itemValue: "xDAI" },
29+
{ id: "ETH", text: "ETH", dot: "blue", itemValue: "ETH" },
30+
]}
31+
callback={(value) => setToken(value.itemValue)}
32+
/>
33+
</div>
3534
);
3635
};
3736
export default TokenAndAmount;

web/src/pages/NewTransaction/Terms/Payment/TokenTransaction/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import React from "react";
2-
import styled from "styled-components";
32
import Header from "pages/NewTransaction/Header";
43
import NavigationButtons from "../../../NavigationButtons";
54
import DestinationAddress from "../DestinationAddress";
65
import ToDivider from "../ToDivider";
76
import TokenAndAmount from "./TokenAndAmount";
87

9-
const Container = styled.div`
10-
display: flex;
11-
flex-direction: column;
12-
align-items: center;
13-
`;
14-
158
interface ITokenTransaction {
169
headerText: string;
1710
prevRoute: string;
@@ -36,13 +29,13 @@ const TokenTransaction: React.FC<ITokenTransaction> = ({
3629
setRecipientAddress,
3730
}) => {
3831
return (
39-
<Container>
32+
<div className="flex flex-col items-center">
4033
<Header text={headerText} />
4134
<TokenAndAmount quantity={quantity} setQuantity={setQuantity} token={token} setToken={setToken} />
4235
<ToDivider />
4336
<DestinationAddress recipientAddress={recipientAddress} setRecipientAddress={setRecipientAddress} />
4437
<NavigationButtons prevRoute={prevRoute} nextRoute={nextRoute} />
45-
</Container>
38+
</div>
4639
);
4740
};
4841

0 commit comments

Comments
 (0)