Skip to content

Commit 26f10b7

Browse files
authored
Merge pull request #81 from ltonetwork/WithRelayService
With relay service
2 parents eebb343 + 33cf3a9 commit 26f10b7

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
lines changed

Diff for: .env

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ REACT_APP_LTO_API_URL=
66
REACT_APP_OWNABLE_EXAMPLES_URL=
77
REACT_APP_LTO_WALLET_URL=https://wallet.testnet.lto.network
88
REACT_APP_LTO_EXPLORER_URL=https://explorer.testnet.lto.network
9-
REACT_APP_RELAY=https://relay.lto.network
10-
#REACT_APP_LOCAL_RELAY=http://localhost:3000
9+
#REACT_APP_RELAY=https://relay.lto.network
10+
REACT_APP_LOCAL_RELAY=http://localhost:3000

Diff for: src/components/PackagesFab.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ interface PackagesDialogProps {
3030
function PackagesDialog(props: PackagesDialogProps) {
3131
const { onClose, onSelect, onImport, fetchPkgFromRelay, open, packages } =
3232
props;
33-
34-
// useEffect(() => {
35-
// fetchPkgFromRelay();
36-
// }, [fetchPkgFromRelay]);
33+
const filteredPackages = packages.filter((pkg) => !pkg.isNotLocal);
3734

3835
return (
3936
<Dialog onClose={onClose} open={open}>
4037
<List sx={{ pt: 0, minWidth: 250 }} disablePadding>
41-
{packages.map((pkg) => (
38+
{filteredPackages.map((pkg) => (
4239
<ListItem disablePadding disableGutters key={pkg.title}>
4340
<Tooltip
4441
condition={"stub" in pkg}

Diff for: src/interfaces/TypedPackage.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface TypedPackage extends TypedPackageCapabilities {
1414
description?: string;
1515
cid: string;
1616
chain?;
17+
isNotLocal?: boolean;
1718
versions: Array<{ date: Date; cid: string }>;
1819
}
1920

@@ -22,4 +23,5 @@ export interface TypedPackageStub {
2223
name: string;
2324
description?: string;
2425
stub: true;
26+
isNotLocal?: boolean;
2527
}

Diff for: src/services/Package.service.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export default class PackageService {
7676
static list(): Array<TypedPackage | TypedPackageStub> {
7777
const local = (LocalStorageService.get("packages") || []) as TypedPackage[];
7878
for (const pkg of local) {
79+
//console.log(pkg);
7980
pkg.versions = pkg.versions.map(({ date, cid }) => ({
8081
date: new Date(date),
8182
cid,
@@ -107,14 +108,23 @@ export default class PackageService {
107108
name: string,
108109
description: string | undefined,
109110
cid: string,
110-
capabilities: TypedPackageCapabilities
111+
capabilities: TypedPackageCapabilities,
112+
isNotLocal?: boolean
111113
): TypedPackage {
112114
const packages = (LocalStorageService.get("packages") ||
113115
[]) as TypedPackage[];
114116
let pkg = packages.find((pkg) => pkg.name === name);
115117

116118
if (!pkg) {
117-
pkg = { title, name, description, cid, ...capabilities, versions: [] };
119+
pkg = {
120+
title,
121+
name,
122+
description,
123+
cid,
124+
isNotLocal,
125+
...capabilities,
126+
versions: [],
127+
};
118128
packages.push(pkg);
119129
} else {
120130
Object.assign(pkg, { cid, description, ...capabilities });
@@ -297,14 +307,16 @@ export default class PackageService {
297307
.replace(/\b\w/, (c: any) => c.toUpperCase());
298308
const description = packageJson.description;
299309
const capabilities = await this.getCapabilities(asset);
310+
const isNotLocal = true;
300311

301312
await this.storeAssets(cid, asset);
302313
const pkg = this.storePackageInfo(
303314
title,
304315
name,
305316
description,
306317
cid,
307-
capabilities
318+
capabilities,
319+
isNotLocal
308320
);
309321

310322
const chain = EventChain.from(chainJson);

Diff for: src/services/Relay.service.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,27 @@ export class RelayService {
3434
try {
3535
const Address = sender.address;
3636

37-
const responses = await axios.get(`${relayURL}/inboxes/${Address}/`);
38-
const ownableData = await Promise.all(
39-
responses.data.map(async (response: any) => {
40-
const infoResponse = await axios.get(
41-
`${relayURL}/inboxes/${Address}/${response.hash}`
42-
);
43-
return Message.from(infoResponse.data);
44-
})
45-
);
46-
const validData = ownableData;
47-
if (validData.length < 1) return null;
48-
return ownableData;
49-
} catch (error) {
50-
console.error("Error:", error);
37+
const responses = relayURL
38+
? await axios.get(`${relayURL}/inboxes/${Address}/`)
39+
: null;
40+
41+
if (responses !== null) {
42+
const ownableData = await Promise.all(
43+
responses.data.map(async (response: any) => {
44+
const infoResponse = await axios.get(
45+
`${relayURL}/inboxes/${Address}/${response.hash}`
46+
);
47+
return Message.from(infoResponse.data);
48+
})
49+
);
50+
const validData = ownableData;
51+
if (validData.length < 1) return null;
52+
return ownableData;
53+
} else {
54+
return;
55+
}
56+
} catch {
57+
console.error("can't connect");
5158
}
5259
}
5360

0 commit comments

Comments
 (0)