Skip to content

Commit

Permalink
Add presets for OP fractal consensus meetings
Browse files Browse the repository at this point in the history
Some code to display ethereum addresses in consensus messages in a
pretty way.
  • Loading branch information
sim31 committed Oct 11, 2023
1 parent cad0a91 commit 9a5b8a6
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 6 deletions.
96 changes: 96 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"big-integer": "github:painor/BigInteger.js",
"croppie": "^2.6.5",
"emoji-data-ios": "git+https://github.com/korenskoy/emoji-data-ios#2886b318eae174527c4bc9fcd321940ef3a85527",
"ethers": "^6.7.1",
"idb-keyval": "^6.2.1",
"lowlight": "^2.9.0",
"mp4box": "^0.5.2",
Expand All @@ -151,6 +152,7 @@
"pako": "^2.1.0",
"path-browserify": "^1.0.1",
"qr-code-styling": "github:zubiden/qr-code-styling#dbbfed0",
"truncate-eth-address": "^1.0.2",
"v8-compile-cache": "^2.4.0"
},
"optionalDependencies": {
Expand Down
16 changes: 15 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ export const FRACTAL_INFO: Record<string, ExtPlatformInfo> = {
platform: 'WAX',
accountInfoUrl: 'https://wax.bloks.io/',
},
OPFractal: {
displayTitle: 'Optimism Fractal',
fractalName: 'OPFractal',
submitUrl: 'https://edenfracfront.web.app',
platform: 'Optimism',
accountInfoUrl: 'https://optimistic.etherscan.io/',
},
};
export const DEFAULT_PLATFORM = FRACTAL_INFO[DEFAULT_FRACTAL_NAME].platform;
export const FRACTAL_INFO_BY_PLATFORM: Record<string, ExtPlatformInfo> = {
Expand All @@ -379,7 +386,14 @@ export const FRACTAL_INFO_BY_PLATFORM: Record<string, ExtPlatformInfo> = {
fractalName: 'AWFractal',
submitUrl: 'https://awfractal.web.app/',
platform: 'WAX',
accountInfoUrl: 'https://wax.bloks.io/',
accountInfoUrl: 'https://wax.bloks.io/account',
},
Optimism: {
displayTitle: 'Optimism Fractal',
fractalName: 'OPFractal',
submitUrl: 'https://edenfracfront.web.app',
platform: 'Optimism',
accountInfoUrl: 'https://optimistic.etherscan.io/address',
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/global/actions/ui/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { getServerTime } from '../../../util/serverTime';
import { IS_TOUCH_ENV } from '../../../util/windowEnvironment';
import versionNotification from '../../../versionNotification.txt';
import { getMessageSummaryText, getSenderTitle, isChatChannel } from '../../helpers';
import { promptStrToPlatform } from '../../helpers/consensusMessages';
import { prettifyAccountStr, promptStrToPlatform } from '../../helpers/consensusMessages';
import { renderMessageSummaryHtml } from '../../helpers/renderMessageSummaryHtml';
import { addActionHandler, getGlobal, setGlobal } from '../../index';
import {
Expand Down Expand Up @@ -935,7 +935,7 @@ addActionHandler('composeConsensusMessage', async (gl, actions, payload): Promis
function constructAccountOption(user: ExtUser, platform?: string) {
const extAccount = platform ? user.extAccounts[platform] : undefined;
let id1 = user.id;
const id2 = extAccount ? `(${extAccount}@${platform})` : '';
const id2 = extAccount ? `(${prettifyAccountStr(extAccount)}@${platform})` : '';
if (user.firstName) {
id1 = user.firstName;
} else if (user.usernames && user.usernames.length) {
Expand Down
21 changes: 18 additions & 3 deletions src/global/helpers/consensusMessages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { isAddress as isEthAddress } from 'ethers';
import truncateEthAddress from 'truncate-eth-address';

import type { ChatConsensusMessages, ConsensusResultOption, ConsensusResults } from '../types';

import {
Expand Down Expand Up @@ -39,6 +42,14 @@ function toSubmissionObject(results: ConsensusResults, platform: string, groupNu
};
}

export function prettifyAccountStr(accountStr: string): string {
if (isEthAddress(accountStr)) {
return truncateEthAddress(accountStr);
} else {
return accountStr;
}
}

export function createConsensusResultMsg(
results: ConsensusResults,
submissionUrl?: string,
Expand All @@ -53,8 +64,9 @@ export function createConsensusResultMsg(
for (const rank of ALLOWED_RANKS) {
const winner = results.rankings[rank];
const option = winner?.option ?? '';
const fullAccStr = platform ? winner?.refUser?.extAccounts[platform] : undefined;
const votes = winner ? getVotesStr(winner) : '';
msg = msg.concat(`Level ${rank}: ${option} ${votes}\n`);
msg = msg.concat(`Level ${rank}: ${option},acc:${fullAccStr} ${votes}\n`);
}
msg = msg.concat('\n');

Expand All @@ -76,9 +88,12 @@ export function createConsensusResultMsg(
}

if (accountInfoUrl && platform) {
const accountReStr = `\\W([\\w.]+)@${platform}\\W`;
const fullAccReStr = ',acc:([\\w]+)\\W';
const accountReStr = `\\W([\\w.…]+)@${platform}\\)${fullAccReStr}`;
const accountRe = new RegExp(accountReStr, 'g');
msg = msg.replace(accountRe, `[$&](${accountInfoUrl}/$1) `);
msg = msg.replace(accountRe, `[$&](${accountInfoUrl}/$2) `);
const fullAccRe = new RegExp(fullAccReStr, 'g');
msg = msg.replace(fullAccRe, '');
}

return msg;
Expand Down

0 comments on commit 9a5b8a6

Please sign in to comment.