Skip to content

Commit

Permalink
Merge pull request #81 from ltonetwork/WithRelayService
Browse files Browse the repository at this point in the history
With relay service
  • Loading branch information
otobongfp authored Jun 20, 2024
2 parents eebb343 + 33cf3a9 commit 26f10b7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ REACT_APP_LTO_API_URL=
REACT_APP_OWNABLE_EXAMPLES_URL=
REACT_APP_LTO_WALLET_URL=https://wallet.testnet.lto.network
REACT_APP_LTO_EXPLORER_URL=https://explorer.testnet.lto.network
REACT_APP_RELAY=https://relay.lto.network
#REACT_APP_LOCAL_RELAY=http://localhost:3000
#REACT_APP_RELAY=https://relay.lto.network
REACT_APP_LOCAL_RELAY=http://localhost:3000
7 changes: 2 additions & 5 deletions src/components/PackagesFab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ interface PackagesDialogProps {
function PackagesDialog(props: PackagesDialogProps) {
const { onClose, onSelect, onImport, fetchPkgFromRelay, open, packages } =
props;

// useEffect(() => {
// fetchPkgFromRelay();
// }, [fetchPkgFromRelay]);
const filteredPackages = packages.filter((pkg) => !pkg.isNotLocal);

return (
<Dialog onClose={onClose} open={open}>
<List sx={{ pt: 0, minWidth: 250 }} disablePadding>
{packages.map((pkg) => (
{filteredPackages.map((pkg) => (
<ListItem disablePadding disableGutters key={pkg.title}>
<Tooltip
condition={"stub" in pkg}
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/TypedPackage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface TypedPackage extends TypedPackageCapabilities {
description?: string;
cid: string;
chain?;
isNotLocal?: boolean;
versions: Array<{ date: Date; cid: string }>;
}

Expand All @@ -22,4 +23,5 @@ export interface TypedPackageStub {
name: string;
description?: string;
stub: true;
isNotLocal?: boolean;
}
18 changes: 15 additions & 3 deletions src/services/Package.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default class PackageService {
static list(): Array<TypedPackage | TypedPackageStub> {
const local = (LocalStorageService.get("packages") || []) as TypedPackage[];
for (const pkg of local) {
//console.log(pkg);
pkg.versions = pkg.versions.map(({ date, cid }) => ({
date: new Date(date),
cid,
Expand Down Expand Up @@ -107,14 +108,23 @@ export default class PackageService {
name: string,
description: string | undefined,
cid: string,
capabilities: TypedPackageCapabilities
capabilities: TypedPackageCapabilities,
isNotLocal?: boolean
): TypedPackage {
const packages = (LocalStorageService.get("packages") ||
[]) as TypedPackage[];
let pkg = packages.find((pkg) => pkg.name === name);

if (!pkg) {
pkg = { title, name, description, cid, ...capabilities, versions: [] };
pkg = {
title,
name,
description,
cid,
isNotLocal,
...capabilities,
versions: [],
};
packages.push(pkg);
} else {
Object.assign(pkg, { cid, description, ...capabilities });
Expand Down Expand Up @@ -297,14 +307,16 @@ export default class PackageService {
.replace(/\b\w/, (c: any) => c.toUpperCase());
const description = packageJson.description;
const capabilities = await this.getCapabilities(asset);
const isNotLocal = true;

await this.storeAssets(cid, asset);
const pkg = this.storePackageInfo(
title,
name,
description,
cid,
capabilities
capabilities,
isNotLocal
);

const chain = EventChain.from(chainJson);
Expand Down
35 changes: 21 additions & 14 deletions src/services/Relay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,27 @@ export class RelayService {
try {
const Address = sender.address;

const responses = await axios.get(`${relayURL}/inboxes/${Address}/`);
const ownableData = await Promise.all(
responses.data.map(async (response: any) => {
const infoResponse = await axios.get(
`${relayURL}/inboxes/${Address}/${response.hash}`
);
return Message.from(infoResponse.data);
})
);
const validData = ownableData;
if (validData.length < 1) return null;
return ownableData;
} catch (error) {
console.error("Error:", error);
const responses = relayURL
? await axios.get(`${relayURL}/inboxes/${Address}/`)
: null;

if (responses !== null) {
const ownableData = await Promise.all(
responses.data.map(async (response: any) => {
const infoResponse = await axios.get(
`${relayURL}/inboxes/${Address}/${response.hash}`
);
return Message.from(infoResponse.data);
})
);
const validData = ownableData;
if (validData.length < 1) return null;
return ownableData;
} else {
return;
}
} catch {
console.error("can't connect");
}
}

Expand Down

0 comments on commit 26f10b7

Please sign in to comment.