|
@@ -68,11 +68,13 @@ export const getBlockHash = (
|
|
|
try {
|
|
|
return api.rpc.chain.getBlockHash(block);
|
|
|
} catch (e) {
|
|
|
- return api.rpc.chain.getFinalizedHead();
|
|
|
+ return getBestHash(api);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
export const getHead = (api: ApiPromise) => api.derive.chain.bestNumber();
|
|
|
+export const getBestHash = (api: ApiPromise) =>
|
|
|
+ api.rpc.chain.getFinalizedHead();
|
|
|
|
|
|
export const getTimestamp = async (
|
|
|
api: ApiPromise,
|
|
@@ -99,8 +101,8 @@ export const getEraStake = async (
|
|
|
(await api.query.staking.erasTotalStake.at(hash, era)).toNumber();
|
|
|
|
|
|
// council
|
|
|
-export const getCouncil = (api: ApiPromise): Promise<Seats> =>
|
|
|
- api.query.council.activeCouncil();
|
|
|
+export const getCouncil = async (api: ApiPromise): Promise<Seats> =>
|
|
|
+ (await api.query.council.activeCouncil()) as Seats;
|
|
|
|
|
|
export const getCouncilAt = (api: ApiPromise, hash: Hash): Promise<Seats> =>
|
|
|
api.query.council.activeCouncil.at(hash);
|
|
@@ -286,8 +288,10 @@ export const getWorkerReward = (
|
|
|
export const getCouncilMint = (api: ApiPromise, hash: Hash): Promise<MintId> =>
|
|
|
api.query.council.councilMint.at(hash);
|
|
|
|
|
|
-export const getGroupMint = (api: ApiPromise, group: string): Promise<MintId> =>
|
|
|
- api.query[group].mint();
|
|
|
+export const getGroupMint = async (
|
|
|
+ api: ApiPromise,
|
|
|
+ group: string
|
|
|
+): Promise<MintId> => (await api.query[group].mint()) as MintId;
|
|
|
|
|
|
export const getMintsCreated = async (
|
|
|
api: ApiPromise,
|
|
@@ -345,6 +349,18 @@ export const getMemberIdByAccount = async (
|
|
|
return ids[0];
|
|
|
};
|
|
|
|
|
|
+export const getMemberHandle = async (
|
|
|
+ api: ApiPromise,
|
|
|
+ id: MemberId
|
|
|
+): Promise<string> =>
|
|
|
+ getMember(api, id).then((member: Membership) => String(member.handle));
|
|
|
+
|
|
|
+export const getMemberHandleByAccount = async (
|
|
|
+ api: ApiPromise,
|
|
|
+ account: AccountId
|
|
|
+): Promise<string> =>
|
|
|
+ getMemberHandle(api, await getMemberIdByAccount(api, account));
|
|
|
+
|
|
|
// forum
|
|
|
export const getNextPost = async (
|
|
|
api: ApiPromise,
|
|
@@ -376,6 +392,11 @@ export const getPost = async (api: ApiPromise, id: number): Promise<Post> =>
|
|
|
(await api.query.forum.postById(id)) as Post;
|
|
|
|
|
|
// proposals
|
|
|
+export const getActiveProposals = async (api: ApiPromise): Promise<number[]> =>
|
|
|
+ api.query.proposalsEngine.activeProposalIds
|
|
|
+ .keys()
|
|
|
+ .then((ids) => ids.map(([key]) => key));
|
|
|
+
|
|
|
export const getProposalCount = async (
|
|
|
api: ApiPromise,
|
|
|
hash?: Hash
|
|
@@ -433,7 +454,7 @@ export const getProposal = async (
|
|
|
const title = proposal.title.toString();
|
|
|
const type: string = await getProposalType(api, id);
|
|
|
const args: string[] = [String(id), title, type, stage, result, author];
|
|
|
- const message: string = ``; //formatProposalMessage(args)
|
|
|
+ const message = formatProposalMessage(args);
|
|
|
const created: number = Number(proposal.createdAt);
|
|
|
|
|
|
return {
|
|
@@ -454,6 +475,16 @@ export const getProposal = async (
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+const formatProposalMessage = (
|
|
|
+ data: string[],
|
|
|
+ domain = "https://testnet.joystream.org"
|
|
|
+): { tg: string; discord: string } => {
|
|
|
+ const [id, title, type, stage, result, handle] = data;
|
|
|
+ const tg = `<b>Type</b>: ${type}\r\n<b>Proposer</b>: <a href="${domain}/#/members/${handle}">${handle}</a>\r\n<b>Title</b>: <a href="${domain}/#/proposals/${id}">${title}</a>\r\n<b>Stage</b>: ${stage}\r\n<b>Result</b>: ${result}`;
|
|
|
+ const discord = `**Type**: ${type}\n**Proposer**: ${handle}\n**Title**: ${title}\n**Stage**: ${stage}\n**Result**: ${result}`;
|
|
|
+ return { tg, discord };
|
|
|
+};
|
|
|
+
|
|
|
export const getProposalVotes = async (
|
|
|
api: ApiPromise,
|
|
|
id: ProposalId | number
|