Skip to content

Commit 71e7ea8

Browse files
committed
refactor: 💡 Examples updated to use latest types and changes
1 parent 6d03b13 commit 71e7ea8

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

‎examples/client/src/App.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { useState, useEffect, useRef } from 'react';
2+
import { RequestQuery, OfferOptions, contractConfig, serverAddress } from '../../shared/index.js';
23
import {
3-
RequestQuery,
4-
OfferOptions,
5-
contractConfig,
6-
serverAddress,
7-
} from '../../shared/index.js';
8-
import { Client, ClientOptions, RequestRecord, createClient, storage, utils } from '@windingtree/sdk';
4+
Client,
5+
ClientOptions,
6+
RequestRecord,
7+
createClient,
8+
storage,
9+
utils,
10+
} from '../../../src/index.js'; //@windingtree/sdk
911

1012
/** Default request expiration time */
1113
const defaultExpire = '30s';
@@ -146,9 +148,7 @@ export const Requests = ({ requests, subscribed, onClear, onCancel }: RequestsPr
146148
export const App = () => {
147149
const client = useRef<Client<RequestQuery, OfferOptions> | undefined>();
148150
const [connected, setConnected] = useState<boolean>(false);
149-
const [requests, setRequests] = useState<RequestsRegistryRecord[]>(
150-
[],
151-
);
151+
const [requests, setRequests] = useState<RequestsRegistryRecord[]>([]);
152152
const [error, setError] = useState<string | undefined>();
153153

154154
/** This hook starts the client that will be available via `client.current` */
@@ -237,6 +237,7 @@ export const App = () => {
237237

238238
client.current.requests.publish(request);
239239
} catch (error) {
240+
console.log('@@@', error);
240241
setError((error as Error).message);
241242
}
242243
};

‎examples/node/index.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ import { EventHandler } from '@libp2p/interfaces/events';
22
import { ZeroAddress } from 'ethers';
33
import { DateTime } from 'luxon';
44
import { RequestQuery, OfferOptions, contractConfig, serverAddress } from '../shared/index.js';
5-
import {
6-
createNode,
7-
Node,
8-
NodeOptions,
9-
Queue,
10-
OfferData,
11-
createJobHandler,
12-
} from '../../src/index.js';
5+
import { createNode, Node, NodeOptions, Queue, createJobHandler } from '../../src/index.js';
6+
import { OfferData } from '../../src/shared/types.js';
137
import { noncePeriod } from '../../src/constants.js';
148
import { memoryStorage } from '../../src/storage/index.js';
159
import { nowSec, parseSeconds } from '../../src/utils/time.js';
16-
import { supplierId as generateSupplierId, randomSalt, simpleUid } from '../../src/utils/uid.js';
10+
import { supplierId as generateSupplierId, randomSalt } from '../../src/utils/uid.js';
1711
import { generateMnemonic, deriveAccount } from '../../src/utils/wallet.js';
1812
import { RequestEvent } from '../../src/node/requestManager.js';
1913
import { createLogger } from '../../src/utils/logger.js';
@@ -94,7 +88,7 @@ const createRequestsHandler =
9488
*/
9589
payment: [
9690
{
97-
id: simpleUid(),
91+
id: randomSalt(),
9892
price: '1',
9993
asset: ZeroAddress,
10094
},
@@ -108,6 +102,7 @@ const createRequestsHandler =
108102
],
109103
/** Check-in time */
110104
checkIn: nowSec() + 1000,
105+
checkOut: nowSec() + 2000,
111106
});
112107

113108
queue.addEventListener('expired', ({ detail: job }) => {
@@ -119,7 +114,7 @@ const createRequestsHandler =
119114
* So, we add a job for detection of deals
120115
*/
121116
queue.addJob('deal', offer, {
122-
expire: offer.expire,
117+
expire: Number(offer.expire),
123118
every: 5000, // 5 sec
124119
});
125120
};
@@ -145,7 +140,7 @@ const main = async (): Promise<void> => {
145140
topics: ['hello'],
146141
contractConfig,
147142
serverAddress,
148-
noncePeriod: parseSeconds(noncePeriod),
143+
noncePeriod: Number(parseSeconds(noncePeriod)),
149144
supplierId,
150145
signerSeedPhrase: signerMnemonic,
151146
};

‎examples/shared/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { GenericQuery, GenericOfferOptions } from '../../src/index.js';
1+
import { GenericQuery, GenericOfferOptions } from '../../src/shared/types.js';
22
import { ContractConfig } from '../../src/utils/contract.js';
33

44
export interface RequestQuery extends GenericQuery {
55
greeting: string;
66
}
77

88
export interface OfferOptions extends GenericOfferOptions {
9-
date: string;
9+
date: string | null;
1010
buongiorno: boolean;
1111
buonasera: boolean;
1212
}

0 commit comments

Comments
 (0)