Skip to content

Commit

Permalink
dedicated pathfinderV2 class connecting to the circlesRpc
Browse files Browse the repository at this point in the history
  • Loading branch information
jaensen committed Oct 24, 2024
1 parent 3eb7d50 commit 4dc1d85
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 216 deletions.
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
},
"name": "@cirlces-sdk/root",
"license": "MIT",
"version": "0.13.4"
"version": "0.14.0"
}
2 changes: 1 addition & 1 deletion packages/abi-v1/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/abi-v1",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/abi-v2",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-cometh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-cometh",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/adapter": "0.13.4",
"@circles-sdk/adapter": "0.14.0",
"@cometh/connect-sdk": "1.2.29"
},
"keywords": [],
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-ethers",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -18,8 +18,8 @@
},
"dependencies": {
"ethers": "^6.13.2",
"@circles-sdk/adapter": "0.13.4",
"@circles-sdk/utils": "0.13.4"
"@circles-sdk/adapter": "0.14.0",
"@circles-sdk/utils": "0.14.0"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-safe-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-safe-app",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/adapter": "0.13.4",
"@circles-sdk/adapter": "0.14.0",
"@safe-global/safe-apps-sdk": "^9.1.0"
},
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-safe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter-safe",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/adapter",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/data",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.13.4"
"@circles-sdk/utils": "0.14.0"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions packages/profiles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles-sdk/profiles",
"version": "0.13.4",
"version": "0.14.0",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand All @@ -17,7 +17,7 @@
"build": "rollup -c"
},
"dependencies": {
"@circles-sdk/utils": "0.13.4"
"@circles-sdk/utils": "0.14.0"
},
"keywords": [],
"author": "",
Expand Down
103 changes: 52 additions & 51 deletions packages/profiles/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,72 @@
export interface Profile {
name: string;
description?: string;
previewImageUrl?: string;
imageUrl?: string;
name: string;
description?: string;
previewImageUrl?: string;
imageUrl?: string;
extensions?: Record<string, any>;
}

export interface GroupProfile extends Profile {
symbol: string;
symbol: string;
}

export class Profiles {
constructor(private readonly profileServiceUrl: string) {
}

private getProfileServiceUrl(): string {
return this.profileServiceUrl.endsWith('/') ? this.profileServiceUrl : `${this.profileServiceUrl}/`;
}
constructor(private readonly profileServiceUrl: string) {
}

async create(profile: Profile): Promise<string> {
const response = await fetch(`${this.getProfileServiceUrl()}pin`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(profile)
});
private getProfileServiceUrl(): string {
return this.profileServiceUrl.endsWith('/') ? this.profileServiceUrl : `${this.profileServiceUrl}/`;
}

if (!response.ok) {
throw new Error(`Failed to create profile. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`);
}
async create(profile: Profile): Promise<string> {
const response = await fetch(`${this.getProfileServiceUrl()}pin`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(profile)
});

const data = await response.json();
return data.cid;
if (!response.ok) {
throw new Error(`Failed to create profile. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`);
}

/**
* Retrieves a profile by its CID. If the profile is not found, an error is thrown.
* @param cid The CID of the profile to retrieve.
*/
async get(cid: string): Promise<Profile|undefined> {
const response = await fetch(`${this.getProfileServiceUrl()}get?cid=${cid}`);
if (!response.ok) {
console.warn(`Failed to retrieve profile ${cid}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`);
return undefined;
}
const data = await response.json();
return data.cid;
}

return await response.json();
/**
* Retrieves a profile by its CID. If the profile is not found, an error is thrown.
* @param cid The CID of the profile to retrieve.
*/
async get(cid: string): Promise<Profile | undefined> {
const response = await fetch(`${this.getProfileServiceUrl()}get?cid=${cid}`);
if (!response.ok) {
console.warn(`Failed to retrieve profile ${cid}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`);
return undefined;
}

/**
* Retrieves multiple profiles by their CIDs. If a profile is not found, it will not be included in the result.
* @param cids The CIDs of the profiles to retrieve.
* @returns A map of CIDs to profiles. If a profile is not found, it will not be included in the map.
*/
async getMany(cids: string[]): Promise<Record<string, Profile>> {
const response = await fetch(`${this.getProfileServiceUrl()}getBatch?cids=${cids.join(',')}`);
if (!response.ok) {
throw new Error(`Failed to retrieve profiles ${cids.join(',')}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`);
}
return await response.json();
}

const profilesArray = await response.json();
const profiles: Record<string, Profile> = {};
/**
* Retrieves multiple profiles by their CIDs. If a profile is not found, it will not be included in the result.
* @param cids The CIDs of the profiles to retrieve.
* @returns A map of CIDs to profiles. If a profile is not found, it will not be included in the map.
*/
async getMany(cids: string[]): Promise<Record<string, Profile>> {
const response = await fetch(`${this.getProfileServiceUrl()}getBatch?cids=${cids.join(',')}`);
if (!response.ok) {
throw new Error(`Failed to retrieve profiles ${cids.join(',')}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`);
}

for (let i = 0; i < cids.length; i++) {
if (profilesArray[i]) {
profiles[cids[i]] = profilesArray[i];
}
}
const profilesArray = await response.json();
const profiles: Record<string, Profile> = {};

return profiles;
for (let i = 0; i < cids.length; i++) {
if (profilesArray[i]) {
profiles[cids[i]] = profilesArray[i];
}
}

return profiles;
}
}
Loading

0 comments on commit 4dc1d85

Please sign in to comment.