Skip to content

Commit 775019a

Browse files
authored
Merge pull request #35 from windingtree/develop
Sync beta
2 parents b28a1e5 + c243646 commit 775019a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+13313
-2187
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
EXAMPLE_ENTITY_SIGNER_MNEMONIC=
33
# EXAMPLE_ENTITY_SIGNER_PK=
44
EXAMPLE_ENTITY_ID=
5+
EXAMPLE_ENTITY_OWNER_ADDRESS=

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
node-version: "lts/*"
2020
- name: Install dependencies
21-
run: yarn install --frozen-lockfile && yarn --cwd ./examples/client install --frozen-lockfile
21+
run: yarn install --frozen-lockfile && yarn --cwd ./examples/client install --frozen-lockfile && yarn --cwd ./examples/manager install --frozen-lockfile
2222
- name: Lint
2323
run: yarn lint
2424
- name: Test

.github/workflows/test.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ jobs:
2020
with:
2121
node-version: "lts/*"
2222
- name: Install dependencies
23-
run: yarn install --frozen-lockfile && yarn --cwd ./examples/client install --frozen-lockfile
23+
run: |
24+
yarn install --frozen-lockfile && \
25+
yarn --cwd ./examples/client install --frozen-lockfile && \
26+
yarn --cwd ./examples/manager install --frozen-lockfile && \
27+
yarn --cwd ./examples/react-libs install --frozen-lockfile
2428
- name: Lint
2529
run: yarn lint
2630
- name: Test

examples/client/package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
"version": "0.0.0",
55
"type": "module",
66
"devDependencies": {
7-
"@types/react": "^18.2.6",
8-
"@types/react-dom": "^18.2.4",
7+
"@types/react": "^18.2.14",
8+
"@types/react-dom": "^18.2.6",
99
"@vitejs/plugin-react": "^4.0.0",
10+
"eslint": "^8.44.0",
1011
"eslint-config-react-app": "^7.0.1",
1112
"eslint-plugin-react-refresh": "^0.4.1",
1213
"react": "^18.2.0",
1314
"react-dom": "^18.2.0",
14-
"typescript": "^5.0.4",
15-
"viem": "^0.3.43",
15+
"typescript": "^5.1.6",
16+
"viem": "^1.2.9",
1617
"vite": "^4.3.9"
1718
},
1819
"eslintConfig": {
@@ -39,8 +40,9 @@
3940
]
4041
},
4142
"scripts": {
42-
"dev": "vite --force",
43+
"dev": "vite --force --port 5173",
4344
"build": "tsc && vite build",
44-
"preview": "vite preview"
45+
"preview": "vite preview",
46+
"lint": "eslint . --ext .ts"
4547
}
4648
}

examples/client/src/App.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ import { hardhat, polygonZkEvmTestnet } from 'viem/chains';
33
import { EventHandler } from '@libp2p/interfaces/events';
44
import {
55
Client,
6-
ClientOptions,
76
createClient,
8-
storage,
97
ClientRequestsManager,
10-
buildRequest,
118
ClientDealsManager,
129
ClientRequestRecord,
13-
} from '../../../src/index.js'; // @windingtree/sdk
10+
} from '../../../src/client/index.js'; // @windingtree/sdk
11+
import { storage, buildRequest } from '../../../src/index.js'; // @windingtree/sdk
1412
import {
1513
RequestQuery,
1614
OfferOptions,
1715
contractsConfig,
1816
serverAddress,
1917
} from '../../shared/index.js';
2018
import { OfferData, RequestData } from '../../../src/shared/types.js';
21-
import { useWallet } from './providers/WalletProvider/WalletProviderContext.js';
22-
import { AccountWidget } from './providers/WalletProvider/AccountWidget.js';
19+
import { useWallet } from '../../react-libs/src/providers/WalletProvider/WalletProviderContext.js';
20+
import { AccountWidget } from '../../react-libs/src/providers/WalletProvider/AccountWidget.js';
2321
import { FormValues, RequestForm } from './components/RequestForm.js';
2422
import { Tabs, TabPanel } from './components/Tabs.js';
2523
import { Requests, RequestsRegistryRecord } from './components/Requests.js';

examples/client/src/components/Deals.tsx

+48-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { useState, useCallback, useEffect } from 'react';
22
import { DateTime } from 'luxon';
3-
import { Address } from 'viem';
3+
import { Address, Hash } from 'viem';
44
import {
5-
ClientDealsManager,
65
DealRecord,
76
DealStatus,
87
} from '../../../../src/index.js'; // @windingtree/sdk
8+
import { ClientDealsManager } from '../../../../src/client/dealsManager.js';
99
import { RequestQuery, OfferOptions } from '../../../shared/index.js';
10-
import { centerEllipsis, formatBalance, parseWalletError } from '../utils.js';
11-
import { useWallet } from '../providers/WalletProvider/WalletProviderContext.js';
10+
import {
11+
centerEllipsis,
12+
formatBalance,
13+
parseWalletError,
14+
} from '../../../react-libs/src/utils/index.js';
15+
import { useWallet } from '../../../react-libs/src/providers/WalletProvider/WalletProviderContext.js';
1216

1317
export type DealsRegistryRecord = Required<
1418
DealRecord<RequestQuery, OfferOptions>
@@ -219,13 +223,31 @@ export const Cancel = ({ deal, manager, onClose }: CancelProps) => {
219223
* Created deals table
220224
*/
221225
export const Deals = ({ deals, manager }: DealsProps) => {
226+
const { walletClient } = useWallet();
222227
const [dealStates, setDealStates] = useState<Record<string, DealStatus>>({});
223228
const [transferDeal, setTransferDeal] = useState<
224229
DealsRegistryRecord | undefined
225230
>();
226231
const [cancelDeal, setCancelDeal] = useState<
227232
DealsRegistryRecord | undefined
228233
>();
234+
const [userSign, setUserSign] = useState<Hash | undefined>();
235+
const [error, setError] = useState<string | undefined>();
236+
237+
const handleCheckInOut = useCallback(async (deal: DealsRegistryRecord) => {
238+
try {
239+
if (!manager || !walletClient) {
240+
throw new Error('Wallet not connected yet');
241+
}
242+
setUserSign(await manager.checkInOutSignature(
243+
deal.offer.id,
244+
walletClient,
245+
));
246+
} catch (error) {
247+
console.log(error);
248+
setError((error as Error).message || 'Unknown check in signature error');
249+
}
250+
}, [manager, walletClient]);
229251

230252
useEffect(() => {
231253
if (deals && deals.length > 0) {
@@ -271,8 +293,8 @@ export const Deals = ({ deals, manager }: DealsProps) => {
271293
{DealStatus[dealStates[d.offer.id]]}
272294
</td>
273295
<td>
274-
<div style={{ display: 'flex', flexDirection: 'column' }}>
275-
<div style={{ marginBottom: 5 }}>
296+
<div style={{ display: 'flex', flexDirection: 'column', gap: 5 }}>
297+
<div>
276298
<button
277299
onClick={() => setCancelDeal(d)}
278300
disabled={
@@ -302,13 +324,22 @@ export const Deals = ({ deals, manager }: DealsProps) => {
302324
Transfer
303325
</button>
304326
</div>
327+
{d.status === DealStatus.Claimed &&
328+
<div>
329+
<button
330+
onClick={() => handleCheckInOut(d)}
331+
>
332+
Check In
333+
</button>
334+
</div>
335+
}
305336
</div>
306337
</td>
307338
</tr>
308339
))}
309340
</tbody>
310341
</table>
311-
<div style={{ marginTop: 20 }}>
342+
<div>
312343
<TransferForm
313344
deal={transferDeal}
314345
manager={manager}
@@ -319,7 +350,17 @@ export const Deals = ({ deals, manager }: DealsProps) => {
319350
manager={manager}
320351
onClose={() => setCancelDeal(undefined)}
321352
/>
353+
{userSign &&
354+
<div style={{ marginTop: 20 }}>
355+
<h2>Provide this signature to the reception manager:</h2>
356+
<input style={{ width: '100%' }} onFocus={(event) => {
357+
event.target.select();
358+
}} value={userSign} onChange={() => {}} />
359+
</div>
360+
}
322361
</div>
362+
363+
{error && <div style={{ marginTop: 20 }}>🚨 {error}</div>}
323364
</div>
324365
);
325366
};

examples/client/src/components/MakeDeal.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { useState, useCallback, useEffect } from 'react';
22
import { Hash, stringify } from 'viem';
3-
import { ClientDealsManager } from '../../../../src/index.js'; // @windingtree/sdk
3+
import { ClientDealsManager } from '../../../../src/client/dealsManager.js';
44
import { OfferData } from '../../../../src/shared/types.js';
55
import { RequestQuery, OfferOptions } from '../../../shared/index.js';
66
import {
77
ZeroHash,
88
centerEllipsis,
99
formatBalance,
1010
parseWalletError,
11-
} from '../utils.js';
12-
import { useWallet } from '../providers/WalletProvider/WalletProviderContext.js';
13-
import { ConnectButton } from '../providers/WalletProvider/ConnectButton.js';
11+
} from '../../../react-libs/src/utils/index.js';
12+
import { useWallet } from '../../../react-libs/src/providers/WalletProvider/WalletProviderContext.js';
13+
import { ConnectButton } from '../../../react-libs/src/providers/WalletProvider/ConnectButton.js';
1414

1515
interface MakeDealProps {
1616
offer?: OfferData<RequestQuery, OfferOptions>;

examples/client/src/components/Offers.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { stringify } from 'viem';
33
import { utils } from '../../../../src/index.js'; // @windingtree/sdk
44
import { OfferData } from '../../../../src/shared/types.js';
55
import { RequestQuery, OfferOptions } from '../../../shared/index.js';
6-
import { centerEllipsis } from '../utils.js';
6+
import { centerEllipsis } from '../../../react-libs/src/utils/index.js';
77

88
interface OffersProps {
99
offers?: OfferData<RequestQuery, OfferOptions>[];

examples/client/src/components/Requests.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ClientRequestRecord, utils } from '../../../../src/index.js'; // @windingtree/sdk
1+
import { utils } from '../../../../src/index.js'; // @windingtree/sdk
2+
import { ClientRequestRecord } from '../../../../src/client/requestsManager.js';
23
import { OfferData } from '../../../../src/shared/types.js';
34
import { RequestQuery, OfferOptions } from '../../../shared/index.js';
4-
import { centerEllipsis } from '../utils.js';
5+
import { centerEllipsis } from '../../../react-libs/src/utils/index.js';
56

67
export type RequestsRegistryRecord = Required<
78
ClientRequestRecord<RequestQuery, OfferOptions>

examples/client/src/main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createRoot } from 'react-dom/client';
2-
import { WalletProvider } from './providers/WalletProvider';
2+
import { WalletProvider } from '../../react-libs/src/providers/WalletProvider/index.js';
33
import { App } from './App';
44

55
window.addEventListener('unhandledrejection', (event) => {

0 commit comments

Comments
 (0)