diff --git a/packages/transaction/lib/bridge-api.ts b/packages/transaction/lib/bridge-api.ts deleted file mode 100644 index a024b5a50b42f6435a2b6d3065389f8dece11a77..0000000000000000000000000000000000000000 --- a/packages/transaction/lib/bridge-api.ts +++ /dev/null @@ -1,202 +0,0 @@ -import { getLogger } from '@ui/lib/logging'; -import { Community, Entry } from './extended-hive.chain'; -import type { - FollowListType, - IAccountNotification, - IFollowList, - IGetPostHeader, - IUnreadNotifications -} from './extended-hive.chain'; -import { getChain } from './chain'; - -export const DATA_LIMIT = 20; - -const logger = getLogger('bridge'); -export const getPostHeader = async (author: string, permlink: string): Promise => { - return (await getChain()).api.bridge.get_post_header({ - author, - permlink - }); -}; -export const getUnreadNotifications = async (account: string): Promise => { - return (await getChain()).api.bridge.unread_notifications({ - account - }); -}; - -export const getCommunities = async ( - sort: string, - query?: string | null, - observer: string = 'hive.blog' -): Promise => { - return (await getChain()).api.bridge.list_communities({ - query, - sort, - observer - }); -}; - -export const getSubscriptions = async (account: string): Promise => { - return (await getChain()).api.bridge.list_all_subscriptions({ - account - }); -}; - -export const getPostsRanked = async ( - sort: string, - tag: string = '', - start_author: string = '', - start_permlink: string = '', - observer: string, - limit: number = DATA_LIMIT -): Promise => { - return (await getChain()).api.bridge - .get_ranked_posts({ - sort, - start_author, - start_permlink, - limit, - tag, - observer - }) - .then((resp) => { - // logger.info('getPostsRanked result: %o', resp); - if (resp) { - return resolvePosts(resp, observer); - } - console.log('response', resp); - - return resp; - }); -}; - -const resolvePosts = (posts: Entry[], observer: string): Promise => { - const promises = posts.map((p) => resolvePost(p, observer)); - - return Promise.all(promises); -}; - -const resolvePost = (post: Entry, observer: string): Promise => { - const { json_metadata: json } = post; - - if (json.original_author && json.original_permlink && json.tags && json.tags[0] === 'cross-post') { - return getPost(json.original_author, json.original_permlink, observer) - .then((resp) => { - if (resp) { - return { - ...post, - original_entry: resp - }; - } - - return post; - }) - .catch(() => { - return post; - }); - } - - return new Promise((resolve) => { - resolve(post); - }); -}; - -export const getPost = async ( - author: string = '', - permlink: string = '', - observer: string = '' -): Promise => { - return (await getChain()).api.bridge - .get_post({ - author, - permlink, - observer - }) - .then((resp) => { - if (resp) { - return resolvePost(resp, observer); - } - - return resp; - }); -}; - -export const getAccountPosts = async ( - sort: string, - account: string, - observer: string, - start_author: string = '', - start_permlink: string = '', - limit: number = DATA_LIMIT -): Promise => { - return (await getChain()).api.bridge - .get_account_posts({ - sort, - account, - start_author, - start_permlink, - limit, - observer - }) - .then((resp) => { - if (resp) { - return resolvePosts(resp, observer); - } - - return resp; - }); -}; - -export const getFollowList = async ( - observer: string, - follow_type: FollowListType -): Promise => { - return (await getChain()).api.bridge.get_follow_list({ - observer, - follow_type - }); -}; - -export const getSubscribers = async (community: string): Promise => { - return (await getChain()).api.bridge.list_subscribers({ - community - }); -}; - -export const getAccountNotifications = async ( - account: string, - lastId: number | null = null, - limit = 50 -): Promise => { - const params: { account: string; last_id?: number; limit: number } = { - account, - limit - }; - - if (lastId) { - params.last_id = lastId; - } - return (await getChain()).api.bridge.account_notifications(params); -}; - -export const getCommunity = async ( - name: string, - observer: string | undefined = '' -): Promise => { - return (await getChain()).api.bridge.get_community({ name, observer }); -}; -export const getListCommunityRoles = async (community: string): Promise => { - return (await getChain()).api.bridge.list_community_roles({ community }); -}; - -export const getDiscussion = async ( - author: string, - permlink: string, - observer?: string -): Promise | null> => { - return (await getChain()).api.bridge.get_discussion({ - author, - permlink, - observer - }); -}; diff --git a/packages/transaction/lib/bridge.ts b/packages/transaction/lib/bridge.ts index 1c0f38af158db0da7af4ffb73e25e5fac84abcb5..1ff850b09948bec998b48f45c33b2e0b0e520d85 100644 --- a/packages/transaction/lib/bridge.ts +++ b/packages/transaction/lib/bridge.ts @@ -1,17 +1,23 @@ -import { hiveChainService } from './hive-chain-service'; -import { getLogger } from '@ui/lib/logging'; -import { IGetPostHeader, IFollowList, IAccountRelationship, Entry, IUnreadNotifications, Community, IAccountNotification, FollowListType } from './extended-hive.chain'; -import {commonVariables} from'@ui/lib/common-variables'; - -const logger = getLogger('app'); - -const chain = await hiveChainService.getHiveChain(); +import { getChain } from './chain'; +import { + IAccountRelationship, + Entry, + Community, + IAccountNotification, + FollowListType, + IFollowList, + IGetPostHeader, + IUnreadNotifications +} from './extended-hive.chain'; +import { commonVariables } from '@ui/lib/common-variables'; + +const chain = await getChain(); export type Subscription = Array; export const DATA_LIMIT = 20; -const resolvePost = (post: Entry, observer: string): Promise => { +const resolvePost = async (post: Entry, observer: string): Promise => { const { json_metadata: json } = post; if (json.original_author && json.original_permlink && json.tags && json.tags[0] === 'cross-post') { @@ -202,3 +208,38 @@ export const getTwitterInfo = async (username: string) => { return data; }; + +export const getPostHeader = async (author: string, permlink: string): Promise => { + return chain.api.bridge.get_post_header({ + author, + permlink + }); +}; + +export const getUnreadNotifications = async (account: string): Promise => { + return chain.api.bridge.unread_notifications({ + account + }); +}; + +export const getSubscriptions = async (account: string): Promise => { + return chain.api.bridge.list_all_subscriptions({ + account + }); +}; + +export const getFollowList = async ( + observer: string, + follow_type: FollowListType +): Promise => { + return chain.api.bridge.get_follow_list({ + observer, + follow_type + }); +}; + +export const getSubscribers = async (community: string): Promise => { + return chain.api.bridge.list_subscribers({ + community + }); +};