Skip to content

Commit c8bf48c

Browse files
authored
Merge pull request #22 from windingtree/develop
Bump new beta
2 parents 540a250 + 6a6e3ff commit c8bf48c

Some content is hidden

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

49 files changed

+2046
-992
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# LOCAL_NODE=true
12
EXAMPLE_ENTITY_SIGNER_MNEMONIC=
3+
# EXAMPLE_ENTITY_SIGNER_PK=
24
EXAMPLE_ENTITY_ID=

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"semi": true,
33
"trailingComma": "all",
44
"singleQuote": true,
5-
"printWidth": 100,
5+
"printWidth": 80,
66
"tabWidth": 2
77
}

docs/docs/clients.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
More about the client configuration options is [here](./index.md#client-node).
66

77
```typescript
8-
import { GenericQuery, GenericOfferOptions, ClientOptions, createClient } from '@windingtree/sdk';
8+
import {
9+
GenericQuery,
10+
GenericOfferOptions,
11+
ClientOptions,
12+
createClient,
13+
} from '@windingtree/sdk';
914

1015
export interface RequestQuery extends GenericQuery {
1116
/** your custom request interface */
@@ -80,7 +85,8 @@ interface GenericMessage {
8085
/**
8186
* Request data structure
8287
*/
83-
interface RequestData<RequestQuery extends GenericQuery> extends GenericMessage {
88+
interface RequestData<RequestQuery extends GenericQuery>
89+
extends GenericMessage {
8490
/** Industry specific query type */
8591
query: RequestQuery;
8692
}
@@ -182,13 +188,19 @@ Every time a new offer is received the client emits a `request:offer` event. You
182188
```typescript
183189
import { useEffect, useRef } from 'react';
184190

185-
const OffersList = ({ client }: { client: Client<RequestQuery, OfferOptions> }) => {
191+
const OffersList = ({
192+
client,
193+
}: {
194+
client: Client<RequestQuery, OfferOptions>;
195+
}) => {
186196
const offers = useRef();
187197

188198
useEffect(() => {
189199
/** Initialization of the component */
190200
offers.current = new Map<string, OfferData<RequestQuery, OfferOptions>>(
191-
client.requests.getAll().reduce((a, v) => [...a, [v.data.id, v.offers]], []),
201+
client.requests
202+
.getAll()
203+
.reduce((a, v) => [...a, [v.data.id, v.offers]], []),
192204
);
193205

194206
/** Manage up-to-date state */

docs/docs/nodes.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ function lifDepositWithdraw(uint256 amount) external;
8484
More about the node configuration options is [here](./index.md#supplier-node).
8585

8686
```typescript
87-
import { GenericQuery, GenericOfferOptions, NodeOptions, createNode } from '@windingtree/sdk';
87+
import {
88+
GenericQuery,
89+
GenericOfferOptions,
90+
NodeOptions,
91+
createNode,
92+
} from '@windingtree/sdk';
8893

8994
export interface RequestQuery extends GenericQuery {
9095
/** your custom request interface */
@@ -186,12 +191,13 @@ interface RequestHandlerOptions {
186191
/**
187192
* Handler should be created using createJobHandler factory function
188193
*/
189-
const requestsHandler = createJobHandler<RequestData<CustomRequestQuery>, RequestHandlerOptions>(
190-
async (data, options) => {
191-
// data - raw request
192-
// options - object with everything else you want pass into the handler at run time
193-
},
194-
);
194+
const requestsHandler = createJobHandler<
195+
RequestData<CustomRequestQuery>,
196+
RequestHandlerOptions
197+
>(async (data, options) => {
198+
// data - raw request
199+
// options - object with everything else you want pass into the handler at run time
200+
});
195201

196202
/**
197203
* Registering of the request handler in the queue

docs/docs/storage.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ The WindingTree market protocol SDK was developed as a cross-platform solution.
66

77
```typescript
88
abstract class Storage {
9-
abstract set<CustomValueType = unknown>(key: string, value: CustomValueType): Promise<void>;
10-
abstract get<CustomValueType = unknown>(key: string): Promise<CustomValueType | undefined>;
9+
abstract set<CustomValueType = unknown>(
10+
key: string,
11+
value: CustomValueType,
12+
): Promise<void>;
13+
abstract get<CustomValueType = unknown>(
14+
key: string,
15+
): Promise<CustomValueType | undefined>;
1116
abstract delete(key: string): Promise<boolean>;
12-
abstract entries<CustomValueType = unknown>(): IterableIterator<[string, CustomValueType]>;
17+
abstract entries<CustomValueType = unknown>(): IterableIterator<
18+
[string, CustomValueType]
19+
>;
1320
}
1421
```
1522

@@ -20,7 +27,9 @@ Every storage connector has `createInitializer` function that is a factory that
2027
```typescript
2128
type StorageInitializer = () => Promise<Storage>;
2229

23-
type StorageInitializerFunction = (options?: GenericStorageOptions) => StorageInitializer;
30+
type StorageInitializerFunction = (
31+
options?: GenericStorageOptions,
32+
) => StorageInitializer;
2433
```
2534

2635
```typescript

docs/index.html

+19-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55
<title>WindingTree Market Protocol SDK</title>
66
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
77
<link rel="icon" href="build/favicon.png" />
8-
<meta name="description" content="WindingTree Market Protocol SDK Documentation Site" />
9-
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
10-
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css" />
11-
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.css" />
8+
<meta
9+
name="description"
10+
content="WindingTree Market Protocol SDK Documentation Site"
11+
/>
12+
<meta
13+
name="viewport"
14+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0"
15+
/>
16+
<link
17+
rel="stylesheet"
18+
href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css"
19+
/>
20+
<link
21+
rel="stylesheet"
22+
href="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.css"
23+
/>
1224
<!-- Google Tag Manager -->
1325
<script>
1426
(function (w, d, s, l, i) {
@@ -54,7 +66,9 @@
5466
code: function (code, lang) {
5567
if (lang === 'mermaid') {
5668
return (
57-
'<div class="mermaid">' + mermaid.render('mermaid-svg-' + num++, code) + '</div>'
69+
'<div class="mermaid">' +
70+
mermaid.render('mermaid-svg-' + num++, code) +
71+
'</div>'
5872
);
5973
}
6074
return this.origin.code.apply(this, arguments);

examples/client/src/App.tsx

+47-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { useState, useEffect, useRef } from 'react';
2-
import { Client, ClientOptions, createClient, storage } from '../../../src/index.js'; // @windingtree/sdk
3-
import { RequestQuery, OfferOptions, chainConfig, serverAddress } from '../../shared/index.js';
2+
import { hardhat, polygonZkEvmTestnet } from 'viem/chains';
3+
import {
4+
Client,
5+
ClientOptions,
6+
createClient,
7+
storage,
8+
} from '../../../src/index.js'; // @windingtree/sdk
9+
import {
10+
RequestQuery,
11+
OfferOptions,
12+
contractsConfig,
13+
serverAddress,
14+
} from '../../shared/index.js';
415
import { OfferData } from '../../../src/shared/types.js';
516
import { useWallet } from './providers/WalletProvider/WalletProviderContext.js';
617
import { AccountWidget } from './providers/WalletProvider/AccountWidget.js';
@@ -11,6 +22,10 @@ import { MakeDeal } from './components/MakeDeal.js';
1122
import { Offers } from './components/Offers.js';
1223
import { Deals, DealsRegistryRecord } from './components/Deals.js';
1324

25+
/** Target chain config */
26+
const chain =
27+
import.meta.env.LOCAL_NODE === 'true' ? hardhat : polygonZkEvmTestnet;
28+
1429
/** Default request expiration time */
1530
const defaultExpire = '30s';
1631

@@ -27,8 +42,12 @@ export const App = () => {
2742
const [selectedTab, setSelectedTab] = useState<number>(0);
2843
const [requests, setRequests] = useState<RequestsRegistryRecord[]>([]);
2944
const [deals, setDeals] = useState<DealsRegistryRecord[]>([]);
30-
const [offers, setOffers] = useState<OfferData<RequestQuery, OfferOptions>[] | undefined>();
31-
const [offer, setOffer] = useState<OfferData<RequestQuery, OfferOptions> | undefined>();
45+
const [offers, setOffers] = useState<
46+
OfferData<RequestQuery, OfferOptions>[] | undefined
47+
>();
48+
const [offer, setOffer] = useState<
49+
OfferData<RequestQuery, OfferOptions> | undefined
50+
>();
3251
const [error, setError] = useState<string | undefined>();
3352

3453
/** This hook starts the client that will be available via `client.current` */
@@ -38,7 +57,8 @@ export const App = () => {
3857
setError(undefined);
3958

4059
const options: ClientOptions = {
41-
chain: chainConfig,
60+
chain,
61+
contracts: contractsConfig,
4262
serverAddress,
4363
storageInitializer: storage.localStorage.createInitializer({
4464
session: false, // session or local storage
@@ -55,9 +75,12 @@ export const App = () => {
5575

5676
const updateDeals = () => {
5777
if (client.current) {
58-
client.current.deals.getAll().then((newDeals) => {
59-
setDeals(newDeals);
60-
}).catch(console.error);
78+
client.current.deals
79+
.getAll()
80+
.then((newDeals) => {
81+
setDeals(newDeals);
82+
})
83+
.catch(console.error);
6184
}
6285
};
6386

@@ -75,12 +98,18 @@ export const App = () => {
7598

7699
client.current.addEventListener('connected', () => {
77100
setConnected(true);
78-
console.log('🔗 Client connected to server at:', new Date().toISOString());
101+
console.log(
102+
'🔗 Client connected to server at:',
103+
new Date().toISOString(),
104+
);
79105
});
80106

81107
client.current.addEventListener('disconnected', () => {
82108
setConnected(false);
83-
console.log('🔌 Client disconnected from server at:', new Date().toISOString());
109+
console.log(
110+
'🔌 Client disconnected from server at:',
111+
new Date().toISOString(),
112+
);
84113
});
85114

86115
/** Listening for requests events and update tables */
@@ -132,15 +161,21 @@ export const App = () => {
132161

133162
return (
134163
<>
135-
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
164+
<div
165+
style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}
166+
>
136167
<div style={{ flex: 1 }}>
137168
<h1>Client</h1>
138169
</div>
139170
<AccountWidget />
140171
</div>
141172
{client.current && <div>✅ Client started</div>}
142173
{connected && <div>✅ Connected to the coordination server</div>}
143-
<RequestForm connected={connected} onSubmit={sendRequest} defaultTopic={defaultTopic} />
174+
<RequestForm
175+
connected={connected}
176+
onSubmit={sendRequest}
177+
defaultTopic={defaultTopic}
178+
/>
144179
<Tabs
145180
tabs={[
146181
{

0 commit comments

Comments
 (0)