diff --git a/.gitignore b/.gitignore index 328b42a..513a166 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,5 @@ node_modules/ .yarn/install-state.gz .pnp.* +# IntelliJ +.idea diff --git a/packages/site/package.json b/packages/site/package.json index 64d9802..8626c30 100644 --- a/packages/site/package.json +++ b/packages/site/package.json @@ -34,7 +34,7 @@ "@radix-ui/react-label": "^2.0.2", "@radix-ui/react-slot": "^1.0.2", "@radix-ui/react-toast": "^1.1.5", - "@rss3/js-sdk": "^0.6.53", + "@rss3/sdk": "^0.0.11", "ahooks": "^3.7.8", "autoprefixer": "^10.4.16", "class-variance-authority": "^0.7.0", diff --git a/packages/site/src/pages/monitor/create.tsx b/packages/site/src/pages/monitor/create.tsx index 109f51b..ccf3f2e 100644 --- a/packages/site/src/pages/monitor/create.tsx +++ b/packages/site/src/pages/monitor/create.tsx @@ -1,9 +1,10 @@ import { useState, useEffect, useMemo, useContext } from 'react'; import * as z from 'zod'; -import { type Profile, formatAddressAndNS } from '@rss3/js-sdk'; +import { formatAddressAndNS } from '@rss3/sdk'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { navigate } from 'gatsby'; +import { Profile } from '@/types'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; diff --git a/packages/site/src/types/index.ts b/packages/site/src/types/index.ts index fb265f0..28b88c9 100644 --- a/packages/site/src/types/index.ts +++ b/packages/site/src/types/index.ts @@ -1 +1 @@ -export { type GetSnapsResponse, type Snap } from './snap'; +export * from './snap'; diff --git a/packages/site/src/types/snap.ts b/packages/site/src/types/snap.ts index 8f96603..2b18dcc 100644 --- a/packages/site/src/types/snap.ts +++ b/packages/site/src/types/snap.ts @@ -6,3 +6,24 @@ export type Snap = { version: string; initialPermissions: Record; }; + +// TODO: share this type with the `snap` package +export type Profile = { + action?: 'create' | 'renew' | 'unwrap' | 'update' | 'wrap'; + address?: string; + bannerURI?: string[]; + bio?: string; + expireAt?: string | null; + expiry?: string | null; + handle?: string; + image_uri?: string; + key?: string; + name?: string; + network: string; + platform: string; + profileURI?: string[]; + profile_id?: string; + socialURI?: string[]; + url?: string; + value?: string; +}; diff --git a/packages/site/src/utils/snap.ts b/packages/site/src/utils/snap.ts index 18a9e57..3a258ed 100644 --- a/packages/site/src/utils/snap.ts +++ b/packages/site/src/utils/snap.ts @@ -1,7 +1,6 @@ -import { MetaMaskInpageProvider } from '@metamask/providers'; -import type { Profile } from '@rss3/js-sdk'; +import type { MetaMaskInpageProvider } from '@metamask/providers'; import { defaultSnapOrigin } from '../config'; -import { GetSnapsResponse, Snap } from '../types'; +import type { GetSnapsResponse, Snap, Profile } from '../types'; /** * Get the installed snaps in MetaMask. diff --git a/packages/snap/package.json b/packages/snap/package.json index 444534f..5034444 100644 --- a/packages/snap/package.json +++ b/packages/snap/package.json @@ -29,7 +29,7 @@ "@metamask/snaps-types": "^3.1.0", "@metamask/snaps-ui": "^3.1.0", "@metamask/utils": "^8.1.0", - "@rss3/js-sdk": "^0.6.53", + "@rss3/sdk": "^0.0.11", "@urql/core": "^4.1.4", "axios": "^1.6.1", "buffer": "^6.0.3", diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index a9302a8..7f5f5db 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/NaturalSelectionLabs/RSS3-Social-Notifier-Snap.git" }, "source": { - "shasum": "JzJh23BBGdsijFOEAQw8fREDnXCr9VJDCVESa8+qMX0=", + "shasum": "huDZtni5U6N5JLPuNdLI+Hd2EB9k27vZHofTZBymoLw=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/fetch.ts b/packages/snap/src/fetch.ts index b22b0b2..9c213a0 100644 --- a/packages/snap/src/fetch.ts +++ b/packages/snap/src/fetch.ts @@ -1,13 +1,14 @@ import moment from 'moment'; import { type Activity, + getActivities, formatAddressAndNS, format as sdkFormat, formatContent, + themePlain, type Theme, -} from '@rss3/js-sdk'; +} from '@rss3/sdk'; -import { themePlain } from '@rss3/js-sdk/lib/readable/activity/theme'; import { CronActivity, SocialMonitor } from './state'; export const getSocialActivitiesUrl = (address: string) => @@ -20,9 +21,12 @@ export const getSocialActivitiesUrl = (address: string) => * @returns The social activities. */ export async function getSocialActivities(address: string) { - const resp = await fetch(getSocialActivitiesUrl(address)); - const { data } = (await resp.json()) as { data: Activity[] }; - const activities = data.map((item: Activity) => { + const { data } = await getActivities({ + account: address, + tag: ['social'], + direction: 'out', + }); + const activities = data.map((item): CronActivity => { // formatContent only for social and governance tag. const content = formatContent(item); @@ -88,67 +92,57 @@ export function format(activity: Activity) { * @returns The social count array. */ export async function getMultiple(addresses: string[]) { - const activities: CronActivity[] = []; - let hasNextPage = true; - let cursor: string | undefined; - - const filtedAddresses = addresses.filter( + const filteredAddresses = addresses.filter( (addr) => addr !== undefined, ) as string[]; - if (filtedAddresses.length === 0) { + if (filteredAddresses.length === 0) { return []; } - const executeAddresses = filtedAddresses; - // 1 hour ago const timestamp = moment().subtract(1, 'hour').unix(); - while (hasNextPage) { - const params = { - action_limit: 10, - limit: 500, - account: executeAddresses, - tag: ['social'], - type: ['post', 'comment'], - direction: 'out', - since_timestamp: timestamp, - cursor, - }; - const resp = await fetch( - 'https://testnet.rss3.io/data/accounts/activities', - { - method: 'POST', - headers: { - accept: 'application/json', - 'content-type': 'application/json', - }, - body: JSON.stringify(params), - }, - ); - const { data, meta } = (await resp.json()) as { - data: Activity[]; - meta: null | { cursor: string }; - }; - - data.map((item) => { - const content = formatContent(item); - const { id, owner } = item; - const text = format(item).join(''); - const image = content?.media?.[0]?.address; - return content - ? activities.push({ id, text, image, owner }) - : activities.push({ id, text, owner }); - }); - - if (meta === null) { - hasNextPage = false; - } else { - cursor = meta.cursor; - } - } - return executeAddresses.map((addr) => { + const activities = ( + await Promise.all( + filteredAddresses.map(async (account) => { + let cursor: string | undefined; + const result: CronActivity[] = []; + + do { + const res = await getActivities({ + account, + actionLimit: 10, + limit: 500, + tag: ['social'], + type: ['post', 'comment'], + direction: 'out', + sinceTimestamp: timestamp, + cursor, + }); + + res.data.forEach((item) => { + const content = formatContent(item); + const { id, owner } = item; + const text = format(item).join(''); + const image = content?.media?.[0]?.address; + + if (content) { + result.push({ id, text, image, owner }); + } else { + result.push({ id, text, owner }); + } + }); + + cursor = res.cursor; + } while (cursor); + + return result; + }), + ) + ).flat(); + + return filteredAddresses.map((addr) => { const groupBy = activities.filter( (activity) => activity.owner?.toLocaleLowerCase() === addr?.toLocaleLowerCase(), diff --git a/packages/snap/src/index.ts b/packages/snap/src/index.ts index a112400..72e5591 100644 --- a/packages/snap/src/index.ts +++ b/packages/snap/src/index.ts @@ -6,7 +6,6 @@ import { import { divider, heading, panel, text, image } from '@metamask/snaps-ui'; import { assert } from '@metamask/utils'; -import { Profile } from '@rss3/js-sdk'; import { CronActivity, SocialActivity, @@ -18,7 +17,7 @@ import { setState, } from './state'; import { diff, getSocialActivities } from './fetch'; -import { getProfilesBySearch } from './social-graph'; +import { getProfilesBySearch, type Profile } from './social-graph'; import { coverIpfsToUrl, imageBufferToBase64, diff --git a/packages/snap/src/social-graph/index.ts b/packages/snap/src/social-graph/index.ts index 5d5fccd..ea798d9 100644 --- a/packages/snap/src/social-graph/index.ts +++ b/packages/snap/src/social-graph/index.ts @@ -31,4 +31,4 @@ export { Platform }; export { LensHandler, LensFormat }; export { FarcasterHandler, FarcasterFormat }; export { CrossbellHandler, CrossbellFormat, type TCSBProfile }; -export { getProfilesBySearch } from './profiles'; +export { getProfilesBySearch, type Profile } from './profiles'; diff --git a/packages/snap/src/social-graph/profiles.ts b/packages/snap/src/social-graph/profiles.ts index 3ef5e51..eb7ce07 100644 --- a/packages/snap/src/social-graph/profiles.ts +++ b/packages/snap/src/social-graph/profiles.ts @@ -1,7 +1,29 @@ -import { isSupportedNS, type Profile } from '@rss3/js-sdk'; +import { isSupportedNS } from '@rss3/sdk'; + import { isValidWalletAddress } from './utils'; import { Platform } from '.'; +// TODO: share this type with the `site` package +export type Profile = { + action?: 'create' | 'renew' | 'unwrap' | 'update' | 'wrap'; + address?: string; + bannerURI?: string[]; + bio?: string; + expireAt?: string | null; + expiry?: string | null; + handle?: string; + image_uri?: string; + key?: string; + name?: string; + network: string; + platform: string; + profileURI?: string[]; + profile_id?: string; + socialURI?: string[]; + url?: string; + value?: string; +}; + export const profileApi = (search: string) => `https://testnet.rss3.io/data/accounts/${search}/profiles`; diff --git a/packages/snap/src/state.ts b/packages/snap/src/state.ts index 9118d01..20923b9 100644 --- a/packages/snap/src/state.ts +++ b/packages/snap/src/state.ts @@ -1,5 +1,6 @@ import { ManageStateOperation } from '@metamask/snaps-types'; -import { Profile } from '@rss3/js-sdk'; + +import { Profile } from './social-graph'; import { TSocialGraphResult } from '.'; export type CronActivity = { diff --git a/packages/snap/src/tests/index.test.ts b/packages/snap/src/tests/index.test.ts index a411f56..cde85ab 100644 --- a/packages/snap/src/tests/index.test.ts +++ b/packages/snap/src/tests/index.test.ts @@ -1,6 +1,6 @@ import { installSnap } from '@metamask/snaps-jest'; import { expect } from '@jest/globals'; -import { type Activity } from '@rss3/js-sdk'; +import { type Activity } from '@rss3/sdk'; import { format, getSocialActivitiesUrl } from '../fetch'; const DEFAULT_WALLET_ADDRESS = '0xc6d5a3c98ec9073b54fa0969957bd582e8d874bf'; diff --git a/packages/snap/src/utils/activitiy.ts b/packages/snap/src/utils/activitiy.ts index 3c518b4..2e90c28 100644 --- a/packages/snap/src/utils/activitiy.ts +++ b/packages/snap/src/utils/activitiy.ts @@ -6,7 +6,6 @@ import { panel, type Component, } from '@metamask/snaps-ui'; -import { Profile } from '@rss3/js-sdk'; import moment from 'moment'; import { CronActivity, getState, setState } from '../state'; import { @@ -14,6 +13,7 @@ import { FarcasterHandler, LensHandler, Platform, + Profile, } from '../social-graph'; import { TSocialGraphResult } from '..'; import { downloadAndCovertImage, wrapBase64ToSvg } from './image'; diff --git a/yarn.lock b/yarn.lock index e712fc7..4619ce7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6403,14 +6403,33 @@ __metadata: languageName: node linkType: hard -"@rss3/js-sdk@npm:^0.6.53": - version: 0.6.53 - resolution: "@rss3/js-sdk@npm:0.6.53" +"@rss3/api-core@npm:0.0.11": + version: 0.0.11 + resolution: "@rss3/api-core@npm:0.0.11" dependencies: - debug: ^4.3.4 - openapi-fetch: ^0.7.10 - qs: ^6.11.2 - checksum: 6f10e7397fe02e83b6bf3a55270b6e89a69a5e21bd649c9547d3236c0bd45ca4cc35c014525fcf0e5a19455370fb198c8322a02e64233650951794664cf69fc5 + openapi-fetch: ^0.10.2 + ts-case-convert: ^2.0.7 + type-fest: ^4.20.1 + checksum: 2c5728ca8e6dadfdc6e463af5eca47b3385f1dc79094a89a0bd04a1aa60739bcc7d652d4538d72bd3151da3931c043cfaff7f6b7e91b3dd213ceb77d396c0372 + languageName: node + linkType: hard + +"@rss3/api-utils@npm:0.0.11": + version: 0.0.11 + resolution: "@rss3/api-utils@npm:0.0.11" + dependencies: + "@rss3/api-core": 0.0.11 + checksum: b6221e302a1c0bdb701678a81164e0655ddd321b04032cae980244130729d0ca6d5c8aec0970b7bc3b5bb4f70a35f19ec79313f5094e1826edd8870fe7c29589 + languageName: node + linkType: hard + +"@rss3/sdk@npm:^0.0.11": + version: 0.0.11 + resolution: "@rss3/sdk@npm:0.0.11" + dependencies: + "@rss3/api-core": 0.0.11 + "@rss3/api-utils": 0.0.11 + checksum: ac26dd03ab693637809c1d6fd5b0e1599d94d373107bfac6adae2b68e9cb29429989b8b69e7ffc434480bc921231ce385b1f08b9e2d737fff741b3505eed7c16 languageName: node linkType: hard @@ -6430,7 +6449,7 @@ __metadata: "@metamask/snaps-types": ^3.1.0 "@metamask/snaps-ui": ^3.1.0 "@metamask/utils": ^8.1.0 - "@rss3/js-sdk": ^0.6.53 + "@rss3/sdk": ^0.0.11 "@typescript-eslint/eslint-plugin": ^5.33.0 "@typescript-eslint/parser": ^5.33.0 "@urql/core": ^4.1.4 @@ -18560,19 +18579,19 @@ __metadata: languageName: node linkType: hard -"openapi-fetch@npm:^0.7.10": - version: 0.7.10 - resolution: "openapi-fetch@npm:0.7.10" +"openapi-fetch@npm:^0.10.2": + version: 0.10.2 + resolution: "openapi-fetch@npm:0.10.2" dependencies: - openapi-typescript-helpers: ^0.0.4 - checksum: cf9042de76d58585bcb4b93e069f7846031a4a86e0ccae36f8caa0b41f5237369badea88b81fbd801a0d4f456997bc7c6cbded68b2c1b6b78d2d42b19955e3be + openapi-typescript-helpers: ^0.0.9 + checksum: 16e5a366318b5d6297ccd561dd48787fddfa1843dd3e2ab3051f93cf7b991c34184b309634f0498ef07ddc5fbf3579277cb74a48824ade23e3de4764f7b4fefd languageName: node linkType: hard -"openapi-typescript-helpers@npm:^0.0.4": - version: 0.0.4 - resolution: "openapi-typescript-helpers@npm:0.0.4" - checksum: d06d62f9669db5110f32ef36a70f9f2698dd7ad03ba41968baf13e1091caaf23c4af6f8a79103cfd68f65046da4284dcc2f75e9950e9170115189b545e3030fc +"openapi-typescript-helpers@npm:^0.0.9": + version: 0.0.9 + resolution: "openapi-typescript-helpers@npm:0.0.9" + checksum: 4052cf58e0eca87f24764ddd2157d5c91ab2ddbfa1fbe8fbe52b12cf8d1b9d10669d2506c9511270cb4e6155c5315cac59f9ee824313c88bc2edd7eaf27136ee languageName: node linkType: hard @@ -21677,7 +21696,7 @@ __metadata: "@radix-ui/react-label": ^2.0.2 "@radix-ui/react-slot": ^1.0.2 "@radix-ui/react-toast": ^1.1.5 - "@rss3/js-sdk": ^0.6.53 + "@rss3/sdk": ^0.0.11 "@testing-library/dom": ^8.17.1 "@testing-library/jest-dom": ^5.16.4 "@testing-library/react": ^13.3.0 @@ -22968,6 +22987,13 @@ __metadata: languageName: node linkType: hard +"ts-case-convert@npm:^2.0.7": + version: 2.0.7 + resolution: "ts-case-convert@npm:2.0.7" + checksum: 25ec59a8a18b766dc8faca012cec5b47390bf5008fe048285233ba456a4f904fa6e0d479971d2f2889ef07870e009d62806f23c25be576cd14645671afcf9511 + languageName: node + linkType: hard + "ts-interface-checker@npm:^0.1.9": version: 0.1.13 resolution: "ts-interface-checker@npm:0.1.13" @@ -23154,6 +23180,13 @@ __metadata: languageName: node linkType: hard +"type-fest@npm:^4.20.1": + version: 4.20.1 + resolution: "type-fest@npm:4.20.1" + checksum: 8cc8d86c900be4a803a4b252840b761153541f18b03c5bcc02fa2684d0237d48895cc675cd234049f110004d9ce63770242255c04890b85a133f72643c49e342 + languageName: node + linkType: hard + "type-is@npm:^1.6.4, type-is@npm:~1.6.18": version: 1.6.18 resolution: "type-is@npm:1.6.18"