From 47647704cb7558ccef7b01726be3049d04efbd16 Mon Sep 17 00:00:00 2001 From: dasein Date: Mon, 11 Mar 2024 21:26:18 +0530 Subject: [PATCH 01/39] feat(sense): cozo op transaction to teleport send --- src/pages/teleport/send/actionBar.send.tsx | 15 ++++++++++++--- .../SyncTransactionsLoop/services/chat.ts | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/pages/teleport/send/actionBar.send.tsx b/src/pages/teleport/send/actionBar.send.tsx index c50774a46..2a6ccd8e1 100644 --- a/src/pages/teleport/send/actionBar.send.tsx +++ b/src/pages/teleport/send/actionBar.send.tsx @@ -12,6 +12,7 @@ import { LEDGER } from '../../../utils/config'; import { convertAmountReverce } from '../../../utils/utils'; import ActionBarPingTxs from '../components/actionBarPingTxs'; +import { useBackend } from 'src/contexts/backend/backend'; const { STAGE_INIT, STAGE_ERROR, STAGE_SUBMITTED } = LEDGER; @@ -37,7 +38,7 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { const [txHash, setTxHash] = useState>(undefined); const [errorMessage, setErrorMessage] = useState>(undefined); - + const { senseApi } = useBackend(); const { tokenAmount, tokenSelect, @@ -70,7 +71,15 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { ); if (response.code === 0) { - setTxHash(response.transactionHash); + const txHash = response.transactionHash; + setTxHash(txHash); + await senseApi?.addMsgSendAsLocal({ + transactionHash: txHash, + fromAddress: address, + toAddress: recipient, + amount: offerCoin, + memo: memoValue, + }); } else { setTxHash(undefined); setStage(STAGE_ERROR); @@ -79,7 +88,7 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { } catch (error) { setTxHash(undefined); setStage(STAGE_ERROR); - + console.log('error', error); setErrorMessage(error.toString()); } } else { diff --git a/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts b/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts index 922cf0a5a..68463bb7e 100644 --- a/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts +++ b/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts @@ -122,7 +122,10 @@ export const syncMyChats = async ( }; // eslint-disable-next-line no-await-in-loop - await throwIfAborted(db.updateSyncStatus, signal)(syncStatusChanges); + await throwIfAborted( + db.updateSyncStatus.bind(db), + signal + )(syncStatusChanges); results.push({ ...syncItem, From a86ed8768a12376997ba9bf3e102eedf17a52b2f Mon Sep 17 00:00:00 2001 From: dasein Date: Mon, 11 Mar 2024 21:50:48 +0530 Subject: [PATCH 02/39] feat(sense): cozo op transaction teleport as cid --- src/features/sense/ui/ActionBar/ActionBar.tsx | 9 +++------ src/pages/teleport/send/actionBar.send.tsx | 10 +++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/features/sense/ui/ActionBar/ActionBar.tsx b/src/features/sense/ui/ActionBar/ActionBar.tsx index e3e8c1ebf..4a7390f6f 100644 --- a/src/features/sense/ui/ActionBar/ActionBar.tsx +++ b/src/features/sense/ui/ActionBar/ActionBar.tsx @@ -95,12 +95,9 @@ function ActionBarWrapper({ id, adviser }: Props) { const formattedAmount = [coin(amount || 1, CYBER.DENOM_CYBER)]; - let messageCid; - if (!message.match(PATTERN_IPFS_HASH)) { - messageCid = (await ipfsApi.addContent(message)) as string; - } else { - messageCid = message; - } + const messageCid = !message.match(PATTERN_IPFS_HASH) + ? ((await ipfsApi.addContent(message)) as string) + : message; let response; diff --git a/src/pages/teleport/send/actionBar.send.tsx b/src/pages/teleport/send/actionBar.send.tsx index 2a6ccd8e1..d1b72e5f8 100644 --- a/src/pages/teleport/send/actionBar.send.tsx +++ b/src/pages/teleport/send/actionBar.send.tsx @@ -8,7 +8,7 @@ import { useIbcDenom } from 'src/contexts/ibcDenom'; import { RootState } from 'src/redux/store'; import { useAppSelector } from 'src/redux/hooks'; import { Account, ActionBar as ActionBarCenter } from '../../../components'; -import { LEDGER } from '../../../utils/config'; +import { LEDGER, PATTERN_IPFS_HASH } from '../../../utils/config'; import { convertAmountReverce } from '../../../utils/utils'; import ActionBarPingTxs from '../components/actionBarPingTxs'; @@ -38,7 +38,7 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { const [txHash, setTxHash] = useState>(undefined); const [errorMessage, setErrorMessage] = useState>(undefined); - const { senseApi } = useBackend(); + const { senseApi, ipfsApi } = useBackend(); const { tokenAmount, tokenSelect, @@ -62,12 +62,16 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { if (addressActive !== null && addressActive.bech32 === address) { try { + const memoAsCid = !memoValue.match(PATTERN_IPFS_HASH) + ? ((await ipfsApi!.addContent(memoValue)) as string) + : memoValue; + const response = await signingClient.sendTokens( address, recipient, offerCoin, 'auto', - memoValue + memoAsCid ); if (response.code === 0) { From e35c252e23b04f593fc038dede15a3fa2b125ff5 Mon Sep 17 00:00:00 2001 From: dasein Date: Mon, 11 Mar 2024 22:24:05 +0530 Subject: [PATCH 03/39] refactor(sense): move logic out of componet --- src/contexts/backend/services/senseApi.ts | 4 +- src/pages/teleport/send/actionBar.send.tsx | 88 ++++++++++++------- .../backend/workers/background/worker.ts | 2 +- 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/src/contexts/backend/services/senseApi.ts b/src/contexts/backend/services/senseApi.ts index 6840c008b..7b38f9f95 100644 --- a/src/contexts/backend/services/senseApi.ts +++ b/src/contexts/backend/services/senseApi.ts @@ -1,6 +1,7 @@ import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; import { isParticle } from 'src/features/particle/utils'; import { TransactionDto } from 'src/services/CozoDb/types/dto'; +import BroadcastChannelSender from 'src/services/backend/channels/BroadcastChannelSender'; import DbApiWrapper from 'src/services/backend/services/dataSource/indexedDb/dbApiWrapper'; import { MSG_SEND_TRANSACTION_TYPE, @@ -107,13 +108,14 @@ export const createSenseApi = ( const transaction = prepareSenseTransaction(msg); await dbApi.putTransactions([transaction]); - await syncMyChats( + const items = await syncMyChats( dbApi, myAddress!, transaction.timestamp, new AbortController().signal, false ); + new BroadcastChannelSender().postSenseUpdate(items); }, getTransactions: (neuron: NeuronAddress) => dbApi.getTransactions(neuron), getFriendItems: async (userAddress: NeuronAddress) => { diff --git a/src/pages/teleport/send/actionBar.send.tsx b/src/pages/teleport/send/actionBar.send.tsx index d1b72e5f8..438450ee1 100644 --- a/src/pages/teleport/send/actionBar.send.tsx +++ b/src/pages/teleport/send/actionBar.send.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useCallback, useState } from 'react'; import BigNumber from 'bignumber.js'; import useSetActiveAddress from 'src/hooks/useSetActiveAddress'; import { useSigningClient } from 'src/contexts/signerClient'; @@ -13,6 +13,10 @@ import { convertAmountReverce } from '../../../utils/utils'; import ActionBarPingTxs from '../components/actionBarPingTxs'; import { useBackend } from 'src/contexts/backend/backend'; +import { set } from 'lodash'; +import { SigningCyberClient } from '@cybercongress/cyber-js'; +import { SenseApi } from 'src/contexts/backend/services/senseApi'; +import { IpfsApi } from 'src/services/backend/workers/background/worker'; const { STAGE_INIT, STAGE_ERROR, STAGE_SUBMITTED } = LEDGER; @@ -29,6 +33,46 @@ type Props = { memoValue: string; }; +const sendTokensWitMessage = async ( + address: string, + recipient: string, + offerCoin: Coin[], + memo: string, + { + senseApi, + ipfsApi, + signingClient, + }: { signingClient: SigningCyberClient; senseApi: SenseApi; ipfsApi: IpfsApi } +) => { + const memoAsCid = !memo.match(PATTERN_IPFS_HASH) + ? ((await ipfsApi!.addContent(memo)) as string) + : memo; + + const response = await signingClient.sendTokens( + address, + recipient, + offerCoin, + 'auto', + memoAsCid + ); + + if (response.code === 0) { + const txHash = response.transactionHash; + await senseApi?.addMsgSendAsLocal({ + transactionHash: txHash, + fromAddress: address, + toAddress: recipient, + amount: offerCoin, + memo: memoAsCid, + }); + + return txHash; + } + + console.log('error', response); + throw Error(response.rawLog.toString()); +}; + function ActionBar({ stateActionBar }: { stateActionBar: Props }) { const { defaultAccount } = useAppSelector((state: RootState) => state.pocket); const { addressActive } = useSetActiveAddress(defaultAccount); @@ -39,6 +83,7 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { const [errorMessage, setErrorMessage] = useState>(undefined); const { senseApi, ipfsApi } = useBackend(); + const { tokenAmount, tokenSelect, @@ -61,40 +106,19 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { const offerCoin = [coinFunc(amountTokenA, tokenSelect)]; if (addressActive !== null && addressActive.bech32 === address) { - try { - const memoAsCid = !memoValue.match(PATTERN_IPFS_HASH) - ? ((await ipfsApi!.addContent(memoValue)) as string) - : memoValue; - - const response = await signingClient.sendTokens( - address, - recipient, - offerCoin, - 'auto', - memoAsCid - ); - - if (response.code === 0) { - const txHash = response.transactionHash; + await sendTokensWitMessage(address, recipient, offerCoin, memoValue, { + senseApi, + ipfsApi, + signingClient, + }) + .then((txHash) => { setTxHash(txHash); - await senseApi?.addMsgSendAsLocal({ - transactionHash: txHash, - fromAddress: address, - toAddress: recipient, - amount: offerCoin, - memo: memoValue, - }); - } else { + }) + .catch((e) => { setTxHash(undefined); setStage(STAGE_ERROR); - setErrorMessage(response.rawLog.toString()); - } - } catch (error) { - setTxHash(undefined); - setStage(STAGE_ERROR); - console.log('error', error); - setErrorMessage(error.toString()); - } + setErrorMessage(e.toString()); + }); } else { setStage(STAGE_ERROR); setErrorMessage( diff --git a/src/services/backend/workers/background/worker.ts b/src/services/backend/workers/background/worker.ts index 8f063bf55..8dd566090 100644 --- a/src/services/backend/workers/background/worker.ts +++ b/src/services/backend/workers/background/worker.ts @@ -135,7 +135,7 @@ const createBackgroundWorkerApi = () => { }; const backgroundWorker = createBackgroundWorkerApi(); - +export type IpfsApi = typeof backgroundWorker.ipfsApi; export type BackgroundWorker = typeof backgroundWorker; // Expose the API to the main thread as shared/regular worker From f7d252bdc20e61050bc8dae029c43133967c1915 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 13 Mar 2024 12:16:58 +0530 Subject: [PATCH 04/39] improve button --- .../sense/ui/SenseButton/SenseButton.module.scss | 1 - src/features/sense/ui/SenseButton/SenseButton.tsx | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/features/sense/ui/SenseButton/SenseButton.module.scss b/src/features/sense/ui/SenseButton/SenseButton.module.scss index 697d5e278..5bbbc49a8 100644 --- a/src/features/sense/ui/SenseButton/SenseButton.module.scss +++ b/src/features/sense/ui/SenseButton/SenseButton.module.scss @@ -15,7 +15,6 @@ font-size: 14px; margin-top: 5px; color: white; - // filter: drop-shadow(0px 0px 5px #00c4ff); &:last-of-type { margin-top: 4px; diff --git a/src/features/sense/ui/SenseButton/SenseButton.tsx b/src/features/sense/ui/SenseButton/SenseButton.tsx index f288f8730..592bd523f 100644 --- a/src/features/sense/ui/SenseButton/SenseButton.tsx +++ b/src/features/sense/ui/SenseButton/SenseButton.tsx @@ -14,26 +14,14 @@ function SenseButton({ className }: Props) { const { particles, neurons } = useAppSelector(selectUnreadCounts); const total = particles + neurons; - // if (!total) { - // return null; - // } - return ( - {/* - {unreadCounts.neurons} - - - {unreadCounts.particles} - */} - - {total} + {total || ''} 🧬 - {/* all */} ); } From a01577c273753dab8ed6c76a6c14cb79ef47222e Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 13 Mar 2024 12:31:44 +0530 Subject: [PATCH 05/39] lock sense filters --- .../sense/ui/SenseList/SenseList.module.scss | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/features/sense/ui/SenseList/SenseList.module.scss b/src/features/sense/ui/SenseList/SenseList.module.scss index ac25a0639..80ab749d3 100644 --- a/src/features/sense/ui/SenseList/SenseList.module.scss +++ b/src/features/sense/ui/SenseList/SenseList.module.scss @@ -27,6 +27,24 @@ padding: 10px; min-height: 62px; display: flex; + position: sticky; + top: 0; + z-index: 1; + + &::before { + $blur: 12px; + + content: ''; + position: absolute; + background-color: black; + z-index: -1; + width: 100%; + height: 100%; + left: 0; + top: -$blur; + + filter: blur($blur); + } > * { margin: auto; From f305d7abf7d438a91840600f7deda7c00b4451b5 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 13 Mar 2024 13:55:18 +0530 Subject: [PATCH 06/39] send and follow buttons --- src/pages/robot/Layout/WrappedActionBar.tsx | 93 +++++++------------ .../account/{actionBar.jsx => actionBar.tsx} | 81 +++++++++++++--- 2 files changed, 99 insertions(+), 75 deletions(-) rename src/pages/robot/_refactor/account/{actionBar.jsx => actionBar.tsx} (85%) diff --git a/src/pages/robot/Layout/WrappedActionBar.tsx b/src/pages/robot/Layout/WrappedActionBar.tsx index 45ad788e2..3b5acdd96 100644 --- a/src/pages/robot/Layout/WrappedActionBar.tsx +++ b/src/pages/robot/Layout/WrappedActionBar.tsx @@ -1,83 +1,56 @@ -import { useEffect, useState } from 'react'; -import { useSelector } from 'react-redux'; -import { useLocation } from 'react-router-dom'; +import { useCallback, useEffect, useState } from 'react'; +import { useParams } from 'react-router-dom'; import ActionBarContainer from 'src/pages/robot/_refactor/account/actionBar'; -import { RootState } from 'src/redux/store'; -import { chekFollow } from 'src/utils/search/utils'; +import { chekFollow as checkFollow } from 'src/utils/search/utils'; import { getIpfsHash } from 'src/utils/ipfs/helpers'; import { useRobotContext } from '../robot.context'; import { ActionBar } from 'src/components'; +import { useAppSelector } from 'src/redux/hooks'; function WrappedActionBar() { - const { defaultAccount } = useSelector((state: RootState) => state.pocket); - - const location = useLocation(); - const tab = location.pathname.split('/')[2]; + const { defaultAccount } = useAppSelector((state) => state.pocket); + const activeAddress = defaultAccount.account?.cyber.bech32; + const params = useParams(); + const tab = params['*']; const { address, refetchData } = useRobotContext(); const [tweets, setTweets] = useState(false); const [follow, setFollow] = useState(false); - const [activeAddress, setActiveAddress] = useState(null); - - const chekFollowAddress = async () => { - if (!address) { + const checkFollowAddress = useCallback(async () => { + if (!address || !activeAddress || activeAddress === address) { return; } + const addressFromIpfs = await getIpfsHash(address); - if (defaultAccount.account !== null && defaultAccount.account.cyber) { - const response = await chekFollow( - defaultAccount.account.cyber.bech32, - addressFromIpfs - ); + const response = await checkFollow(activeAddress, addressFromIpfs); - if ( - response !== null && - response.total_count > 0 && - defaultAccount.account.cyber.bech32 !== address - ) { - setFollow(false); - setTweets(false); - } + if (response && Number(response.total_count) === 0) { + setFollow(true); + // setTweets(false); } - }; + }, [activeAddress, address]); useEffect(() => { - chekFollowAddress(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [defaultAccount.name, address]); + checkFollowAddress(); + }, [checkFollowAddress]); useEffect(() => { - const chekAddress = async () => { - const { account } = defaultAccount; - if ( - account !== null && - Object.prototype.hasOwnProperty.call(account, 'cyber') - ) { - const { keys } = account.cyber; - if (keys !== 'read-only') { - if (account.cyber.bech32 === address) { - setFollow(false); - setTweets(true); - setActiveAddress({ ...account.cyber }); - } else { - setFollow(true); - setTweets(false); - setActiveAddress({ ...account.cyber }); - } - } else { - setActiveAddress(null); - } - } else { - setActiveAddress(null); - } - }; - chekAddress(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [defaultAccount.name, address]); + if (defaultAccount.account?.cyber.keys === 'read-only') { + return; + } + + if (address === activeAddress) { + setTweets(true); + } else { + setTweets(false); + } + + setFollow(false); + }, [defaultAccount, address, activeAddress]); return (
- {activeAddress !== null ? ( + {activeAddress ? ( { refetchData(); if (follow) { - chekFollowAddress(); + checkFollowAddress(); } }} addressSend={address} type={tab} follow={follow} tweets={tweets} - defaultAccount={activeAddress} + defaultAccount={defaultAccount.account?.cyber} /> ) : ( diff --git a/src/pages/robot/_refactor/account/actionBar.jsx b/src/pages/robot/_refactor/account/actionBar.tsx similarity index 85% rename from src/pages/robot/_refactor/account/actionBar.jsx rename to src/pages/robot/_refactor/account/actionBar.tsx index 6578d9eb1..555d68cd8 100644 --- a/src/pages/robot/_refactor/account/actionBar.jsx +++ b/src/pages/robot/_refactor/account/actionBar.tsx @@ -26,6 +26,10 @@ import { getTotalRewards, getTxs } from '../../../../utils/search/utils'; import Button from 'src/components/btnGrd'; import withIpfsAndKeplr from '../../../../hocs/withIpfsAndKeplr'; +import { CID_FOLLOW, CID_TWEET } from 'src/constants/app'; +import { routes } from 'src/routes'; +import { createSearchParams } from 'react-router-dom'; +import { AccountValue } from 'src/types/defaultAccount'; const { DIVISOR_CYBER_G } = CYBER; @@ -39,8 +43,24 @@ const { STAGE_ERROR, } = LEDGER; -class ActionBarContainer extends Component { - constructor(props) { +type Props = { + defaultAccount: AccountValue; + + type: string; + + addressSend: string; + + // can be followed + follow: boolean; + tweets: boolean; + + updateAddress: () => void; + + // add more +}; + +class ActionBarContainer extends Component { + constructor(props: Props) { super(props); this.state = { stage: STAGE_INIT, @@ -125,15 +145,21 @@ class ActionBarContainer extends Component { } } } else if (type === 'log' && follow) { - // TODO: REFACT need to just get cid of 'follow' instead of pin - const fromCid = await ipfsApi.addContent('follow'); const toCid = await ipfsApi.addContent(addressSend); - response = await signingClient.cyberlink(address, fromCid, toCid, fee); - } else if (type === 'log' && tweets) { - // TODO: REFACT need to just get cid of 'tweet' instead of pin - const fromCid = await ipfsApi.addContent('tweet'); + response = await signingClient.cyberlink( + address, + CID_FOLLOW, + toCid, + fee + ); + } else if ((type === 'log' || !type) && tweets) { const toCid = await this.calculationIpfsTo(contentHash); - response = await signingClient.cyberlink(address, fromCid, toCid, fee); + response = await signingClient.cyberlink( + address, + CID_TWEET, + toCid, + fee + ); } else { msg.push({ type: 'cosmos-sdk/MsgSend', @@ -145,7 +171,6 @@ class ActionBarContainer extends Component { }); } - console.log(`response`, response); if (response.code === 0) { const hash = response.transactionHash; console.log('hash :>> ', hash); @@ -264,14 +289,40 @@ class ActionBarContainer extends Component { file, } = this.state; - if (stage === STAGE_INIT && type === 'log' && follow) { - return ( - this.onClickSend(e) }} - /> + if (stage === STAGE_INIT) { + const sendBtn = ( + ); + const followBtn = ; + + const content = []; + + // main page + if (!type && addressSend !== defaultAccount.bech32) { + content.push(sendBtn); + } + + if ((type === 'log' || !type) && follow) { + content.push(followBtn); + } + + return {content}; } + // TODO: continue refactoring + if (stage === STAGE_INIT && type === 'log' && tweets) { return ( Date: Wed, 13 Mar 2024 14:20:58 +0530 Subject: [PATCH 07/39] fix logic --- src/pages/robot/Layout/WrappedActionBar.tsx | 2 ++ src/pages/robot/_refactor/account/actionBar.tsx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/robot/Layout/WrappedActionBar.tsx b/src/pages/robot/Layout/WrappedActionBar.tsx index 3b5acdd96..8e9fad929 100644 --- a/src/pages/robot/Layout/WrappedActionBar.tsx +++ b/src/pages/robot/Layout/WrappedActionBar.tsx @@ -31,6 +31,8 @@ function WrappedActionBar() { if (response && Number(response.total_count) === 0) { setFollow(true); // setTweets(false); + } else { + setFollow(false); } }, [activeAddress, address]); diff --git a/src/pages/robot/_refactor/account/actionBar.tsx b/src/pages/robot/_refactor/account/actionBar.tsx index 555d68cd8..8b2726dd9 100644 --- a/src/pages/robot/_refactor/account/actionBar.tsx +++ b/src/pages/robot/_refactor/account/actionBar.tsx @@ -144,7 +144,7 @@ class ActionBarContainer extends Component { ); } } - } else if (type === 'log' && follow) { + } else if ((type === 'log' || !type) && follow) { const toCid = await ipfsApi.addContent(addressSend); response = await signingClient.cyberlink( address, @@ -152,7 +152,7 @@ class ActionBarContainer extends Component { toCid, fee ); - } else if ((type === 'log' || !type) && tweets) { + } else if (type === 'log' && tweets) { const toCid = await this.calculationIpfsTo(contentHash); response = await signingClient.cyberlink( address, From 13abc0ffd9fc959c9bd5f815ffdbdeea071f3e63 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 13 Mar 2024 14:32:33 +0530 Subject: [PATCH 08/39] fix sorting --- src/features/sense/redux/sense.redux.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/sense/redux/sense.redux.ts b/src/features/sense/redux/sense.redux.ts index 9e9eb362b..ae5b2ab37 100644 --- a/src/features/sense/redux/sense.redux.ts +++ b/src/features/sense/redux/sense.redux.ts @@ -88,7 +88,7 @@ function formatApiData(item: SenseListItem): SenseItem { const { meta } = item; const formatted: SenseItem = { - timestamp: meta.timestamp, + timestamp: new Date(meta.timestamp).toISOString(), // lol transactionHash: From b9b95e754b8974b341b5d4fb5aac73a44da74f80 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 13 Mar 2024 14:33:35 +0530 Subject: [PATCH 09/39] add initial load data --- src/features/sense/ui/Sense.tsx | 13 +++++- src/features/sense/ui/SenseList/SenseList.tsx | 44 +++++++++---------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/features/sense/ui/Sense.tsx b/src/features/sense/ui/Sense.tsx index 5c1d97341..a3f505c46 100644 --- a/src/features/sense/ui/Sense.tsx +++ b/src/features/sense/ui/Sense.tsx @@ -6,7 +6,10 @@ import { useAdviser } from 'src/features/adviser/context'; import { useAppDispatch, useAppSelector } from 'src/redux/hooks'; import ActionBar from './ActionBar/ActionBar'; import { useBackend } from 'src/contexts/backend/backend'; -import { getSenseChat } from 'src/features/sense/redux/sense.redux'; +import { + getSenseChat, + getSenseList, +} from 'src/features/sense/redux/sense.redux'; import { useNavigate, useParams } from 'react-router-dom'; import { convertTimestampToString } from 'src/utils/date'; @@ -95,6 +98,14 @@ function Sense({ urlSenseId }: { urlSenseId?: string }) { setAdviserText: (text: string) => setAdviserText(text), }; + useEffect(() => { + if (!senseApi) { + return; + } + + dispatch(getSenseList(senseApi)); + }, [dispatch, senseApi]); + function update() { // dispatch(getSenseList(senseApi)); // dispatch( diff --git a/src/features/sense/ui/SenseList/SenseList.tsx b/src/features/sense/ui/SenseList/SenseList.tsx index 2008279d8..929a8626d 100644 --- a/src/features/sense/ui/SenseList/SenseList.tsx +++ b/src/features/sense/ui/SenseList/SenseList.tsx @@ -63,30 +63,28 @@ function SenseList({ select, selected }: Props) {
) : items.length ? (
    - {items - // .slice(0, 4) - .map((id) => { - return ( -
  • { + return ( +
  • + -
  • - ); - })} + + + + ); + })}
) : (

no {getFilterText(filter)} chats

From 428f2bf01fa9f5051150f0e740d457f40a8d9cb9 Mon Sep 17 00:00:00 2001 From: dasein Date: Wed, 13 Mar 2024 14:37:47 +0530 Subject: [PATCH 10/39] refactor(sense): split user actions from components --- src/features/sense/ui/ActionBar/ActionBar.tsx | 58 ++++-------- src/pages/teleport/send/actionBar.send.tsx | 62 +++---------- .../backend/workers/background/worker.ts | 2 +- src/services/user/userApi.ts | 91 +++++++++++++++++++ 4 files changed, 123 insertions(+), 90 deletions(-) create mode 100644 src/services/user/userApi.ts diff --git a/src/features/sense/ui/ActionBar/ActionBar.tsx b/src/features/sense/ui/ActionBar/ActionBar.tsx index 4a7390f6f..c89c7f57b 100644 --- a/src/features/sense/ui/ActionBar/ActionBar.tsx +++ b/src/features/sense/ui/ActionBar/ActionBar.tsx @@ -14,6 +14,11 @@ import { useBackend } from 'src/contexts/backend/backend'; import { routes } from 'src/routes'; import { Link, createSearchParams } from 'react-router-dom'; import { ibcDenomAtom } from 'src/pages/teleport/bridge/bridge'; +import { + addIfpsMessageOrCid, + sendCyberlink, + sendTokensWithMessage, +} from 'src/services/user/userApi'; type Props = { id: string | undefined; @@ -95,37 +100,22 @@ function ActionBarWrapper({ id, adviser }: Props) { const formattedAmount = [coin(amount || 1, CYBER.DENOM_CYBER)]; - const messageCid = !message.match(PATTERN_IPFS_HASH) - ? ((await ipfsApi.addContent(message)) as string) - : message; + const messageCid = await addIfpsMessageOrCid(message, { ipfsApi }); - let response; - - if (particle) { - const fromCid = messageCid; - const toCid = id; - - const fee = { - amount: [], - gas: DEFAULT_GAS_LIMITS.toString(), - }; - - response = await signingClient!.cyberlink(address, fromCid, toCid, fee); - } else { - response = await signingClient!.sendTokens( - address, - id!, - formattedAmount, - 'auto', - messageCid - ); - } - - if (response.code !== 0) { - throw new Error(response.rawLog); - } + const deps = { + senseApi, + signingClient: signingClient!, + }; - const txHash = response.transactionHash; + const txHash = await (particle + ? sendCyberlink(address, messageCid, id, deps) + : sendTokensWithMessage( + address, + id!, + formattedAmount, + messageCid, + deps + )); const optimisticMessage = { id: id!, @@ -153,16 +143,6 @@ function ActionBarWrapper({ id, adviser }: Props) { amount: formattedAmount, }; optimisticMessage.item.type = 'cyber.graph.v1beta1.MsgSend'; - - (async () => { - await senseApi?.addMsgSendAsLocal({ - transactionHash: txHash, - fromAddress: address, - toAddress: id!, - amount: formattedAmount, - memo: messageCid, - }); - })(); } dispatch(addSenseItem(optimisticMessage)); diff --git a/src/pages/teleport/send/actionBar.send.tsx b/src/pages/teleport/send/actionBar.send.tsx index 438450ee1..179907fe3 100644 --- a/src/pages/teleport/send/actionBar.send.tsx +++ b/src/pages/teleport/send/actionBar.send.tsx @@ -1,4 +1,4 @@ -import { useCallback, useState } from 'react'; +import { useState } from 'react'; import BigNumber from 'bignumber.js'; import useSetActiveAddress from 'src/hooks/useSetActiveAddress'; import { useSigningClient } from 'src/contexts/signerClient'; @@ -7,16 +7,18 @@ import { Coin } from '@cosmjs/launchpad'; import { useIbcDenom } from 'src/contexts/ibcDenom'; import { RootState } from 'src/redux/store'; import { useAppSelector } from 'src/redux/hooks'; -import { Account, ActionBar as ActionBarCenter } from '../../../components'; -import { LEDGER, PATTERN_IPFS_HASH } from '../../../utils/config'; +import { useBackend } from 'src/contexts/backend/backend'; +import { + addIfpsMessageOrCid, + sendTokensWithMessage, +} from 'src/services/user/userApi'; import { convertAmountReverce } from '../../../utils/utils'; +import { LEDGER } from '../../../utils/config'; + +import { Account, ActionBar as ActionBarCenter } from '../../../components'; + import ActionBarPingTxs from '../components/actionBarPingTxs'; -import { useBackend } from 'src/contexts/backend/backend'; -import { set } from 'lodash'; -import { SigningCyberClient } from '@cybercongress/cyber-js'; -import { SenseApi } from 'src/contexts/backend/services/senseApi'; -import { IpfsApi } from 'src/services/backend/workers/background/worker'; const { STAGE_INIT, STAGE_ERROR, STAGE_SUBMITTED } = LEDGER; @@ -33,46 +35,6 @@ type Props = { memoValue: string; }; -const sendTokensWitMessage = async ( - address: string, - recipient: string, - offerCoin: Coin[], - memo: string, - { - senseApi, - ipfsApi, - signingClient, - }: { signingClient: SigningCyberClient; senseApi: SenseApi; ipfsApi: IpfsApi } -) => { - const memoAsCid = !memo.match(PATTERN_IPFS_HASH) - ? ((await ipfsApi!.addContent(memo)) as string) - : memo; - - const response = await signingClient.sendTokens( - address, - recipient, - offerCoin, - 'auto', - memoAsCid - ); - - if (response.code === 0) { - const txHash = response.transactionHash; - await senseApi?.addMsgSendAsLocal({ - transactionHash: txHash, - fromAddress: address, - toAddress: recipient, - amount: offerCoin, - memo: memoAsCid, - }); - - return txHash; - } - - console.log('error', response); - throw Error(response.rawLog.toString()); -}; - function ActionBar({ stateActionBar }: { stateActionBar: Props }) { const { defaultAccount } = useAppSelector((state: RootState) => state.pocket); const { addressActive } = useSetActiveAddress(defaultAccount); @@ -106,9 +68,9 @@ function ActionBar({ stateActionBar }: { stateActionBar: Props }) { const offerCoin = [coinFunc(amountTokenA, tokenSelect)]; if (addressActive !== null && addressActive.bech32 === address) { - await sendTokensWitMessage(address, recipient, offerCoin, memoValue, { + const memo = await addIfpsMessageOrCid(memoValue, { ipfsApi }); + await sendTokensWithMessage(address, recipient, offerCoin, memo, { senseApi, - ipfsApi, signingClient, }) .then((txHash) => { diff --git a/src/services/backend/workers/background/worker.ts b/src/services/backend/workers/background/worker.ts index 8dd566090..1c20715bb 100644 --- a/src/services/backend/workers/background/worker.ts +++ b/src/services/backend/workers/background/worker.ts @@ -135,7 +135,7 @@ const createBackgroundWorkerApi = () => { }; const backgroundWorker = createBackgroundWorkerApi(); -export type IpfsApi = typeof backgroundWorker.ipfsApi; +export type IpfsApi = Remote; export type BackgroundWorker = typeof backgroundWorker; // Expose the API to the main thread as shared/regular worker diff --git a/src/services/user/userApi.ts b/src/services/user/userApi.ts new file mode 100644 index 000000000..4b4c3f270 --- /dev/null +++ b/src/services/user/userApi.ts @@ -0,0 +1,91 @@ +/* eslint-disable import/no-unused-modules */ +import { Coin, StdFee } from '@cosmjs/launchpad'; +import { SigningCyberClient } from '@cybercongress/cyber-js'; +import { SenseApi } from 'src/contexts/backend/services/senseApi'; +import { IpfsApi } from 'src/services/backend/workers/background/worker'; +import { NeuronAddress, ParticleCid } from 'src/types/base'; +import { DEFAULT_GAS_LIMITS, PATTERN_IPFS_HASH } from 'src/utils/config'; + +export const addIfpsMessageOrCid = async ( + message: string | ParticleCid, + { ipfsApi }: { ipfsApi: IpfsApi | null } +) => { + if (!ipfsApi) { + throw Error('IpfsApi is not initialized'); + } + + return ( + !message.match(PATTERN_IPFS_HASH) + ? ((await ipfsApi!.addContent(message)) as string) + : message + ) as ParticleCid; +}; + +export const sendCyberlink = async ( + address: NeuronAddress, + fromCid: ParticleCid, + toCid: ParticleCid, + { + senseApi, + signingClient, + }: { + senseApi: SenseApi; + signingClient: SigningCyberClient; + }, + fee: StdFee = { + amount: [], + gas: DEFAULT_GAS_LIMITS.toString(), + } as StdFee +) => { + const response = await signingClient!.cyberlink(address, fromCid, toCid, fee); + if (response.code === 0) { + const txHash = response.transactionHash; + // await senseApi?.addMsgSendAsLocal({ + // transactionHash: txHash, + // fromAddress: address, + // toAddress: recipient, + // amount: offerCoin, + // memo: memoAsCid, + // }); + + return txHash; + } + + console.log('error', response); + throw Error(response.rawLog.toString()); +}; + +export const sendTokensWithMessage = async ( + address: NeuronAddress, + recipient: string, + offerCoin: Coin[], + memo: string | ParticleCid, + { + senseApi, + signingClient, + }: { signingClient: SigningCyberClient; senseApi: SenseApi } +) => { + const response = await signingClient.sendTokens( + address, + recipient, + offerCoin, + 'auto', + memo + ); + + if (response.code === 0) { + const txHash = response.transactionHash; + await senseApi?.addMsgSendAsLocal({ + transactionHash: txHash, + fromAddress: address, + toAddress: recipient, + amount: offerCoin, + memo, + }); + + return txHash; + } + + console.log('error', response); + throw Error(response.rawLog.toString()); +}; From 8822b792f87547890cc9e8f3fa8f2e8fde6aae0a Mon Sep 17 00:00:00 2001 From: dasein Date: Thu, 14 Mar 2024 13:38:28 +0530 Subject: [PATCH 11/39] feat(sense): neuronApi to handle cozo op links --- src/containers/Search/ActionBarContainer.tsx | 58 ++++------ src/contexts/backend/services/senseApi.ts | 74 +++++++++++- src/features/sense/ui/ActionBar/ActionBar.tsx | 4 +- src/hocs/withIpfsAndKeplr.tsx | 3 +- src/pages/oracle/Learn/Learn.tsx | 49 +++----- .../robot/_refactor/account/actionBar.jsx | 109 +++++++++--------- src/pages/teleport/send/actionBar.send.tsx | 2 +- src/services/CozoDb/mapping.ts | 6 +- .../dataSource/indexedDb/dbApiWrapper.ts | 11 +- .../services/sync/__tests__/utils.test.ts | 7 +- .../SyncMyFriendsLoop/SyncMyFriendsLoop.ts | 4 +- .../SyncParticlesLoop/SyncParticlesLoop.ts | 18 ++- .../SyncTransactionsLoop/services/chat.ts | 2 +- src/services/backend/services/sync/utils.ts | 61 +++++----- .../{user/userApi.ts => neuron/neuronApi.ts} | 45 +++++--- src/utils/logging/bootstrap.ts | 1 + 16 files changed, 255 insertions(+), 199 deletions(-) rename src/services/{user/userApi.ts => neuron/neuronApi.ts} (66%) diff --git a/src/containers/Search/ActionBarContainer.tsx b/src/containers/Search/ActionBarContainer.tsx index b62b884b5..52b935c68 100644 --- a/src/containers/Search/ActionBarContainer.tsx +++ b/src/containers/Search/ActionBarContainer.tsx @@ -1,6 +1,5 @@ /* eslint-disable */ import React, { Component } from 'react'; -import { Link as LinkRoute } from 'react-router-dom'; import { Pane, ActionBar } from '@cybercongress/gravity'; import { connect } from 'react-redux'; import { @@ -15,16 +14,13 @@ import { import { getTxs } from '../../utils/search/utils'; -import { - LEDGER, - CYBER, - PATTERN_IPFS_HASH, - DEFAULT_GAS_LIMITS, -} from '../../utils/config'; +import { LEDGER, PATTERN_IPFS_HASH } from '../../utils/config'; import { trimString } from '../../utils/utils'; import withIpfsAndKeplr from 'src/hocs/withIpfsAndKeplr'; import { DefaultAccount } from 'src/types/defaultAccount'; import { BackgroundWorker } from 'src/services/backend/workers/background/worker'; +import { SenseApi } from 'src/contexts/backend/services/senseApi'; +import { sendCyberlink } from 'src/services/neuron/neuronApi'; const imgKeplr = require('../../image/keplr-icon.svg'); const imgLedger = require('../../image/ledger.svg'); @@ -52,6 +48,7 @@ interface Props { update: () => void; signer: any; ipfsApi: BackgroundWorker['ipfsApi']; + senseApi: SenseApi; signingClient: any; keywordHash: string; } @@ -164,7 +161,7 @@ class ActionBarContainer extends Component { generateTx = async () => { try { - const { signer, signingClient } = this.props; + const { signer, signingClient, senseApi } = this.props; const { fromCid, toCid, addressLocalStor } = this.state; this.setState({ @@ -175,36 +172,23 @@ class ActionBarContainer extends Component { console.log('address', address); if (addressLocalStor !== null && addressLocalStor.address === address) { - const fee = { - amount: [], - gas: DEFAULT_GAS_LIMITS.toString(), - }; - const result = await signingClient.cyberlink( - address, - fromCid, - toCid, - fee - ); - if (result.code === 0) { - const hash = result.transactionHash; - console.log('hash :>> ', hash); - this.setState({ stage: STAGE_SUBMITTED, txHash: hash }); - this.timeOut = setTimeout(this.confirmTx, 1500); - } else if (result.code === 4) { - this.setState({ - txHash: null, - stage: STAGE_ERROR, - errorMessage: - 'Cyberlinking and investmint are not working. Wait for updates.', - }); - } else { - this.setState({ - txHash: null, - stage: STAGE_ERROR, - errorMessage: result.rawLog.toString(), + const txHash = await sendCyberlink(address, fromCid, toCid, { + signingClient, + senseApi, + }) + .then((txHash) => { + console.log('hash :>> ', txHash); + this.setState({ stage: STAGE_SUBMITTED, txHash }); + this.timeOut = setTimeout(this.confirmTx, 1500); + }) + .catch((e) => { + this.setState({ + txHash: null, + stage: STAGE_ERROR, + errorMessage: e.message, + }); + console.log('result: ', e.message, e); }); - } - console.log('result: ', result); } else { this.setState({ stage: STAGE_ERROR, diff --git a/src/contexts/backend/services/senseApi.ts b/src/contexts/backend/services/senseApi.ts index 7b38f9f95..4917279ae 100644 --- a/src/contexts/backend/services/senseApi.ts +++ b/src/contexts/backend/services/senseApi.ts @@ -1,14 +1,23 @@ import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; +import { CID_FOLLOW, CID_TWEET } from 'src/constants/app'; import { isParticle } from 'src/features/particle/utils'; -import { TransactionDto } from 'src/services/CozoDb/types/dto'; +import { + LinkDto, + SyncStatusDto, + TransactionDto, +} from 'src/services/CozoDb/types/dto'; +import { EntryType } from 'src/services/CozoDb/types/entities'; import BroadcastChannelSender from 'src/services/backend/channels/BroadcastChannelSender'; import DbApiWrapper from 'src/services/backend/services/dataSource/indexedDb/dbApiWrapper'; import { + CyberLinkValue, MSG_SEND_TRANSACTION_TYPE, MsgSendValue, } from 'src/services/backend/services/indexer/types'; import { syncMyChats } from 'src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat'; import { SENSE_FRIEND_PARTICLES } from 'src/services/backend/services/sync/services/consts'; +import { changeParticleSyncStatus } from 'src/services/backend/services/sync/utils'; +import { SenseLinkMeta } from 'src/services/backend/types/sense'; import { NeuronAddress, ParticleCid, TransactionHash } from 'src/types/base'; import { EntityToDto } from 'src/types/dto'; import { getNowUtcNumber } from 'src/utils/date'; @@ -21,7 +30,7 @@ type LocalSenseChatMessage = { memo: string; }; -const prepareSenseTransaction = ({ +const prepareSenseMsgSendTransaction = ({ transactionHash, fromAddress, toAddress, @@ -49,6 +58,28 @@ const prepareSenseTransaction = ({ return transaction; }; +const prepareSenseCyberlinkTransaction = (link: LinkDto) => { + const { from, to, neuron, transactionHash, timestamp } = link; + const value = { + neuron, + links: [{ from, to }], + } as EntityToDto; + + const transaction = { + hash: transactionHash, + type: MSG_SEND_TRANSACTION_TYPE, + index: 0, + timestamp, + success: true, + value, + memo: '', + neuron, + blockHeight: -1, + } as TransactionDto; + + return transaction; +}; + export const createSenseApi = ( dbApi: DbApiWrapper, myAddress?: NeuronAddress, @@ -105,7 +136,7 @@ export const createSenseApi = ( This function create syntetic transaction (blockHeight=-1) and create syncItem as well. */ - const transaction = prepareSenseTransaction(msg); + const transaction = prepareSenseMsgSendTransaction(msg); await dbApi.putTransactions([transaction]); const items = await syncMyChats( @@ -117,6 +148,43 @@ export const createSenseApi = ( ); new BroadcastChannelSender().postSenseUpdate(items); }, + addCyberlinkLocal: async (link: LinkDto) => { + const syncItemLinkTo = await dbApi.getSyncStatus(myAddress!, link.to); + const syncItemLinkFrom = await dbApi.getSyncStatus(myAddress!, link.from); + let syncItemLink; + + if (link.from === CID_TWEET) { + syncItemLink = syncItemLinkTo.id + ? syncItemLinkTo + : ({ + ownerId: myAddress!, + id: link.to, + unreadCount: 0, + timestampRead: 0, + timestampUpdate: 0, + meta: { ...link }, + entryType: EntryType.particle, + disabled: false, + } as SyncStatusDto); + } else { + syncItemLink = syncItemLinkFrom.id ? syncItemLinkFrom : syncItemLinkTo; + } + if (!syncItemLink || !syncItemLink.id) { + throw new Error('syncItem not found, and not tweet link'); + } + + const transaction = prepareSenseCyberlinkTransaction(link); + await dbApi.putTransactions([transaction]); + const newItem = changeParticleSyncStatus( + syncItemLink, + [link], + myAddress!, + false + ); + await dbApi.putSyncStatus(newItem); + new BroadcastChannelSender().postSenseUpdate([newItem]); + }, + putCyberlinsks: (links: LinkDto | LinkDto[]) => dbApi.putCyberlinks(links), getTransactions: (neuron: NeuronAddress) => dbApi.getTransactions(neuron), getFriendItems: async (userAddress: NeuronAddress) => { if (!myAddress) { diff --git a/src/features/sense/ui/ActionBar/ActionBar.tsx b/src/features/sense/ui/ActionBar/ActionBar.tsx index c89c7f57b..d0062c526 100644 --- a/src/features/sense/ui/ActionBar/ActionBar.tsx +++ b/src/features/sense/ui/ActionBar/ActionBar.tsx @@ -5,7 +5,7 @@ import { useAppDispatch, useAppSelector } from 'src/redux/hooks'; import { selectCurrentAddress } from 'src/redux/features/pocket'; import useWaitForTransaction from 'src/hooks/useWaitForTransaction'; import { AdviserProps } from '../Sense'; -import { CYBER, DEFAULT_GAS_LIMITS, PATTERN_IPFS_HASH } from 'src/utils/config'; +import { CYBER } from 'src/utils/config'; import { coin } from '@cosmjs/launchpad'; import { addSenseItem, updateSenseItem } from '../../redux/sense.redux'; import styles from './ActionBar.module.scss'; @@ -18,7 +18,7 @@ import { addIfpsMessageOrCid, sendCyberlink, sendTokensWithMessage, -} from 'src/services/user/userApi'; +} from 'src/services/neuron/neuronApi'; type Props = { id: string | undefined; diff --git a/src/hocs/withIpfsAndKeplr.tsx b/src/hocs/withIpfsAndKeplr.tsx index 3074ad746..3d06e5638 100644 --- a/src/hocs/withIpfsAndKeplr.tsx +++ b/src/hocs/withIpfsAndKeplr.tsx @@ -2,7 +2,7 @@ import { useBackend } from 'src/contexts/backend/backend'; import { useSigningClient } from 'src/contexts/signerClient'; const withIpfsAndKeplr = (Component) => (props) => { - const { ipfsApi } = useBackend(); + const { ipfsApi, senseApi } = useBackend(); const { signer, signingClient } = useSigningClient(); return ( @@ -11,6 +11,7 @@ const withIpfsAndKeplr = (Component) => (props) => { ipfsApi={ipfsApi} signer={signer} signingClient={signingClient} + senseApi={senseApi} /> ); }; diff --git a/src/pages/oracle/Learn/Learn.tsx b/src/pages/oracle/Learn/Learn.tsx index 59f33cb0b..63d373dc4 100644 --- a/src/pages/oracle/Learn/Learn.tsx +++ b/src/pages/oracle/Learn/Learn.tsx @@ -8,7 +8,7 @@ import { } from 'src/components'; import { routes } from 'src/routes'; import { useEffect, useState } from 'react'; -import { CYBER, DEFAULT_GAS_LIMITS, PATTERN_IPFS_HASH } from 'src/utils/config'; +import { CYBER } from 'src/utils/config'; import { useAdviser } from 'src/features/adviser/context'; import { useQueryClient } from 'src/contexts/queryClient'; import { selectCurrentAddress } from 'src/redux/features/pocket'; @@ -19,10 +19,14 @@ import { selectCurrentPassport } from 'src/features/passport/passports.redux'; import { Networks } from 'src/types/networks'; import useGetSlots from 'src/containers/mint/useGetSlots'; import { AdviserColors } from 'src/features/adviser/Adviser/Adviser'; -import KeywordButton from '../landing/components/KeywordButton/KeywordButton'; -import styles from './Learn.module.scss'; import { useBackend } from 'src/contexts/backend/backend'; +import { + addIfpsMessageOrCid, + sendCyberlink, +} from 'src/services/neuron/neuronApi'; import TitleText from '../landing/components/TitleText/TitleText'; +import KeywordButton from '../landing/components/KeywordButton/KeywordButton'; +import styles from './Learn.module.scss'; const learningListConfig = [ { @@ -43,11 +47,6 @@ const learningListConfig = [ }, ]; -const fee = { - amount: [], - gas: DEFAULT_GAS_LIMITS.toString(), -}; - function Learn() { const [ask, setAsk] = useState(''); const [answer, setAnswer] = useState(''); @@ -55,7 +54,7 @@ function Learn() { const [loading, setLoading] = useState(false); const [error, setError] = useState(); - const { isIpfsInitialized, ipfsApi } = useBackend(); + const { isIpfsInitialized, ipfsApi, senseApi } = useBackend(); const queryClient = useQueryClient(); @@ -141,41 +140,29 @@ function Learn() { try { setLoading(true); - let fromCid = ask; - if (!ask.match(PATTERN_IPFS_HASH)) { - fromCid = await ipfsApi?.addContent(ask); - } - - let toCid = answer; - if (!answer.match(PATTERN_IPFS_HASH)) { - toCid = await ipfsApi?.addContent(answer); - } - const result = await signingClient.cyberlink( - address, - fromCid, - toCid, - fee - ); + const fromCid = await addIfpsMessageOrCid(ask, { ipfsApi }); + const toCid = await addIfpsMessageOrCid(answer, { ipfsApi }); - if (result.code !== 0) { - throw new Error(result.rawLog); - } + const txHash = await sendCyberlink(address, fromCid, toCid, { + signingClient, + senseApi, + }); setTx({ - hash: result.transactionHash, + hash: txHash, onSuccess: () => { navigate(routes.ipfs.getLink(toCid)); }, }); - } catch (error) { + } catch (e) { // better use code of error - if (error.message === 'Request rejected') { + if (e.message === 'Request rejected') { return; } console.error(error); - setError(error.message); + setError(e.message); } finally { setLoading(false); } diff --git a/src/pages/robot/_refactor/account/actionBar.jsx b/src/pages/robot/_refactor/account/actionBar.jsx index 6578d9eb1..8dd9a323d 100644 --- a/src/pages/robot/_refactor/account/actionBar.jsx +++ b/src/pages/robot/_refactor/account/actionBar.jsx @@ -1,8 +1,6 @@ /* eslint-disable */ import React, { Component } from 'react'; -import { Pane, ActionBar } from '@cybercongress/gravity'; -import { connect } from 'react-redux'; -import { coins } from '@cosmjs/launchpad'; +import { ActionBar } from '@cybercongress/gravity'; import { JsonTransaction, TransactionSubmitted, @@ -24,8 +22,9 @@ import { import { getTotalRewards, getTxs } from '../../../../utils/search/utils'; -import Button from 'src/components/btnGrd'; import withIpfsAndKeplr from '../../../../hocs/withIpfsAndKeplr'; +import { sendCyberlink } from 'src/services/neuron/neuronApi'; +import { CID_FOLLOW, CID_TWEET } from 'src/constants/app'; const { DIVISOR_CYBER_G } = CYBER; @@ -88,6 +87,7 @@ class ActionBarContainer extends Component { signer, signingClient, ipfsApi, + senseApi, } = this.props; const amount = parseFloat(toSend) * DIVISOR_CYBER_G; const fee = { @@ -97,65 +97,64 @@ class ActionBarContainer extends Component { if (signer && signingClient) { const [{ address }] = await signer.getAccounts(); - let response = null; - const msg = []; - if (type === 'security') { - if (address === addressSend) { - const dataTotalRewards = await getTotalRewards(address); - console.log(`dataTotalRewards`, dataTotalRewards); - if (dataTotalRewards !== null && dataTotalRewards.rewards) { - const { rewards } = dataTotalRewards; - const validatorAddress = []; - Object.keys(rewards).forEach((key) => { - if (rewards[key].reward !== null) { - validatorAddress.push(rewards[key].validator_address); + try { + let txHash = null; + + if (type === 'security') { + if (address === addressSend) { + const dataTotalRewards = await getTotalRewards(address); + console.log(`dataTotalRewards`, dataTotalRewards); + if (dataTotalRewards !== null && dataTotalRewards.rewards) { + const { rewards } = dataTotalRewards; + const validatorAddress = []; + Object.keys(rewards).forEach((key) => { + if (rewards[key].reward !== null) { + validatorAddress.push(rewards[key].validator_address); + } + }); + const gasLimitsRewards = + 100000 * Object.keys(validatorAddress).length; + const feeRewards = { + amount: [], + gas: gasLimitsRewards.toString(), + }; + + response = await signingClient.withdrawAllRewards( + address, + validatorAddress, + feeRewards + ); + + txHash = response.transactionHash; + + if (response.code) { + throw Error(response.rawLog.toString()); } + } + } + } else if (type === 'log') { + if (follow) { + const toCid = await ipfsApi.addContent(addressSend); + txHash = await sendCyberlink(address, CID_FOLLOW, toCid, { + signingClient, + senseApi, + }); + } else if (tweets) { + const toCid = await this.calculationIpfsTo(contentHash); + txHash = await sendCyberlink(address, CID_TWEET, toCid, { + signingClient, + senseApi, }); - const gasLimitsRewards = - 100000 * Object.keys(validatorAddress).length; - const feeRewards = { - amount: [], - gas: gasLimitsRewards.toString(), - }; - response = await signingClient.withdrawAllRewards( - address, - validatorAddress, - feeRewards - ); } } - } else if (type === 'log' && follow) { - // TODO: REFACT need to just get cid of 'follow' instead of pin - const fromCid = await ipfsApi.addContent('follow'); - const toCid = await ipfsApi.addContent(addressSend); - response = await signingClient.cyberlink(address, fromCid, toCid, fee); - } else if (type === 'log' && tweets) { - // TODO: REFACT need to just get cid of 'tweet' instead of pin - const fromCid = await ipfsApi.addContent('tweet'); - const toCid = await this.calculationIpfsTo(contentHash); - response = await signingClient.cyberlink(address, fromCid, toCid, fee); - } else { - msg.push({ - type: 'cosmos-sdk/MsgSend', - value: { - amount: coins(amount, CYBER.DENOM_CYBER), - from_address: address, - to_address: toSendAddres, - }, - }); - } - - console.log(`response`, response); - if (response.code === 0) { - const hash = response.transactionHash; - console.log('hash :>> ', hash); - this.setState({ stage: STAGE_SUBMITTED, txHash: hash }); + console.log('hash :>> ', txHash); + this.setState({ stage: STAGE_SUBMITTED, txHash }); this.timeOut = setTimeout(this.confirmTx, 1500); - } else { + } catch (e) { this.setState({ txHash: null, stage: STAGE_ERROR, - errorMessage: response.rawLog.toString(), + errorMessage: e.message, }); } } diff --git a/src/pages/teleport/send/actionBar.send.tsx b/src/pages/teleport/send/actionBar.send.tsx index 179907fe3..69527172c 100644 --- a/src/pages/teleport/send/actionBar.send.tsx +++ b/src/pages/teleport/send/actionBar.send.tsx @@ -11,7 +11,7 @@ import { useBackend } from 'src/contexts/backend/backend'; import { addIfpsMessageOrCid, sendTokensWithMessage, -} from 'src/services/user/userApi'; +} from 'src/services/neuron/neuronApi'; import { convertAmountReverce } from '../../../utils/utils'; import { LEDGER } from '../../../utils/config'; diff --git a/src/services/CozoDb/mapping.ts b/src/services/CozoDb/mapping.ts index 6a57c3042..54f5a7939 100644 --- a/src/services/CozoDb/mapping.ts +++ b/src/services/CozoDb/mapping.ts @@ -91,16 +91,16 @@ export const mapLinkToEntity = ( timestamp, }); -export const mapLinkFromIndexerToDbEntity = ({ +export const mapLinkFromIndexerToDto = ({ from, to, neuron, timestamp, transaction_hash, -}: CyberlinksByParticleResponse['cyberlinks'][0]): LinkDbEntity => ({ +}: CyberlinksByParticleResponse['cyberlinks'][0]): LinkDto => ({ from, to, neuron, timestamp: dateToUtcNumber(timestamp), - transaction_hash, + transactionHash: transaction_hash, }); diff --git a/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts b/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts index 57aedcc40..524d48b81 100644 --- a/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts +++ b/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts @@ -64,10 +64,8 @@ class DbApiWrapper { : defaultSyncStatus; } - public async putSyncStatus(entity: SyncStatusDto[] | SyncStatusDto) { - const entitites = dtoListToEntity( - Array.isArray(entity) ? entity : [entity] - ); + public async putSyncStatus(item: SyncStatusDto[] | SyncStatusDto) { + const entitites = dtoListToEntity(Array.isArray(item) ? item : [item]); const result = await this.db!.executePutCommand('sync_status', entitites); return result; @@ -232,8 +230,9 @@ class DbApiWrapper { return userChats ? userChats.transactions : []; } - public async putCyberlinks(links: LinkDbEntity[] | LinkDbEntity) { - const entitites = Array.isArray(links) ? links : [links]; + public async putCyberlinks(links: LinkDto[] | LinkDto) { + const entitites = dtoListToEntity(Array.isArray(links) ? links : [links]); + console.log('putCyberlinks', links, entitites); return this.db!.executePutCommand('link', entitites); } diff --git a/src/services/backend/services/sync/__tests__/utils.test.ts b/src/services/backend/services/sync/__tests__/utils.test.ts index 91caf8e86..bae112097 100644 --- a/src/services/backend/services/sync/__tests__/utils.test.ts +++ b/src/services/backend/services/sync/__tests__/utils.test.ts @@ -1,6 +1,6 @@ import { CID_TWEET } from 'src/constants/app'; -import { extractLinkData, changeSyncStatus } from '../utils'; +import { extractLinkData, changeParticleSyncStatus } from '../utils'; import { extractCybelinksFromTransaction } from '../services/utils/links'; import { CYBER_LINK_TRANSACTION_TYPE } from '../../indexer/types'; @@ -162,7 +162,10 @@ test('updateSyncState should return the expected result', () => { unreadCount: 5, timestampRead: 1641753000000, }; - const result = changeSyncStatus(mockStatusEntity, mockCyberlinks.cyberlinks); + const result = changeParticleSyncStatus( + mockStatusEntity, + mockCyberlinks.cyberlinks + ); console.log(result); expect(result.lastId).toEqual('from_cid_1'); diff --git a/src/services/backend/services/sync/services/SyncMyFriendsLoop/SyncMyFriendsLoop.ts b/src/services/backend/services/sync/services/SyncMyFriendsLoop/SyncMyFriendsLoop.ts index 84f18f101..d000f031f 100644 --- a/src/services/backend/services/sync/services/SyncMyFriendsLoop/SyncMyFriendsLoop.ts +++ b/src/services/backend/services/sync/services/SyncMyFriendsLoop/SyncMyFriendsLoop.ts @@ -12,7 +12,7 @@ import { NeuronAddress } from 'src/types/base'; import { QueuePriority } from 'src/services/QueueManager/types'; import { isAbortException } from 'src/utils/exceptions/helpers'; -import { mapLinkFromIndexerToDbEntity } from 'src/services/CozoDb/mapping'; +import { mapLinkFromIndexerToDto } from 'src/services/CozoDb/mapping'; import { throwIfAborted } from 'src/utils/async/promise'; import { SyncEntryName } from 'src/services/backend/types/services'; @@ -154,7 +154,7 @@ class SyncMyFriendsLoop extends BaseSyncLoop { this.progressTracker.trackProgress(1) ); - const links = linksBatch.map(mapLinkFromIndexerToDbEntity); + const links = linksBatch.map(mapLinkFromIndexerToDto); const { timestampRead: newTimestampRead, unreadCount: newUnreadCount } = getLastReadInfo(linksBatch, myAddress, timestampRead, unreadCount); diff --git a/src/services/backend/services/sync/services/SyncParticlesLoop/SyncParticlesLoop.ts b/src/services/backend/services/sync/services/SyncParticlesLoop/SyncParticlesLoop.ts index bc56bd332..1f13113a9 100644 --- a/src/services/backend/services/sync/services/SyncParticlesLoop/SyncParticlesLoop.ts +++ b/src/services/backend/services/sync/services/SyncParticlesLoop/SyncParticlesLoop.ts @@ -4,7 +4,7 @@ import { SyncStatusDto } from 'src/services/CozoDb/types/dto'; import { QueuePriority } from 'src/services/QueueManager/types'; import { NeuronAddress } from 'src/types/base'; -import { mapLinkFromIndexerToDbEntity } from 'src/services/CozoDb/mapping'; +import { mapLinkFromIndexerToDto } from 'src/services/CozoDb/mapping'; import { CID_TWEET } from 'src/constants/app'; import { dateToUtcNumber } from 'src/utils/date'; import { SenseListItem } from 'src/services/backend/types/sense'; @@ -15,7 +15,7 @@ import { entityToDto } from 'src/utils/dto'; import { ServiceDeps } from '../types'; import { fetchCyberlinksAndResolveParticles } from '../utils/links'; -import { changeSyncStatus } from '../../utils'; +import { changeParticleSyncStatus } from '../../utils'; import { fetchCyberlinksByNerounIterable, fetchCyberlinksCount, @@ -160,7 +160,7 @@ class SyncParticlesLoop extends BaseSyncLoop { ); // eslint-disable-next-line no-await-in-loop - const links = await fetchCyberlinksAndResolveParticles( + const linksIndexer = await fetchCyberlinksAndResolveParticles( id, timestampUpdate, this.particlesResolver!, @@ -168,20 +168,18 @@ class SyncParticlesLoop extends BaseSyncLoop { this.abortController?.signal ); - if (links.length > 0) { + if (linksIndexer.length > 0) { + const links = linksIndexer.map(mapLinkFromIndexerToDto); + // save links // eslint-disable-next-line no-await-in-loop await asyncIterableBatchProcessor( links, - (links) => - throwIfAborted( - this.db!.putCyberlinks, - signal - )(links.map(mapLinkFromIndexerToDbEntity)), + (links) => throwIfAborted(this.db!.putCyberlinks, signal)(links), MAX_DATABASE_PUT_SIZE ); - const newItem = changeSyncStatus(syncItem, links, myAddress); + const newItem = changeParticleSyncStatus(syncItem, links, myAddress); updatedSyncItems.push(newItem); } diff --git a/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts b/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts index 68463bb7e..05acfe4e5 100644 --- a/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts +++ b/src/services/backend/services/sync/services/SyncTransactionsLoop/services/chat.ts @@ -69,7 +69,7 @@ export const syncMyChats = async ( }; // eslint-disable-next-line no-await-in-loop - await throwIfAborted(db.putSyncStatus, signal)(newItem); + await throwIfAborted(db.putSyncStatus.bind(db), signal)(newItem); results.push({ ...newItem, meta: lastTransaction }); } else { diff --git a/src/services/backend/services/sync/utils.ts b/src/services/backend/services/sync/utils.ts index cecd5f1fd..80045d38c 100644 --- a/src/services/backend/services/sync/utils.ts +++ b/src/services/backend/services/sync/utils.ts @@ -1,38 +1,36 @@ import { dateToUtcNumber } from 'src/utils/date'; import { NeuronAddress, ParticleCid } from 'src/types/base'; -import { SyncStatusDto } from 'src/services/CozoDb/types/dto'; +import { LinkDto, SyncStatusDto } from 'src/services/CozoDb/types/dto'; import { EntryType } from 'src/services/CozoDb/types/entities'; -import { CyberlinksByParticleResponse } from '../dataSource/blockchain/indexer'; import { findLastIndex } from 'lodash'; -import { SenseItemLinkMeta } from '../../types/sense'; import { entityToDto } from 'src/utils/dto'; + +import { SenseItemLinkMeta } from '../../types/sense'; import { SyncEntryName } from '../../types/services'; -export function extractLinkData( - cid: ParticleCid, - links: CyberlinksByParticleResponse['cyberlinks'] -) { - return { - lastLink: links[0], - count: links.length, - lastTimestamp: dateToUtcNumber(links[0].timestamp), - firstTimestamp: dateToUtcNumber(links[links.length - 1].timestamp), - }; -} +// export function extractLinkData( +// cid: ParticleCid, +// links: CyberlinksByParticleResponse['cyberlinks'] +// ) { +// return { +// lastLink: links[0], +// count: links.length, +// lastTimestamp: dateToUtcNumber(links[0].timestamp), +// firstTimestamp: dateToUtcNumber(links[links.length - 1].timestamp), +// }; +// } export function getLastReadInfo( - links: CyberlinksByParticleResponse['cyberlinks'], + links: LinkDto[], ownerId: NeuronAddress, prevTimestampRead = 0, prevUnreadCount = 0 ) { const lastMyLinkIndex = findLastIndex( links, - (link) => - link.neuron === ownerId && - dateToUtcNumber(link.timestamp) > prevTimestampRead + (link) => link.neuron === ownerId && link.timestamp > prevTimestampRead ); const unreadCount = @@ -41,9 +39,7 @@ export function getLastReadInfo( : links.length - lastMyLinkIndex - 1; const timestampRead = - lastMyLinkIndex < 0 - ? prevTimestampRead - : dateToUtcNumber(links[lastMyLinkIndex].timestamp); + lastMyLinkIndex < 0 ? prevTimestampRead : links[lastMyLinkIndex].timestamp; return { timestampRead, @@ -51,23 +47,24 @@ export function getLastReadInfo( }; } -export function changeSyncStatus( - statusEntity: Partial, - links: CyberlinksByParticleResponse['cyberlinks'], - ownerId: NeuronAddress +export function changeParticleSyncStatus( + syncStatus: Partial, + links: LinkDto[], + ownerId: NeuronAddress, + shouldUpdateTimestamp = true ) { - const timestampUpdate = dateToUtcNumber(links[0].timestamp); + const timestampUpdate = links[0].timestamp; const { timestampRead, unreadCount } = getLastReadInfo( links, ownerId, - statusEntity.timestampRead, - statusEntity.unreadCount + syncStatus.timestampRead, + syncStatus.unreadCount ); const lastLink = entityToDto(links[0]); return { - ...statusEntity, + ...syncStatus, ownerId, entryType: EntryType.particle, disabled: false, @@ -77,7 +74,9 @@ export function changeSyncStatus( timestamp: timestampUpdate, } as SenseItemLinkMeta, timestampRead, - timestampUpdate, + timestampUpdate: shouldUpdateTimestamp + ? timestampUpdate + : syncStatus.timestampUpdate, } as SyncStatusDto; } @@ -86,6 +85,8 @@ const mapSyncEntryReadable: Record = { particles: 'log cyberlinks', resolver: 'particles', transactions: 'transactions', + pin: 'ipfs pins', }; + export const syncEntryNameToReadable = (name: SyncEntryName) => mapSyncEntryReadable[name] || name; diff --git a/src/services/user/userApi.ts b/src/services/neuron/neuronApi.ts similarity index 66% rename from src/services/user/userApi.ts rename to src/services/neuron/neuronApi.ts index 4b4c3f270..c46527b00 100644 --- a/src/services/user/userApi.ts +++ b/src/services/neuron/neuronApi.ts @@ -5,9 +5,12 @@ import { SenseApi } from 'src/contexts/backend/services/senseApi'; import { IpfsApi } from 'src/services/backend/workers/background/worker'; import { NeuronAddress, ParticleCid } from 'src/types/base'; import { DEFAULT_GAS_LIMITS, PATTERN_IPFS_HASH } from 'src/utils/config'; +import { isString } from 'lodash'; +import { LinkDto } from '../CozoDb/types/dto'; +import { getNowUtcNumber } from 'src/utils/date'; export const addIfpsMessageOrCid = async ( - message: string | ParticleCid, + message: string | ParticleCid | File, { ipfsApi }: { ipfsApi: IpfsApi | null } ) => { if (!ipfsApi) { @@ -15,16 +18,25 @@ export const addIfpsMessageOrCid = async ( } return ( - !message.match(PATTERN_IPFS_HASH) - ? ((await ipfsApi!.addContent(message)) as string) - : message + isString(message) && message.match(PATTERN_IPFS_HASH) + ? message + : ((await ipfsApi!.addContent(message)) as string) ) as ParticleCid; }; +const processSigningClientResponse = async (response: any) => { + if (response.code === 0) { + return response.transactionHash; + } + + console.log('error', response); + throw Error(response.rawLog.toString()); +}; + export const sendCyberlink = async ( - address: NeuronAddress, - fromCid: ParticleCid, - toCid: ParticleCid, + neuron: NeuronAddress, + from: ParticleCid, + to: ParticleCid, { senseApi, signingClient, @@ -37,16 +49,19 @@ export const sendCyberlink = async ( gas: DEFAULT_GAS_LIMITS.toString(), } as StdFee ) => { - const response = await signingClient!.cyberlink(address, fromCid, toCid, fee); + const response = await signingClient!.cyberlink(neuron, from, to, fee); if (response.code === 0) { const txHash = response.transactionHash; - // await senseApi?.addMsgSendAsLocal({ - // transactionHash: txHash, - // fromAddress: address, - // toAddress: recipient, - // amount: offerCoin, - // memo: memoAsCid, - // }); + const link = { + from, + to, + transactionHash: txHash, + timestamp: getNowUtcNumber(), + neuron, + } as LinkDto; + await senseApi?.putCyberlinsks(link); + debugger; + await senseApi?.addCyberlinkLocal(link); return txHash; } diff --git a/src/utils/logging/bootstrap.ts b/src/utils/logging/bootstrap.ts index 0cc7c15c9..aaa45b2b8 100644 --- a/src/utils/logging/bootstrap.ts +++ b/src/utils/logging/bootstrap.ts @@ -52,6 +52,7 @@ window.setCyblogConsole = (val: boolean | ConsoleLogParams) => { : {} : val ) as ConsoleLogParams; + console.log('---window.setCyblogConsole', params, val); localStorage.setItem(CYBLOG_LOG_SHOW, JSON.stringify(params)); updateCyblogConsoleLogParams(params); } else { From b464335c9197fee3b135d8bffb7f5a79ed605381 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Fri, 15 Mar 2024 12:50:02 +0530 Subject: [PATCH 12/39] add following ui --- src/components/account/account.tsx | 5 ++-- .../SenseListItem/SenseListItem.container.tsx | 6 +++- .../Message/Message.container.module.scss | 6 ++++ .../Messages/Message/Message.container.tsx | 30 +++++++++++++------ .../SenseViewer/Messages/Message/Message.tsx | 6 +++- src/features/sense/ui/utils/format.ts | 8 +++++ 6 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/features/sense/ui/SenseViewer/Messages/Message/Message.container.module.scss diff --git a/src/components/account/account.tsx b/src/components/account/account.tsx index f7b0c14bf..7397851a7 100644 --- a/src/components/account/account.tsx +++ b/src/components/account/account.tsx @@ -104,7 +104,8 @@ function Account({ }} > {avatar && ( -
-
+ )} {!onlyAvatar && ( ); } else if (data) { - content = ( - - ); + if (isFollow) { + const address = data.content; + + content = ( +
+ followed 💚 +
+ ); + } else { + content = ( + + ); + } } } else if (text) { content = text; diff --git a/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx b/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx index 9e134ebb6..12c446b22 100644 --- a/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx +++ b/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx @@ -79,7 +79,11 @@ function Message({
{ + onClick={(e) => { + // inner link clicked + if (e.target instanceof HTMLAnchorElement) { + return; + } // if text not selected // shouldn't be null if (window.getSelection().toString() === '') { diff --git a/src/features/sense/ui/utils/format.ts b/src/features/sense/ui/utils/format.ts index 7d3ed97f4..2e9f61287 100644 --- a/src/features/sense/ui/utils/format.ts +++ b/src/features/sense/ui/utils/format.ts @@ -7,6 +7,7 @@ import { import { SenseItem } from '../../redux/sense.redux'; import { isParticle } from 'src/features/particle/utils'; import { EntityToDto } from 'src/types/dto'; +import { CID_FOLLOW } from 'src/constants/app'; // eslint-disable-next-line import/prefer-default-export, import/no-unused-modules export function formatSenseItemDataToUI( @@ -18,11 +19,13 @@ export function formatSenseItemDataToUI( cid: string | undefined; amount: Coin[] | undefined; isAmountSendToMyAddress: boolean; + isFollow: boolean; } { const { type, memo, meta, id } = senseItem; let amount: Coin[] | undefined; let isAmountSendToMyAddress = false; + let isFollow = false; let cid; switch (type) { @@ -55,6 +58,10 @@ export function formatSenseItemDataToUI( case 'cyber.graph.v1beta1.MsgCyberlink': { cid = currentChatId === meta.to ? meta.from : meta.to; + if (meta.from === CID_FOLLOW) { + isFollow = true; + } + break; } @@ -71,6 +78,7 @@ export function formatSenseItemDataToUI( return { ...senseItem, text: memo || '', + isFollow, cid, amount: amount?.filter((a) => !(a.denom === 'boot' && a.amount === '1')), isAmountSendToMyAddress, From 8011232b4f70b0d9ff3cd3005d1f9a81ae1fd258 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Fri, 15 Mar 2024 13:20:01 +0530 Subject: [PATCH 13/39] add message sender --- .../SenseListItem/SenseListItem.container.tsx | 40 ++++++++++++++----- .../SenseList/SenseListItem/SenseListItem.tsx | 7 ++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.container.tsx b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.container.tsx index cd7b0f34a..fb8ad51d0 100644 --- a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.container.tsx +++ b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.container.tsx @@ -2,7 +2,7 @@ import useParticleDetails from '../../../../particle/useParticleDetails'; import { selectCurrentAddress } from 'src/redux/features/pocket'; import { useAppSelector } from 'src/redux/hooks'; import { contentTypeConfig } from 'src/containers/Search/Filters/Filters'; -import { Dots } from 'src/components'; +import { Account, Dots } from 'src/components'; import SenseListItem from './SenseListItem'; import { formatSenseItemDataToUI } from '../../utils/format'; import { SenseItemId } from 'src/features/sense/types/sense'; @@ -29,8 +29,15 @@ function SenseListItemContainer({ senseItemId }: Props) { }); const address = useAppSelector(selectCurrentAddress); - const { timestamp, amount, cid, text, isAmountSendToMyAddress, isFollow } = - formatSenseItemDataToUI(senseData, address, senseItemId); + const { + timestamp, + amount, + cid, + text, + isAmountSendToMyAddress, + isFollow, + from, + } = formatSenseItemDataToUI(senseData, address, senseItemId); const particle = isParticle(senseItemId); @@ -52,19 +59,29 @@ function SenseListItemContainer({ senseItemId }: Props) { ); } else if (data) { - content = - data.text?.replaceAll('#', '') || - contentTypeConfig[data.type]?.label || - 'unsupported type'; + if (isFollow) { + content = ( +
+ 💚 {' '} +
+ ); + } else { + content = + data.text?.replaceAll('#', '') || + contentTypeConfig[data.type]?.label || + 'unsupported type'; + } } } else { content = text; } - if (isFollow) { - content = `followed 💚 neuron`; - } - function formatParticleTitle(text?: string, type: string) { if (type === 'image' || !text) { return null; @@ -82,6 +99,7 @@ function SenseListItemContainer({ senseItemId }: Props) { title={formatParticleTitle(particleText, data?.type)} unreadCount={unreadCount} content={content} + from={from} status={senseData.status} amountData={{ amount, isAmountSendToMyAddress }} /> diff --git a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx index e0fb1a77d..3656db08f 100644 --- a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx +++ b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx @@ -39,6 +39,7 @@ function SenseListItem({ content, status, amountData, + from, fromLog, title, }: Props) { @@ -79,6 +80,12 @@ function SenseListItem({ {icon} )} + + {address !== from && ( +
+ +
+ )}
Date: Sat, 16 Mar 2024 06:47:06 +0300 Subject: [PATCH 14/39] fix(robot): actionBar (#1126) --- src/pages/robot/_refactor/account/actionBar.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/robot/_refactor/account/actionBar.tsx b/src/pages/robot/_refactor/account/actionBar.tsx index 8b2726dd9..01b5cb406 100644 --- a/src/pages/robot/_refactor/account/actionBar.tsx +++ b/src/pages/robot/_refactor/account/actionBar.tsx @@ -289,7 +289,7 @@ class ActionBarContainer extends Component { file, } = this.state; - if (stage === STAGE_INIT) { + if (stage === STAGE_INIT && addressSend !== defaultAccount.bech32) { const sendBtn = ( - ); const followBtn = ; const content = []; // main page - if (!type && addressSend !== defaultAccount.bech32) { - content.push(sendBtn); - } + if (!type) { + if (!isOwner) { + content.push( + + ); + } - if ((type === 'log' || !type) && follow) { - content.push(followBtn); + if (follow) { + content.push(followBtn); + } } - return {content}; - } + if (type === 'log') { + if (follow) { + content.push(followBtn); + } - // TODO: continue refactoring + if (tweets) { + return ( + + ); + } + } - if (stage === STAGE_INIT && type === 'log' && tweets) { - return ( - - ); - } + if (type === 'security' && isOwner && defaultAccount.keys === 'keplr') { + content.push(); + } - if ( - stage === STAGE_INIT && - type === 'security' && - defaultAccount !== null && - defaultAccount.keys === 'keplr' && - addressSend === defaultAccount.bech32 - ) { - return ( - - ); + return {content}; } if (stage === STAGE_READY) { From c15ef49150537380b044da2fac19b072c948f340 Mon Sep 17 00:00:00 2001 From: dasein Date: Sat, 16 Mar 2024 11:06:42 +0530 Subject: [PATCH 18/39] fix(sense): last item when update --- src/services/backend/services/sync/utils.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/services/backend/services/sync/utils.ts b/src/services/backend/services/sync/utils.ts index 3831f06f4..2e2e8c54e 100644 --- a/src/services/backend/services/sync/utils.ts +++ b/src/services/backend/services/sync/utils.ts @@ -54,16 +54,6 @@ export function changeParticleSyncStatus( ownerId: NeuronAddress, shouldUpdateTimestamp = true ) { - const timestampUpdate = links[0].timestamp; - // if (syncStatus.id === 'QmVvYEERKAEFm1fqSZxKYdvHJqL6QLPbTYLSeaGSNv4NKy') { - // console.log( - // '----changeParticleSyncStatus led', - // syncStatus, - // links, - // shouldUpdateTimestamp - // ); - // debugger; - // } const { timestampRead, unreadCount } = getLastReadInfo( links, ownerId, @@ -72,7 +62,7 @@ export function changeParticleSyncStatus( ); const lastLink = entityToDto(links[links.length - 1]); - + const timestampUpdate = lastLink.timestamp; return { ...syncStatus, ownerId, From e30c8e5f33a428c1dfcf79d2dd3b9e61a89b7277 Mon Sep 17 00:00:00 2001 From: dasein Date: Sat, 16 Mar 2024 14:21:57 +0530 Subject: [PATCH 19/39] fix(community): remove dublicates for other users --- .../account/hooks/useGetCommunity.ts | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/pages/robot/_refactor/account/hooks/useGetCommunity.ts b/src/pages/robot/_refactor/account/hooks/useGetCommunity.ts index 540b325e0..60862f0ac 100644 --- a/src/pages/robot/_refactor/account/hooks/useGetCommunity.ts +++ b/src/pages/robot/_refactor/account/hooks/useGetCommunity.ts @@ -4,7 +4,7 @@ import useQueueIpfsContent from 'src/hooks/useQueueIpfsContent'; import { fetchCommunity } from 'src/services/community/community'; import { CommunityDto } from 'src/services/CozoDb/types/dto'; -import { NeuronAddress } from 'src/types/base'; +import { NeuronAddress, ParticleCid } from 'src/types/base'; import { makeCancellable } from 'src/utils/async/promise'; import { removeDublicates } from 'src/utils/list'; @@ -49,28 +49,32 @@ function useGetCommunity(address: string | null, { skip }: { skip?: boolean }) { } (async () => { - const communityRaw: CommunityDto[] = []; + const communityRaw: Map = new Map(); const onResolve = (communityResolved: CommunityDto[]) => { - communityRaw.push(...communityResolved); - const followers = communityRaw - .filter((item) => item.follower && !item.following) - .map((item) => item.neuron); - const following = communityRaw - .filter((item) => item.following && !item.follower) - .map((item) => item.neuron); - const friends = communityRaw - .filter((item) => item.follower && item.following) - .map((item) => item.neuron); - + communityResolved.forEach((item) => + communityRaw.set(item.neuron, item) + ); // TODO: exclude dublicates when followe and following from 2 sources // const allItems = [...state.community.raw, ...items]; - setCommunity((community) => ({ - followers: removeDublicates([...community.followers, ...followers]), - following: removeDublicates([...community.following, ...following]), - friends: removeDublicates([...community.friends, ...friends]), - })); + setCommunity({ + followers: removeDublicates( + [...communityRaw.values()] + .filter((item) => item.follower && !item.following) + .map((item) => item.neuron) + ), + following: removeDublicates( + [...communityRaw.values()] + .filter((item) => item.following && !item.follower) + .map((item) => item.neuron) + ), + friends: removeDublicates( + [...communityRaw.values()] + .filter((item) => item.follower && item.following) + .map((item) => item.neuron) + ), + }); }; await makeCancellable(fetchCommunity, abortController.signal)( From 182d86d7748c1065ee7f834493eb227249abe0a4 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Sat, 16 Mar 2024 15:50:10 +0530 Subject: [PATCH 20/39] fix logic --- src/pages/robot/_refactor/account/actionBar.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pages/robot/_refactor/account/actionBar.tsx b/src/pages/robot/_refactor/account/actionBar.tsx index 314e94255..f37533c10 100644 --- a/src/pages/robot/_refactor/account/actionBar.tsx +++ b/src/pages/robot/_refactor/account/actionBar.tsx @@ -152,7 +152,7 @@ class ActionBarContainer extends Component { } } } - } else if (type === 'log') { + } else if (type === 'log' || !type) { if (follow) { const toCid = await ipfsApi.addContent(addressSend); txHash = await sendCyberlink(address, CID_FOLLOW, toCid, { @@ -167,7 +167,12 @@ class ActionBarContainer extends Component { }); } } - console.log('hash :>> ', txHash); + + // sholdn't be after refactoring + if (!txHash) { + throw new Error('Tx hash is empty'); + } + this.setState({ stage: STAGE_SUBMITTED, txHash }); this.timeOut = setTimeout(this.confirmTx, 1500); From e391340cd7f1de5aa5dde1c9f710d04fbbff4864 Mon Sep 17 00:00:00 2001 From: dasein Date: Sat, 16 Mar 2024 18:12:42 +0530 Subject: [PATCH 21/39] refactor(general): refact neuronApi layer --- src/constants/app.ts | 1 + src/containers/Search/ActionBarContainer.tsx | 3 +- src/containers/Search/SearchResults.tsx | 2 +- .../Header/Commander/Commander.tsx | 2 +- src/containers/ipfs/ipfs.tsx | 2 +- src/features/sense/ui/ActionBar/ActionBar.tsx | 2 +- .../Messages/Message/Message.container.tsx | 2 +- src/pages/oracle/Learn/Learn.tsx | 6 +- .../robot/_refactor/account/actionBar.tsx | 8 +- src/pages/teleport/send/actionBar.send.tsx | 6 +- .../dataSendTxs/DataSendTxsItems.tsx | 2 +- src/services/neuron/errors.ts | 31 +++++++ src/services/neuron/neuronApi.ts | 82 ++++++------------- src/utils/config.ts | 1 - src/utils/ipfs/helpers.ts | 18 ++++ 15 files changed, 90 insertions(+), 78 deletions(-) create mode 100644 src/services/neuron/errors.ts diff --git a/src/constants/app.ts b/src/constants/app.ts index ecc5096e0..f9d7d493f 100644 --- a/src/constants/app.ts +++ b/src/constants/app.ts @@ -8,3 +8,4 @@ export const PATTERN_CYBER = new RegExp( `^${BECH32_PREFIX_ACC_ADDR_CYBER}[a-zA-Z0-9]{39}$`, 'g' ); +export const PATTERN_IPFS_HASH = /^Qm[a-zA-Z0-9]{44}$/g; diff --git a/src/containers/Search/ActionBarContainer.tsx b/src/containers/Search/ActionBarContainer.tsx index 52b935c68..532341577 100644 --- a/src/containers/Search/ActionBarContainer.tsx +++ b/src/containers/Search/ActionBarContainer.tsx @@ -14,7 +14,8 @@ import { import { getTxs } from '../../utils/search/utils'; -import { LEDGER, PATTERN_IPFS_HASH } from '../../utils/config'; +import { LEDGER } from '../../utils/config'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; import { trimString } from '../../utils/utils'; import withIpfsAndKeplr from 'src/hocs/withIpfsAndKeplr'; import { DefaultAccount } from 'src/types/defaultAccount'; diff --git a/src/containers/Search/SearchResults.tsx b/src/containers/Search/SearchResults.tsx index 649e54391..95d76141d 100644 --- a/src/containers/Search/SearchResults.tsx +++ b/src/containers/Search/SearchResults.tsx @@ -9,7 +9,7 @@ import { getIpfsHash } from 'src/utils/ipfs/helpers'; import { encodeSlash } from '../../utils/utils'; import { NoItems } from '../../components'; import ActionBarContainer from './ActionBarContainer'; -import { PATTERN_IPFS_HASH } from '../../utils/config'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; import { MainContainer } from '../portal/components'; import FirstItems from './_FirstItems.refactor'; import useSearchData from './hooks/useSearchData'; diff --git a/src/containers/application/Header/Commander/Commander.tsx b/src/containers/application/Header/Commander/Commander.tsx index 1f79dceb8..3fa02aaf7 100644 --- a/src/containers/application/Header/Commander/Commander.tsx +++ b/src/containers/application/Header/Commander/Commander.tsx @@ -3,7 +3,7 @@ import { useNavigate, useParams } from 'react-router-dom'; import { Color } from 'src/components/LinearGradientContainer/LinearGradientContainer'; import { routes } from 'src/routes'; import { getIpfsHash } from 'src/utils/ipfs/helpers'; -import { PATTERN_IPFS_HASH } from 'src/utils/config'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; import { useAppDispatch, useAppSelector } from 'src/redux/hooks'; import { setFocus, setValue } from './commander.redux'; import styles from './Commander.module.scss'; diff --git a/src/containers/ipfs/ipfs.tsx b/src/containers/ipfs/ipfs.tsx index c5a6852f4..13ee53cb3 100644 --- a/src/containers/ipfs/ipfs.tsx +++ b/src/containers/ipfs/ipfs.tsx @@ -4,7 +4,7 @@ import useQueueIpfsContent from 'src/hooks/useQueueIpfsContent'; import { useEffect, useMemo, useState } from 'react'; import { useAdviser } from 'src/features/adviser/context'; import { encodeSlash } from 'src/utils/utils'; -import { PATTERN_IPFS_HASH } from 'src/utils/config'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; import { getIpfsHash } from 'src/utils/ipfs/helpers'; import { parseArrayLikeToDetails } from 'src/services/ipfs/utils/content'; import { IPFSContentDetails } from 'src/services/ipfs/ipfs'; diff --git a/src/features/sense/ui/ActionBar/ActionBar.tsx b/src/features/sense/ui/ActionBar/ActionBar.tsx index d0062c526..be8c76d5e 100644 --- a/src/features/sense/ui/ActionBar/ActionBar.tsx +++ b/src/features/sense/ui/ActionBar/ActionBar.tsx @@ -15,10 +15,10 @@ import { routes } from 'src/routes'; import { Link, createSearchParams } from 'react-router-dom'; import { ibcDenomAtom } from 'src/pages/teleport/bridge/bridge'; import { - addIfpsMessageOrCid, sendCyberlink, sendTokensWithMessage, } from 'src/services/neuron/neuronApi'; +import { addIfpsMessageOrCid } from 'src/utils/ipfs/helpers'; type Props = { id: string | undefined; diff --git a/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx b/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx index bbe59a91a..dfa5312a8 100644 --- a/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx +++ b/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx @@ -9,7 +9,7 @@ import { SenseItem } from 'src/features/sense/redux/sense.redux'; import { formatSenseItemDataToUI } from '../../../utils/format'; import { getIpfsHash } from 'src/utils/ipfs/helpers'; import { useEffect, useState } from 'react'; -import { PATTERN_IPFS_HASH } from 'src/utils/config'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; type Props = { senseItem: SenseItem; diff --git a/src/pages/oracle/Learn/Learn.tsx b/src/pages/oracle/Learn/Learn.tsx index 63d373dc4..9226e0469 100644 --- a/src/pages/oracle/Learn/Learn.tsx +++ b/src/pages/oracle/Learn/Learn.tsx @@ -20,10 +20,8 @@ import { Networks } from 'src/types/networks'; import useGetSlots from 'src/containers/mint/useGetSlots'; import { AdviserColors } from 'src/features/adviser/Adviser/Adviser'; import { useBackend } from 'src/contexts/backend/backend'; -import { - addIfpsMessageOrCid, - sendCyberlink, -} from 'src/services/neuron/neuronApi'; +import { sendCyberlink } from 'src/services/neuron/neuronApi'; +import { addIfpsMessageOrCid } from 'src/utils/ipfs/helpers'; import TitleText from '../landing/components/TitleText/TitleText'; import KeywordButton from '../landing/components/KeywordButton/KeywordButton'; import styles from './Learn.module.scss'; diff --git a/src/pages/robot/_refactor/account/actionBar.tsx b/src/pages/robot/_refactor/account/actionBar.tsx index 314e94255..53b8c9152 100644 --- a/src/pages/robot/_refactor/account/actionBar.tsx +++ b/src/pages/robot/_refactor/account/actionBar.tsx @@ -14,12 +14,8 @@ import { ActionBar as ActionBarComp, Button, } from '../../../../components'; -import { - LEDGER, - CYBER, - PATTERN_IPFS_HASH, - DEFAULT_GAS_LIMITS, -} from '../../../../utils/config'; +import { LEDGER, CYBER, DEFAULT_GAS_LIMITS } from '../../../../utils/config'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; import { getTotalRewards, getTxs } from '../../../../utils/search/utils'; diff --git a/src/pages/teleport/send/actionBar.send.tsx b/src/pages/teleport/send/actionBar.send.tsx index 69527172c..5c1b88768 100644 --- a/src/pages/teleport/send/actionBar.send.tsx +++ b/src/pages/teleport/send/actionBar.send.tsx @@ -8,10 +8,8 @@ import { useIbcDenom } from 'src/contexts/ibcDenom'; import { RootState } from 'src/redux/store'; import { useAppSelector } from 'src/redux/hooks'; import { useBackend } from 'src/contexts/backend/backend'; -import { - addIfpsMessageOrCid, - sendTokensWithMessage, -} from 'src/services/neuron/neuronApi'; +import { sendTokensWithMessage } from 'src/services/neuron/neuronApi'; +import { addIfpsMessageOrCid } from 'src/utils/ipfs/helpers'; import { convertAmountReverce } from '../../../utils/utils'; import { LEDGER } from '../../../utils/config'; diff --git a/src/pages/teleport/send/components/dataSendTxs/DataSendTxsItems.tsx b/src/pages/teleport/send/components/dataSendTxs/DataSendTxsItems.tsx index 58e080e09..14889cec8 100644 --- a/src/pages/teleport/send/components/dataSendTxs/DataSendTxsItems.tsx +++ b/src/pages/teleport/send/components/dataSendTxs/DataSendTxsItems.tsx @@ -1,6 +1,6 @@ import { Coin } from '@cosmjs/launchpad'; import { AmountDenom, Cid } from 'src/components'; -import { PATTERN_IPFS_HASH } from 'src/utils/config'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; import useQueueIpfsContent from 'src/hooks/useQueueIpfsContent'; import { useEffect, useState } from 'react'; import { parseArrayLikeToDetails } from 'src/services/ipfs/utils/content'; diff --git a/src/services/neuron/errors.ts b/src/services/neuron/errors.ts new file mode 100644 index 000000000..3c0d7d075 --- /dev/null +++ b/src/services/neuron/errors.ts @@ -0,0 +1,31 @@ +import { DeliverTxResponse } from '@cosmjs/stargate'; + +export class SigningCyberClientError extends Error { + public code: number; + + constructor(response: string[] | DeliverTxResponse) { + let message = ''; + let code = -1; + if (response instanceof Array) { + message = response.join('\r\n'); + } else if (response.rawLog) { + message = response.rawLog.toString(); + code = response.code; + } else { + message = message?.error; + } + + super(message); + this.code = code; + } +} + +export const throwErrorOrResponse = ( + response: string[] | DeliverTxResponse +) => { + const isResponseError = response instanceof Array || response.code !== 0; + if (isResponseError) { + throw new SigningCyberClientError(response); + } + return response as DeliverTxResponse; +}; diff --git a/src/services/neuron/neuronApi.ts b/src/services/neuron/neuronApi.ts index 5b6c941df..6380b7a08 100644 --- a/src/services/neuron/neuronApi.ts +++ b/src/services/neuron/neuronApi.ts @@ -2,36 +2,12 @@ import { Coin, StdFee } from '@cosmjs/launchpad'; import { SigningCyberClient } from '@cybercongress/cyber-js'; import { SenseApi } from 'src/contexts/backend/services/senseApi'; -import { IpfsApi } from 'src/services/backend/workers/background/worker'; import { NeuronAddress, ParticleCid } from 'src/types/base'; -import { DEFAULT_GAS_LIMITS, PATTERN_IPFS_HASH } from 'src/utils/config'; -import { isString } from 'lodash'; -import { LinkDto } from '../CozoDb/types/dto'; +import { DEFAULT_GAS_LIMITS } from 'src/utils/config'; import { getNowUtcNumber } from 'src/utils/date'; -export const addIfpsMessageOrCid = async ( - message: string | ParticleCid | File, - { ipfsApi }: { ipfsApi: IpfsApi | null } -) => { - if (!ipfsApi) { - throw Error('IpfsApi is not initialized'); - } - - return ( - isString(message) && message.match(PATTERN_IPFS_HASH) - ? message - : ((await ipfsApi!.addContent(message)) as string) - ) as ParticleCid; -}; - -const processSigningClientResponse = async (response: any) => { - if (response.code === 0) { - return response.transactionHash; - } - - console.log('error', response); - throw Error(response.rawLog.toString()); -}; +import { LinkDto } from '../CozoDb/types/dto'; +import { throwErrorOrResponse } from './errors'; export const sendCyberlink = async ( neuron: NeuronAddress, @@ -50,23 +26,21 @@ export const sendCyberlink = async ( } as StdFee ) => { const response = await signingClient!.cyberlink(neuron, from, to, fee); - if (response.code === 0) { - const txHash = response.transactionHash; - const link = { - from, - to, - transactionHash: txHash, - timestamp: getNowUtcNumber(), - neuron, - } as LinkDto; - await senseApi?.putCyberlinsks(link); - await senseApi?.addCyberlinkLocal(link); + const result = throwErrorOrResponse(response); - return txHash; - } + const { transactionHash } = result; + const link = { + from, + to, + transactionHash, + timestamp: getNowUtcNumber(), + neuron, + } as LinkDto; - console.log('error', response); - throw Error(response.rawLog.toString()); + await senseApi?.putCyberlinsks(link); + await senseApi?.addCyberlinkLocal(link); + + return transactionHash; }; export const sendTokensWithMessage = async ( @@ -86,20 +60,16 @@ export const sendTokensWithMessage = async ( 'auto', memo ); + const result = throwErrorOrResponse(response); + const { transactionHash } = result; - if (response.code === 0) { - const txHash = response.transactionHash; - await senseApi?.addMsgSendAsLocal({ - transactionHash: txHash, - fromAddress: address, - toAddress: recipient, - amount: offerCoin, - memo, - }); - - return txHash; - } + await senseApi?.addMsgSendAsLocal({ + transactionHash, + fromAddress: address, + toAddress: recipient, + amount: offerCoin, + memo, + }); - console.log('error', response); - throw Error(response.rawLog.toString()); + return transactionHash; }; diff --git a/src/utils/config.ts b/src/utils/config.ts index ef87b104e..e1d540458 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -278,7 +278,6 @@ const PATTERN_OSMOS = /^osmo[a-zA-Z0-9]{39}$/g; const PATTERN_TERRA = /^terra[a-zA-Z0-9]{39}$/g; const PATTERN_ETH = /^0x[a-fA-F0-9]{40}$/g; const PATTERN_TX = /[0-9a-fA-F]{64}$/g; -const PATTERN_IPFS_HASH = /^Qm[a-zA-Z0-9]{44}$/g; const PATTERN_BLOCK = /^[0-9]+$/g; const PATTERN_HTTP = /^https:\/\/|^http:\/\//g; const PATTERN_HTML = /<\/?[\w\d]+>/gi; diff --git a/src/utils/ipfs/helpers.ts b/src/utils/ipfs/helpers.ts index d2b1cef39..03d4ce87d 100644 --- a/src/utils/ipfs/helpers.ts +++ b/src/utils/ipfs/helpers.ts @@ -1,6 +1,10 @@ import Unixfs from 'ipfs-unixfs'; import { DAGNode, util as DAGUtil } from 'ipld-dag-pb'; +import { isString } from 'lodash'; +import { IpfsApi } from 'src/services/backend/workers/background/worker'; +import { IpfsApi } from 'src/services/backend/workers/background/worker'; import { ParticleCid } from 'src/types/base'; +import { PATTERN_IPFS_HASH } from 'src/constants/app'; // eslint-disable-next-line import/prefer-default-export export const getIpfsHash = (string: string): Promise => @@ -18,3 +22,17 @@ export const getIpfsHash = (string: string): Promise => }); }); }); +export const addIfpsMessageOrCid = async ( + message: string | ParticleCid | File, + { ipfsApi }: { ipfsApi: IpfsApi | null } +) => { + if (!ipfsApi) { + throw Error('IpfsApi is not initialized'); + } + + return ( + isString(message) && message.match(PATTERN_IPFS_HASH) + ? message + : ((await ipfsApi!.addContent(message)) as string) + ) as ParticleCid; +}; From 6d006c5622ceac4069a81ab306d20dd5c4d6e5d2 Mon Sep 17 00:00:00 2001 From: dasein Date: Mon, 18 Mar 2024 13:57:24 +0530 Subject: [PATCH 22/39] fix(sense): date sorting of local cozo op msg bug --- .../backend/services/dataSource/indexedDb/dbApiWrapper.ts | 4 ++-- src/utils/date.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts b/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts index c28a4eaee..67084b7b1 100644 --- a/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts +++ b/src/services/backend/services/dataSource/indexedDb/dbApiWrapper.ts @@ -174,8 +174,8 @@ class DbApiWrapper { ss_chat_links[id, meta] := ss_chat_all[id, meta, hash, is_link, index], is_link ss_chat_trans[id, m] := ss_chat_all[id, meta, hash, is_link, index], !is_link, *transaction{hash, index, value, type, timestamp, success, memo}, m=concat(meta, json_object('value', value, 'type', type, 'timestamp', timestamp, 'memo', memo, 'success', success, 'index', index)) - ?[owner_id, entry_type, id, unread_count, timestamp_update, timestamp_read, meta] := *sync_status{entry_type, id, unread_count, timestamp_update, timestamp_read, owner_id}, ss_particles[id, meta] or ss_chat_links[id, meta] or ss_chat_trans[id, meta], id!='${myAddress}', owner_id = '${myAddress}' - :order -timestamp_update + ?[owner_id, entry_type, id, unread_count, timestamp_update, timestamp_read, meta, meta_timestamp] := *sync_status{entry_type, id, unread_count, timestamp_update, timestamp_read, owner_id}, ss_particles[id, meta] or ss_chat_links[id, meta] or ss_chat_trans[id, meta], id!='${myAddress}', owner_id = '${myAddress}', meta_timestamp = maybe_get(meta, 'timestamp') + :order -meta_timestamp `; const result = await this.db!.runCommand(command, true); diff --git a/src/utils/date.ts b/src/utils/date.ts index 4486e6c4d..d3c34f878 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -7,7 +7,7 @@ export const dateToUtcNumber = (isoString: string) => Date.parse(isoString.endsWith('Z') ? isoString : `${isoString}Z`); export const getNowUtcNumber = (): number => { - return dateToUtcNumber(new Date().toISOString()); + return Date.now(); //dateToUtcNumber(new Date().toISOString()); }; // function roundMilliseconds(dateTimeString: string) { From 9f976cc9c75bac20edd0cd4a804ddeef847eac86 Mon Sep 17 00:00:00 2001 From: Max G Date: Mon, 18 Mar 2024 14:13:09 +0530 Subject: [PATCH 23/39] =?UTF-8?q?Revert=20"feat(sense=20=F0=9F=A7=AC):=20i?= =?UTF-8?q?mprovements"=20(#1132)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/account/account.tsx | 5 ++- .../SenseListItem/SenseListItem.container.tsx | 36 ++++--------------- .../SenseList/SenseListItem/SenseListItem.tsx | 7 ---- .../Message/Message.container.module.scss | 6 ---- .../Messages/Message/Message.container.tsx | 30 +++++----------- .../SenseViewer/Messages/Message/Message.tsx | 6 +--- src/features/sense/ui/utils/format.ts | 8 ----- 7 files changed, 19 insertions(+), 79 deletions(-) delete mode 100644 src/features/sense/ui/SenseViewer/Messages/Message/Message.container.module.scss diff --git a/src/components/account/account.tsx b/src/components/account/account.tsx index 7397851a7..f7b0c14bf 100644 --- a/src/components/account/account.tsx +++ b/src/components/account/account.tsx @@ -104,8 +104,7 @@ function Account({ }} > {avatar && ( - - + )} {!onlyAvatar && ( ); } else if (data) { - if (isFollow) { - content = ( -
- 💚 {' '} -
- ); - } else { - content = - data.text?.replaceAll('#', '') || - contentTypeConfig[data.type]?.label || - 'unsupported type'; - } + content = + data.text?.replaceAll('#', '') || + contentTypeConfig[data.type]?.label || + 'unsupported type'; } } else { content = text; @@ -99,7 +78,6 @@ function SenseListItemContainer({ senseItemId }: Props) { title={formatParticleTitle(particleText, data?.type)} unreadCount={unreadCount} content={content} - from={from} status={senseData.status} amountData={{ amount, isAmountSendToMyAddress }} /> diff --git a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx index 3656db08f..e0fb1a77d 100644 --- a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx +++ b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx @@ -39,7 +39,6 @@ function SenseListItem({ content, status, amountData, - from, fromLog, title, }: Props) { @@ -80,12 +79,6 @@ function SenseListItem({ {icon} )} - - {address !== from && ( -
- -
- )}
); } else if (data) { - if (isFollow) { - const address = data.content; - - content = ( -
- followed 💚 -
- ); - } else { - content = ( - - ); - } + content = ( + + ); } } else if (text) { content = text; diff --git a/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx b/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx index 12c446b22..9e134ebb6 100644 --- a/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx +++ b/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx @@ -79,11 +79,7 @@ function Message({
{ - // inner link clicked - if (e.target instanceof HTMLAnchorElement) { - return; - } + onClick={() => { // if text not selected // shouldn't be null if (window.getSelection().toString() === '') { diff --git a/src/features/sense/ui/utils/format.ts b/src/features/sense/ui/utils/format.ts index 2e9f61287..7d3ed97f4 100644 --- a/src/features/sense/ui/utils/format.ts +++ b/src/features/sense/ui/utils/format.ts @@ -7,7 +7,6 @@ import { import { SenseItem } from '../../redux/sense.redux'; import { isParticle } from 'src/features/particle/utils'; import { EntityToDto } from 'src/types/dto'; -import { CID_FOLLOW } from 'src/constants/app'; // eslint-disable-next-line import/prefer-default-export, import/no-unused-modules export function formatSenseItemDataToUI( @@ -19,13 +18,11 @@ export function formatSenseItemDataToUI( cid: string | undefined; amount: Coin[] | undefined; isAmountSendToMyAddress: boolean; - isFollow: boolean; } { const { type, memo, meta, id } = senseItem; let amount: Coin[] | undefined; let isAmountSendToMyAddress = false; - let isFollow = false; let cid; switch (type) { @@ -58,10 +55,6 @@ export function formatSenseItemDataToUI( case 'cyber.graph.v1beta1.MsgCyberlink': { cid = currentChatId === meta.to ? meta.from : meta.to; - if (meta.from === CID_FOLLOW) { - isFollow = true; - } - break; } @@ -78,7 +71,6 @@ export function formatSenseItemDataToUI( return { ...senseItem, text: memo || '', - isFollow, cid, amount: amount?.filter((a) => !(a.denom === 'boot' && a.amount === '1')), isAmountSendToMyAddress, From ceba43933c91051a7d45081df549a7d3d617bb38 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:29:12 +0400 Subject: [PATCH 24/39] build(deps): bump ip from 2.0.0 to 2.0.1 (#1100) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index a7d7694c8..b521f92d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17504,9 +17504,9 @@ ip-regex@^5.0.0: integrity sha512-fOCG6lhoKKakwv+C6KdsOnGvgXnmgfmp0myi3bcNwj3qfwPAxRKWEuFhvEFF7ceYIz6+1jRZ+yguLFAmUNPEfw== ip@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da" - integrity sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ== + version "2.0.1" + resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.1.tgz#e8f3595d33a3ea66490204234b77636965307105" + integrity sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ== ipaddr.js@1.9.1: version "1.9.1" From ed1f2c82ccc78e0c2e6d97a3dd6df126b2c29e45 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:29:50 +0400 Subject: [PATCH 25/39] build(deps): bump es5-ext from 0.10.62 to 0.10.64 (#1107) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index b521f92d6..2ce7c6f4b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13913,13 +13913,14 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -es5-ext@^0.10.35, es5-ext@^0.10.46, es5-ext@^0.10.50: - version "0.10.62" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.62.tgz#5e6adc19a6da524bf3d1e02bbc8960e5eb49a9a5" - integrity sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA== +es5-ext@^0.10.35, es5-ext@^0.10.46, es5-ext@^0.10.50, es5-ext@^0.10.62, es5-ext@~0.10.14: + version "0.10.64" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.64.tgz#12e4ffb48f1ba2ea777f1fcdd1918ef73ea21714" + integrity sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg== dependencies: es6-iterator "^2.0.3" es6-symbol "^3.1.3" + esniff "^2.0.1" next-tick "^1.1.0" es6-iterator@^2.0.3: @@ -14470,6 +14471,16 @@ eslint@^8.7.0: strip-json-comments "^3.1.0" text-table "^0.2.0" +esniff@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/esniff/-/esniff-2.0.1.tgz#a4d4b43a5c71c7ec51c51098c1d8a29081f9b308" + integrity sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg== + dependencies: + d "^1.0.1" + es5-ext "^0.10.62" + event-emitter "^0.3.5" + type "^2.7.2" + espree@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/espree/-/espree-5.0.1.tgz#5d6526fa4fc7f0788a5cf75b15f30323e2f81f7a" @@ -14707,6 +14718,14 @@ ethjs-util@0.1.6: is-hex-prefixed "1.0.0" strip-hex-prefix "1.0.0" +event-emitter@^0.3.5: + version "0.3.5" + resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39" + integrity sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA== + dependencies: + d "1" + es5-ext "~0.10.14" + event-iterator@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/event-iterator/-/event-iterator-2.0.0.tgz#10f06740cc1e9fd6bc575f334c2bc1ae9d2dbf62" From 7f62af11c8b1d9a858eaccc651876286b3469d8e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:30:21 +0400 Subject: [PATCH 26/39] build(deps): bump follow-redirects from 1.15.4 to 1.15.6 (#1131) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/yarn.lock b/yarn.lock index 2ce7c6f4b..0aa625e69 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15414,15 +15414,10 @@ fnv1a@^1.0.1: resolved "https://registry.yarnpkg.com/fnv1a/-/fnv1a-1.1.1.tgz#4e01d51bae60735d00e54ffde02581fe2e74f465" integrity sha512-S2HviLR9UyNbt8R+vU6YeQtL8RliPwez9DQEVba5MAvN3Od+RSgKUSL2+qveOMt3owIeBukKoRu2enoOck5uag== -follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.9, follow-redirects@^1.15.0: - version "1.15.4" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.4.tgz#cdc7d308bf6493126b17ea2191ea0ccf3e535adf" - integrity sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw== - -follow-redirects@^1.15.4: - version "1.15.5" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020" - integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw== +follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.9, follow-redirects@^1.15.0, follow-redirects@^1.15.4: + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== font-atlas@^2.1.0: version "2.1.0" From 575a72af8fcae470cf80afcdc002769a63d095f2 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 20 Mar 2024 12:46:26 +0400 Subject: [PATCH 27/39] =?UTF-8?q?feat(sense=20=F0=9F=A7=AC):=20improvement?= =?UTF-8?q?s=20(#1134)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/account/account.tsx | 5 +- .../SenseListItem/SenseListItem.container.tsx | 45 +++++++++++++++--- .../SenseListItem/SenseListItem.module.scss | 7 ++- .../SenseList/SenseListItem/SenseListItem.tsx | 7 +++ .../Message/Message.container.module.scss | 11 +++++ .../Messages/Message/Message.container.tsx | 32 +++++++++---- .../SenseViewer/Messages/Message/Message.tsx | 18 +++++-- .../ui/SenseViewer/SenseViewer.module.scss | 47 +++++++++---------- .../sense/ui/SenseViewer/SenseViewer.tsx | 16 ++----- src/features/sense/ui/utils/format.ts | 8 ++++ src/utils/ipfs/helpers.ts | 1 - 11 files changed, 133 insertions(+), 64 deletions(-) create mode 100644 src/features/sense/ui/SenseViewer/Messages/Message/Message.container.module.scss diff --git a/src/components/account/account.tsx b/src/components/account/account.tsx index f7b0c14bf..7397851a7 100644 --- a/src/components/account/account.tsx +++ b/src/components/account/account.tsx @@ -104,7 +104,8 @@ function Account({ }} > {avatar && ( -
-
+ )} {!onlyAvatar && ( ); } else if (data) { - content = - data.text?.replaceAll('#', '') || - contentTypeConfig[data.type]?.label || - 'unsupported type'; + if (isFollow) { + content = ( +
+ + 💚 + {' '} + {/* {' '} */} + neuron +
+ ); + } else { + content = + data.text?.replaceAll('#', '') || + contentTypeConfig[data.type]?.label || + 'unsupported type'; + } } } else { content = text; @@ -78,6 +108,7 @@ function SenseListItemContainer({ senseItemId }: Props) { title={formatParticleTitle(particleText, data?.type)} unreadCount={unreadCount} content={content} + from={from} status={senseData.status} amountData={{ amount, isAmountSendToMyAddress }} /> diff --git a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.module.scss b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.module.scss index f3d1904ce..8dd8e3d41 100644 --- a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.module.scss +++ b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.module.scss @@ -31,8 +31,13 @@ .icon { position: absolute; - bottom: 0; + bottom: -2px; right: -5px; + + background-color: rgba(97, 94, 94, 0.461); + border-radius: 50%; + + filter: grayscale(20%); } } diff --git a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx index e0fb1a77d..3656db08f 100644 --- a/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx +++ b/src/features/sense/ui/SenseList/SenseListItem/SenseListItem.tsx @@ -39,6 +39,7 @@ function SenseListItem({ content, status, amountData, + from, fromLog, title, }: Props) { @@ -79,6 +80,12 @@ function SenseListItem({ {icon} )} + + {address !== from && ( +
+ +
+ )}
span:nth-of-type(1) { + position: relative; + top: 1px; + } +} diff --git a/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx b/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx index dfa5312a8..47bf334ea 100644 --- a/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx +++ b/src/features/sense/ui/SenseViewer/Messages/Message/Message.container.tsx @@ -4,12 +4,13 @@ import { useAppSelector } from 'src/redux/hooks'; import Message from './Message'; import useParticleDetails from '../../../../../particle/useParticleDetails'; import ContentIpfs from 'src/components/contentIpfs/contentIpfs'; -import { Dots } from 'src/components'; +import { Account, Dots } from 'src/components'; import { SenseItem } from 'src/features/sense/redux/sense.redux'; import { formatSenseItemDataToUI } from '../../../utils/format'; import { getIpfsHash } from 'src/utils/ipfs/helpers'; import { useEffect, useState } from 'react'; import { PATTERN_IPFS_HASH } from 'src/constants/app'; +import styles from './Message.container.module.scss'; type Props = { senseItem: SenseItem; @@ -29,6 +30,7 @@ function MessageContainer({ senseItem, currentChatId }: Props) { text, fromLog, isAmountSendToMyAddress, + isFollow, } = formatSenseItemDataToUI(senseItem, address, currentChatId); const particleDetails = useParticleDetails(cid!, { @@ -58,14 +60,24 @@ function MessageContainer({ senseItem, currentChatId }: Props) { ); } else if (data) { - content = ( - - ); + if (isFollow) { + const address = data.content; + + content = ( +
+ 💚 +
+ ); + } else { + content = ( + + ); + } } } else if (text) { content = text; @@ -76,7 +88,7 @@ function MessageContainer({ senseItem, currentChatId }: Props) { address={from} myMessage={address === from} fromLog={fromLog} - from={from} + from={currentChatId !== from ? from : undefined} transactionHash={transactionHash} date={timestamp} content={content} diff --git a/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx b/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx index 9e134ebb6..8971a7c17 100644 --- a/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx +++ b/src/features/sense/ui/SenseViewer/Messages/Message/Message.tsx @@ -64,10 +64,14 @@ function Message({ - {fromLog && ( - - - + {fromLog && from && ( + <> + {!myMessage && ( + + + + )} + // // 🍀 // @@ -79,7 +83,11 @@ function Message({
{ + onClick={(e) => { + // inner link clicked + if (e.target instanceof HTMLAnchorElement) { + return; + } // if text not selected // shouldn't be null if (window.getSelection().toString() === '') { diff --git a/src/features/sense/ui/SenseViewer/SenseViewer.module.scss b/src/features/sense/ui/SenseViewer/SenseViewer.module.scss index 1d6b87b90..9221fdbaf 100644 --- a/src/features/sense/ui/SenseViewer/SenseViewer.module.scss +++ b/src/features/sense/ui/SenseViewer/SenseViewer.module.scss @@ -33,17 +33,26 @@ gap: 0 10px; - .toggleContent { - margin-top: 15px; - color: var(--primary-color); - - &:hover { - opacity: 0.8; - } + position: relative; + &::before { + content: ''; + bottom: -10px; + position: absolute; + left: -25px; + height: 20%; + pointer-events: none; + right: -10px; + filter: blur(10px); + background-image: linear-gradient( + to bottom, + rgba(0, 0, 0, 0.484), + rgba(0, 0, 0, 1) + ); } img { - max-width: 100px; + width: auto; + max-height: 100px; } .meta { @@ -85,25 +94,10 @@ grid-area: title; margin-top: 15px; - + max-height: 150px; + overflow: hidden; color: white; - &.largeContent { - > div > div { - display: -webkit-box; - -webkit-line-clamp: 5; - -webkit-box-orient: vertical; - } - - &.fullContent { - > div > div { - -webkit-line-clamp: unset; - -webkit-box-orient: unset; - display: unset; - } - } - } - > div { display: flex; justify-content: center; @@ -111,6 +105,9 @@ } > div > div { + // display: -webkit-box; + // -webkit-line-clamp: 5; + // -webkit-box-orient: vertical; * { line-height: normal; } diff --git a/src/features/sense/ui/SenseViewer/SenseViewer.tsx b/src/features/sense/ui/SenseViewer/SenseViewer.tsx index 5cd0fde17..17531b66b 100644 --- a/src/features/sense/ui/SenseViewer/SenseViewer.tsx +++ b/src/features/sense/ui/SenseViewer/SenseViewer.tsx @@ -27,9 +27,11 @@ type Props = { selected: string | undefined; } & AdviserProps; -function SenseViewer({ selected, adviser }: Props) { +function SenseViewer({ adviser, selected }: Props) { const { senseApi } = useBackend(); + // const selected = 'QmZ4b5kbCV9K9Jd2ZXpfUAKiPSkzPfD558wBbebYFpztKY'; + const isParticle = isParticleFunc(selected || ''); const chat = useAppSelector((store) => { @@ -106,18 +108,6 @@ function SenseViewer({ selected, adviser }: Props) { details={particleData} /> - - {largeContent && ( - - )} ) : (
diff --git a/src/features/sense/ui/utils/format.ts b/src/features/sense/ui/utils/format.ts index 7d3ed97f4..2e9f61287 100644 --- a/src/features/sense/ui/utils/format.ts +++ b/src/features/sense/ui/utils/format.ts @@ -7,6 +7,7 @@ import { import { SenseItem } from '../../redux/sense.redux'; import { isParticle } from 'src/features/particle/utils'; import { EntityToDto } from 'src/types/dto'; +import { CID_FOLLOW } from 'src/constants/app'; // eslint-disable-next-line import/prefer-default-export, import/no-unused-modules export function formatSenseItemDataToUI( @@ -18,11 +19,13 @@ export function formatSenseItemDataToUI( cid: string | undefined; amount: Coin[] | undefined; isAmountSendToMyAddress: boolean; + isFollow: boolean; } { const { type, memo, meta, id } = senseItem; let amount: Coin[] | undefined; let isAmountSendToMyAddress = false; + let isFollow = false; let cid; switch (type) { @@ -55,6 +58,10 @@ export function formatSenseItemDataToUI( case 'cyber.graph.v1beta1.MsgCyberlink': { cid = currentChatId === meta.to ? meta.from : meta.to; + if (meta.from === CID_FOLLOW) { + isFollow = true; + } + break; } @@ -71,6 +78,7 @@ export function formatSenseItemDataToUI( return { ...senseItem, text: memo || '', + isFollow, cid, amount: amount?.filter((a) => !(a.denom === 'boot' && a.amount === '1')), isAmountSendToMyAddress, diff --git a/src/utils/ipfs/helpers.ts b/src/utils/ipfs/helpers.ts index 03d4ce87d..ece6da5a5 100644 --- a/src/utils/ipfs/helpers.ts +++ b/src/utils/ipfs/helpers.ts @@ -2,7 +2,6 @@ import Unixfs from 'ipfs-unixfs'; import { DAGNode, util as DAGUtil } from 'ipld-dag-pb'; import { isString } from 'lodash'; import { IpfsApi } from 'src/services/backend/workers/background/worker'; -import { IpfsApi } from 'src/services/backend/workers/background/worker'; import { ParticleCid } from 'src/types/base'; import { PATTERN_IPFS_HASH } from 'src/constants/app'; From bf59d6219460807e4620670e1bd243441a1be335 Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 20 Mar 2024 21:03:57 +0400 Subject: [PATCH 28/39] fix(storybook): fix crash while build (#1137) --- src/utils/config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/config.ts b/src/utils/config.ts index e1d540458..047a718b1 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -296,7 +296,6 @@ export { PATTERN_CYBER_CONTRACT, PATTERN_CYBER_VALOPER, PATTERN_TX, - PATTERN_IPFS_HASH, PATTERN_COSMOS, PATTERN_ETH, PATTERN_TERRA, From 92fe171410c1871d9cc7fa352606e2f9707f5699 Mon Sep 17 00:00:00 2001 From: Max G Date: Tue, 26 Mar 2024 12:26:50 +0530 Subject: [PATCH 29/39] fix(sense): scroll messages in viewer bugfix (#1141) --- .../ui/SenseViewer/Messages/Messages.tsx | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/features/sense/ui/SenseViewer/Messages/Messages.tsx b/src/features/sense/ui/SenseViewer/Messages/Messages.tsx index 94b163bdf..a16a2f3f0 100644 --- a/src/features/sense/ui/SenseViewer/Messages/Messages.tsx +++ b/src/features/sense/ui/SenseViewer/Messages/Messages.tsx @@ -37,28 +37,28 @@ function Messages({ messages, currentChatId }: Props) { ); } - const messagesByDate = useMemo(() => { - const msgs = [...messages].reverse().slice(0, showItemsLength); + const messagesByDateAll = useMemo(() => { + return Object.entries( + [...messages].reverse().reduce<{ + [date: string]: SenseItem[]; + }>((acc, senseItem) => { + const date = dateFormat(senseItem.timestamp, 'yyyy-mm-dd'); - const messagesByDate = msgs.reduce<{ - [date: string]: SenseItem[]; - }>((acc, senseItem) => { - const date = dateFormat(senseItem.timestamp, 'yyyy-mm-dd'); + if (!acc[date]) { + acc[date] = []; + } - if (!acc[date]) { - acc[date] = []; - } + acc[date].push(senseItem); - acc[date].push(senseItem); - - return acc; - }, {}); - - // maybe need order? - const arr = Object.entries(messagesByDate); + return acc; + }, {}) + ); + }, [messages]); - return arr; - }, [messages, showItemsLength]); + const messagesByDate = useMemo( + () => messagesByDateAll.slice(0, showItemsLength), + [messagesByDateAll, showItemsLength] + ); return ( // wrappers for correct scroll From 44fd91764d1f60385231a82fcdf02918f861560f Mon Sep 17 00:00:00 2001 From: Max G Date: Tue, 26 Mar 2024 17:15:41 +0530 Subject: [PATCH 30/39] fix(backend): multitab service statuses (#1143) --- src/contexts/backend/backend.tsx | 93 +++++++++++++++++++------------- src/services/CozoDb/cozoDb.ts | 1 + 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/contexts/backend/backend.tsx b/src/contexts/backend/backend.tsx index 2e1034cf5..b8c9547c4 100644 --- a/src/contexts/backend/backend.tsx +++ b/src/contexts/backend/backend.tsx @@ -1,4 +1,10 @@ -import React, { useContext, useEffect, useMemo, useState } from 'react'; +import React, { + useCallback, + useContext, + useEffect, + useMemo, + useState, +} from 'react'; import { useAppDispatch, useAppSelector } from 'src/redux/hooks'; import { proxy, Remote } from 'comlink'; import { backgroundWorkerInstance } from 'src/services/backend/workers/background/service'; @@ -11,11 +17,14 @@ import { selectCurrentAddress } from 'src/redux/features/pocket'; import DbApiWrapper from 'src/services/backend/services/dataSource/indexedDb/dbApiWrapper'; import { CozoDbWorker } from 'src/services/backend/workers/db/worker'; import { BackgroundWorker } from 'src/services/backend/workers/background/worker'; -import { SenseApi, createSenseApi } from './services/senseApi'; + import { SyncEntryName } from 'src/services/backend/types/services'; -// import BroadcastChannelListener from 'src/services/backend/channels/BroadcastChannelListener'; import { DB_NAME } from 'src/services/CozoDb/cozoDb'; import { RESET_SYNC_STATE_ACTION_NAME } from 'src/redux/reducers/backend'; +import BroadcastChannelSender from 'src/services/backend/channels/BroadcastChannelSender'; +// import BroadcastChannelListener from 'src/services/backend/channels/BroadcastChannelListener'; + +import { SenseApi, createSenseApi } from './services/senseApi'; const setupStoragePersistence = async () => { let isPersistedStorage = await navigator.storage.persisted(); @@ -72,6 +81,7 @@ window.cyb.db = { }; // const dbApi = new DbApiWrapper(); +const bcSender = new BroadcastChannelSender(); function BackendProvider({ children }: { children: React.ReactNode }) { const dispatch = useAppDispatch(); @@ -120,6 +130,31 @@ function BackendProvider({ children }: { children: React.ReactNode }) { return null; }, [isDbInitialized, dbApi, myAddress, followings]); + const createDbApi = useCallback(() => { + const dbApi = new DbApiWrapper(); + + dbApi.init(proxy(cozoDbWorkerInstance)); + setDbApi(dbApi); + return dbApi; + }, []); + + const loadIpfs = async () => { + const ipfsOpts = getIpfsOpts(); + await backgroundWorkerInstance.ipfsApi.stop(); + console.time('🔋 Ipfs started.'); + + await backgroundWorkerInstance.ipfsApi + .start(ipfsOpts) + .then(() => { + setIpfsError(null); + console.timeEnd('🔋 Ipfs started.'); + }) + .catch((err) => { + setIpfsError(err); + console.log(`☠️ Ipfs error: ${err}`); + }); + }; + useEffect(() => { // eslint-disable-next-line @typescript-eslint/no-unused-vars // const channel = new BroadcastChannelListener((msg) => { @@ -128,6 +163,18 @@ function BackendProvider({ children }: { children: React.ReactNode }) { // }); const channel = new RxBroadcastChannelListener(dispatch); + const loadCozoDb = async () => { + console.time('🔋 CozoDb worker started.'); + await cozoDbWorkerInstance + .init() + .then(async () => { + const dbApi = createDbApi(); + // pass dbApi into background worker + await backgroundWorkerInstance.init(proxy(dbApi)); + }) + .then(() => console.timeEnd('🔋 CozoDb worker started.')); + }; + (async () => { console.log( process.env.IS_DEV @@ -140,6 +187,8 @@ function BackendProvider({ children }: { children: React.ReactNode }) { const isInitialized = await backgroundWorkerInstance.isInitialized(); if (isInitialized) { console.log('🔋 Background worker already active.'); + bcSender.postServiceStatus('ipfs', 'started'); + bcSender.postServiceStatus('sync', 'started'); return Promise.resolve(); } return loadIpfs(); @@ -149,6 +198,8 @@ function BackendProvider({ children }: { children: React.ReactNode }) { const isInitialized = await cozoDbWorkerInstance.isInitialized(); if (isInitialized) { console.log('🔋 CozoDb worker already active.'); + bcSender.postServiceStatus('db', 'started'); + createDbApi(); return Promise.resolve(); } return loadCozoDb(); @@ -160,41 +211,7 @@ function BackendProvider({ children }: { children: React.ReactNode }) { window.q = backgroundWorkerInstance.ipfsQueue; return () => channel.close(); - }, [dispatch]); - - const loadCozoDb = async () => { - console.time('🔋 CozoDb worker started.'); - await cozoDbWorkerInstance - .init() - .then(async () => { - // init dbApi - // TODO: refactor to use simple object instead of global instance - const dbApi = new DbApiWrapper(); - dbApi.init(proxy(cozoDbWorkerInstance)); - setDbApi(dbApi); - - // pass dbApi into background worker - await backgroundWorkerInstance.init(proxy(dbApi)); - }) - .then(() => console.timeEnd('🔋 CozoDb worker started.')); - }; - - const loadIpfs = async () => { - const ipfsOpts = getIpfsOpts(); - await backgroundWorkerInstance.ipfsApi.stop(); - console.time('🔋 Ipfs started.'); - - await backgroundWorkerInstance.ipfsApi - .start(ipfsOpts) - .then(() => { - setIpfsError(null); - console.timeEnd('🔋 Ipfs started.'); - }) - .catch((err) => { - setIpfsError(err); - console.log(`☠️ Ipfs error: ${err}`); - }); - }; + }, [dispatch, createDbApi]); const valueMemo = useMemo( () => diff --git a/src/services/CozoDb/cozoDb.ts b/src/services/CozoDb/cozoDb.ts index 73220a7f2..3105ff513 100644 --- a/src/services/CozoDb/cozoDb.ts +++ b/src/services/CozoDb/cozoDb.ts @@ -148,6 +148,7 @@ function createCozoDb() { // console.log('----> runCommand ', command, result); if (!result.ok) { + console.log('----> runCommand error ', command, result); throw new DBResultError(result); } From d8f81608b57c42f7e365286049043315821fecdd Mon Sep 17 00:00:00 2001 From: OggyKUN <46613040+OggyKUN@users.noreply.github.com> Date: Wed, 10 Apr 2024 04:51:59 +0300 Subject: [PATCH 31/39] feat(community): add proposals comments (#1136) --- src/containers/governance/proposalsDetail.jsx | 42 +++-- .../proposalsDetailTableComments.jsx | 175 ++++++++++++++++++ src/containers/governance/proposalsRoutes.jsx | 54 ++++++ src/containers/governance/tabList.tsx | 22 +++ src/containers/governance/tabsLayout.tsx | 13 ++ src/containers/governance/type.ts | 5 + src/routes.ts | 2 +- 7 files changed, 292 insertions(+), 21 deletions(-) create mode 100644 src/containers/governance/proposalsDetailTableComments.jsx create mode 100644 src/containers/governance/proposalsRoutes.jsx create mode 100644 src/containers/governance/tabList.tsx create mode 100644 src/containers/governance/tabsLayout.tsx create mode 100644 src/containers/governance/type.ts diff --git a/src/containers/governance/proposalsDetail.jsx b/src/containers/governance/proposalsDetail.jsx index 6bde660de..c39fc514c 100644 --- a/src/containers/governance/proposalsDetail.jsx +++ b/src/containers/governance/proposalsDetail.jsx @@ -1,7 +1,7 @@ /* eslint-disable react/no-children-prop */ import { useEffect, useState } from 'react'; import { Pane, Text, ActionBar } from '@cybercongress/gravity'; -import { Link, useParams } from 'react-router-dom'; +import { Link, useParams, Routes, Route } from 'react-router-dom'; import { connect } from 'react-redux'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; @@ -21,12 +21,12 @@ import ActionBarDetail from './actionBarDatail'; import { formatNumber } from '../../utils/utils'; -import ProposalsIdDetail from './proposalsIdDetail'; import ProposalsDetailProgressBar from './proposalsDetailProgressBar'; -import ProposalsIdDetailTableVoters from './proposalsDetailTableVoters'; import { PROPOSAL_STATUS } from '../../utils/config'; import useSetActiveAddress from '../../hooks/useSetActiveAddress'; import { MainContainer } from '../portal/components'; +import ProposalsRoutes from './proposalsRoutes'; +import { useLocation, useNavigate } from 'react-router-dom'; const finalTallyResult = (item) => { const finalVotes = { @@ -184,6 +184,15 @@ function ProposalsDetail({ defaultAccount }) { console.log(`proposals`, proposals); console.log(`addressActive`, addressActive); + const location = useLocation(); + const navigate = useNavigate(); + + useEffect(() => { + if (location.pathname === `/senate/${proposalId}`) { + navigate(`/senate/${proposalId}/comments`); + } + }, [location.pathname]); + return ( <> @@ -192,7 +201,6 @@ function ProposalsDetail({ defaultAccount }) { {proposals.title && ` #${proposalId} ${proposals.title}`} - {proposals.status && ( @@ -275,29 +283,23 @@ function ProposalsDetail({ defaultAccount }) { /> )} - - - - - {proposals.status > PROPOSAL_STATUS.PROPOSAL_STATUS_DEPOSIT_PERIOD && ( - - )} {addressActive !== null && addressActive.keys === 'keplr' ? ( - add address to your pocket from keplr + connect diff --git a/src/containers/governance/proposalsDetailTableComments.jsx b/src/containers/governance/proposalsDetailTableComments.jsx new file mode 100644 index 000000000..611274aeb --- /dev/null +++ b/src/containers/governance/proposalsDetailTableComments.jsx @@ -0,0 +1,175 @@ +import { useState, useEffect } from 'react'; +import InfiniteScroll from 'react-infinite-scroll-component'; +import Spark from 'src/components/search/Spark/Spark'; +import useSearchData from 'src/containers/Search/hooks/useSearchData'; +import { LinksTypeFilter, SortBy } from 'src/containers/Search/types'; +import styles from 'src/containers/Search/SearchResults.module.scss'; +import FirstItems from 'src/containers/Search/_FirstItems.refactor'; +import Loader2 from 'src/components/ui/Loader2'; +import Display from 'src/components/containerGradient/Display/Display'; +import ActionBarContainer from 'src/containers/Search/ActionBarContainer'; +import Filters from 'src/containers/Search/Filters/Filters'; +import { useBackend } from 'src/contexts/backend/backend'; +import { useDevice } from 'src/contexts/device'; + +import { IpfsContentType } from 'src/utils/ipfs/ipfs'; + +export const initialContentTypeFilterState = { + text: false, + image: false, + video: false, + pdf: false, + link: false, + // audio: false, +}; + +const sortByLSKey = 'search-sort'; + +function ProposalsDetailTableComments({ proposalId }) { + const { ipfsApi } = useBackend(); + const query = `bostrom proposal ${proposalId}`; + + const [proposalHash, setproposalHash] = useState(''); + const [rankLink, setRankLink] = useState(null); + + const [contentType, setContentType] = useState<{ + [key: string]: IpfsContentType; + }>({}); + + const [contentTypeFilter, setContentTypeFilter] = useState( + initialContentTypeFilterState + ); + const [sortBy, setSortBy] = useState( + localStorage.getItem(sortByLSKey) || SortBy.rank + ); + const [linksTypeFilter, setLinksTypeFilter] = useState(LinksTypeFilter.all); + + const { isMobile: mobile } = useDevice(); + + useEffect(() => { + setContentTypeFilter(initialContentTypeFilterState); + setContentType({}); + + (async () => { + let keywordHashTemp = ''; + + keywordHashTemp = await ipfsApi.addContent(query); + + setproposalHash(keywordHashTemp); + })(); + }, [query]); + + const onClickRank = async (key) => { + if (rankLink === key) { + setRankLink(null); + } else { + setRankLink(key); + } +}; + + const { + data: items, + total, + error, + hasMore, + isInitialLoading, + refetch, + fetchNextPage: next, + } = useSearchData(proposalHash, { + sortBy, + linksType: linksTypeFilter, + }); + + const renderItems = items + .filter((item) => { + const { cid } = item; + + if (!Object.values(contentTypeFilter).some((value) => value)) { + return true; + } + if (!contentType[cid]) { + return false; + } + return contentTypeFilter[contentType[cid]]; + }) + .map((key, i) => { + + return ( + + setContentType((items) => { + return { + ...items, + [key.cid]: type, + }; + }) + } + /> + ); + }); + + return ( + <> + + +
+ + + {isInitialLoading ? ( + + ) : Object.keys(renderItems).length > 0 ? ( + } + > + {renderItems} + + ) : error ? ( + +

{error.message}

+
+ ) : ( + + there are no comments to this proposal
be the first and + create one +
+ )} +
+ {!mobile && ( +
+ { + refetch(); + setRankLink(null); + }} + rankLink={rankLink} + /> +
+ )} + + ); +} +export default ProposalsDetailTableComments; + diff --git a/src/containers/governance/proposalsRoutes.jsx b/src/containers/governance/proposalsRoutes.jsx new file mode 100644 index 000000000..5b191f997 --- /dev/null +++ b/src/containers/governance/proposalsRoutes.jsx @@ -0,0 +1,54 @@ +import { Routes, Route } from 'react-router-dom'; +import ProposalsDetailTableComments from './proposalsDetailTableComments'; +import ProposalsIdDetail from './proposalsIdDetail'; +import ProposalsIdDetailTableVoters from './proposalsDetailTableVoters'; +import Layout from './Layout'; + +function ProposalsRoutes({ + proposalId, + proposals, + tallying, + tally, + totalDeposit, + updateFunc, + proposalStatus, +}) { + return ( + + }> + } + /> + } + /> + + } + /> + proposalStatus.PROPOSAL_STATUS_DEPOSIT_PERIOD ? ( + + ) : null + } + /> + + + ); +} + +export default ProposalsRoutes; diff --git a/src/containers/governance/tabList.tsx b/src/containers/governance/tabList.tsx new file mode 100644 index 000000000..b26ce8c59 --- /dev/null +++ b/src/containers/governance/tabList.tsx @@ -0,0 +1,22 @@ +import { Tabs } from 'src/components'; +import { useLocation } from 'react-router-dom'; +import { TypePages } from './type'; + +function TabListGoverance() { + const location = useLocation(); + const locationSplit = location.pathname.replace(/^\/|\/$/g, '').split('/'); + let active = Object.values(TypePages).find( + (item) => item === locationSplit[2] + ); + if (!active) { + return null; + } + return ( + ({ to: key, key }))} + /> + ); +} + +export default TabListGoverance; diff --git a/src/containers/governance/tabsLayout.tsx b/src/containers/governance/tabsLayout.tsx new file mode 100644 index 000000000..7648451c1 --- /dev/null +++ b/src/containers/governance/tabsLayout.tsx @@ -0,0 +1,13 @@ +import { Outlet } from 'react-router-dom'; +import TabListGoverance from './tabList'; + +function Layout() { + return ( +
+ + +
+ ); +} + +export default Layout; diff --git a/src/containers/governance/type.ts b/src/containers/governance/type.ts new file mode 100644 index 000000000..d8fb740fe --- /dev/null +++ b/src/containers/governance/type.ts @@ -0,0 +1,5 @@ +export enum TypePages { + voters = 'voters', + comments = 'comments', + meta = 'meta', +} diff --git a/src/routes.ts b/src/routes.ts index a69530f42..d48145eb6 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -7,7 +7,7 @@ export const routes = { path: '/temple', }, senateProposal: { - path: '/senate/:proposalId', + path: '/senate/:proposalId/*', getLink: (proposalId: number) => `/senate/${proposalId}`, }, sphere: { From abe3e3ab607f6594d8bc3e04ba1a07099f8aa00a Mon Sep 17 00:00:00 2001 From: OggyKUN <46613040+OggyKUN@users.noreply.github.com> Date: Wed, 10 Apr 2024 13:34:20 +0300 Subject: [PATCH 32/39] fix(senate): fix imports (#1150) --- src/containers/governance/proposalsDetail.jsx | 5 +---- src/containers/governance/proposalsRoutes.jsx | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/containers/governance/proposalsDetail.jsx b/src/containers/governance/proposalsDetail.jsx index c39fc514c..305b66f93 100644 --- a/src/containers/governance/proposalsDetail.jsx +++ b/src/containers/governance/proposalsDetail.jsx @@ -1,7 +1,7 @@ /* eslint-disable react/no-children-prop */ import { useEffect, useState } from 'react'; import { Pane, Text, ActionBar } from '@cybercongress/gravity'; -import { Link, useParams, Routes, Route } from 'react-router-dom'; +import { Link, useParams } from 'react-router-dom'; import { connect } from 'react-redux'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; @@ -181,9 +181,6 @@ function ProposalsDetail({ defaultAccount }) { return string; }; - console.log(`proposals`, proposals); - console.log(`addressActive`, addressActive); - const location = useLocation(); const navigate = useNavigate(); diff --git a/src/containers/governance/proposalsRoutes.jsx b/src/containers/governance/proposalsRoutes.jsx index 5b191f997..b8dd7c584 100644 --- a/src/containers/governance/proposalsRoutes.jsx +++ b/src/containers/governance/proposalsRoutes.jsx @@ -2,7 +2,7 @@ import { Routes, Route } from 'react-router-dom'; import ProposalsDetailTableComments from './proposalsDetailTableComments'; import ProposalsIdDetail from './proposalsIdDetail'; import ProposalsIdDetailTableVoters from './proposalsDetailTableVoters'; -import Layout from './Layout'; +import Layout from './tabsLayout'; function ProposalsRoutes({ proposalId, From 69d64bb98f39388070b783ef312328a99513f573 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 14 Apr 2024 22:11:30 +0530 Subject: [PATCH 33/39] build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 (#1138) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index 0aa625e69..3cd58ef64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -29703,9 +29703,9 @@ webpack-cli@^4.10.0: webpack-merge "^5.7.3" webpack-dev-middleware@^5.3.1: - version "5.3.3" - resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz#efae67c2793908e7311f1d9b06f2a08dcc97e51f" - integrity sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA== + version "5.3.4" + resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-5.3.4.tgz#eb7b39281cbce10e104eb2b8bf2b63fce49a3517" + integrity sha512-BVdTqhhs+0IfoeAf7EoH5WE+exCmqGerHfDM0IL096Px60Tq2Mn9MAbnaGUe6HiMa41KMCYF19gyzZmBcq/o4Q== dependencies: colorette "^2.0.10" memfs "^3.4.3" @@ -29714,9 +29714,9 @@ webpack-dev-middleware@^5.3.1: schema-utils "^4.0.0" webpack-dev-middleware@^6.1.1: - version "6.1.1" - resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-6.1.1.tgz#6bbc257ec83ae15522de7a62f995630efde7cc3d" - integrity sha512-y51HrHaFeeWir0YO4f0g+9GwZawuigzcAdRNon6jErXy/SqV/+O6eaVAzDqE6t3e3NpGeR5CS+cCDaTC+V3yEQ== + version "6.1.2" + resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-6.1.2.tgz#0463232e59b7d7330fa154121528d484d36eb973" + integrity sha512-Wu+EHmX326YPYUpQLKmKbTyZZJIB8/n6R09pTmB03kJmnMsVPTo9COzHZFr01txwaCAuZvfBJE4ZCHRcKs5JaQ== dependencies: colorette "^2.0.10" memfs "^3.4.12" From d0ea8e9894ad1a81e86394cc3b4aa3c3ebb15400 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 14 Apr 2024 22:12:36 +0530 Subject: [PATCH 34/39] build(deps): bump web3-utils from 1.9.0 to 4.2.1 (#1142) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 116 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 85 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 077a9bb23..e133cc0f6 100644 --- a/package.json +++ b/package.json @@ -243,7 +243,7 @@ "ts-jest-resolver": "^2.0.1", "videostream": "^3.2.2", "web3": "1.2.4", - "web3-utils": "^1.2.4", + "web3-utils": "^4.2.1", "worker-url": "^1.1.0" }, "prec-commit": [ diff --git a/yarn.lock b/yarn.lock index 3cd58ef64..427659c20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5986,6 +5986,13 @@ resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-0.3.0.tgz#6ba3090afdc7a7051393486f6af210e62e0f04ec" integrity sha512-ldbrnOjmNRwFdXcTM6uXDcxpMIFrbzAWNnpBPp4oTJTFF0XByGD6vf45WrehZGXRQTRVV+Zm8YP+EgEf+e4cWA== +"@noble/curves@1.3.0", "@noble/curves@~1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.3.0.tgz#01be46da4fd195822dab821e72f71bf4aeec635e" + integrity sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA== + dependencies: + "@noble/hashes" "1.3.3" + "@noble/curves@^1.1.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" @@ -6003,6 +6010,11 @@ resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== +"@noble/hashes@1.3.3", "@noble/hashes@~1.3.2": + version "1.3.3" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699" + integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA== + "@noble/hashes@^1", "@noble/hashes@^1.0.0", "@noble/hashes@^1.2.0": version "1.3.0" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.0.tgz#085fd70f6d7d9d109671090ccae1d3bec62554a1" @@ -6438,6 +6450,28 @@ prop-types "^15.7.2" react-is "^16.9.0" +"@scure/base@~1.1.4": + version "1.1.6" + resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.6.tgz#8ce5d304b436e4c84f896e0550c83e4d88cb917d" + integrity sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g== + +"@scure/bip32@1.3.3": + version "1.3.3" + resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.3.tgz#a9624991dc8767087c57999a5d79488f48eae6c8" + integrity sha512-LJaN3HwRbfQK0X1xFSi0Q9amqOgzQnnDngIt+ZlsBC3Bm7/nE7K0kwshZHyaru79yIVRv/e1mQAjZyuZG6jOFQ== + dependencies: + "@noble/curves" "~1.3.0" + "@noble/hashes" "~1.3.2" + "@scure/base" "~1.1.4" + +"@scure/bip39@1.2.2": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.2.2.tgz#f3426813f4ced11a47489cbcf7294aa963966527" + integrity sha512-HYf9TUXG80beW+hGAt3TRM8wU6pQoYur9iNypTROm42dorCGmLnFe3eWjz3gOq6G62H2WRh0FCzAR1PI+29zIA== + dependencies: + "@noble/hashes" "~1.3.2" + "@scure/base" "~1.1.4" + "@sinclair/typebox@^0.25.16": version "0.25.24" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.25.24.tgz#8c7688559979f7079aacaf31aa881c3aa410b718" @@ -7879,13 +7913,6 @@ dependencies: "@types/node" "*" -"@types/bn.js@^5.1.0": - version "5.1.1" - resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.1.tgz#b51e1b55920a4ca26e9285ff79936bbdec910682" - integrity sha512-qNrYbZqMx0uJAfKnKclPh+dTwK33KfLHYqtyODwd5HnXOjnkhc4qgn3BrK6RWyGZm5+sIFE7Q7Vz6QQtJB7w7g== - dependencies: - "@types/node" "*" - "@types/body-parser@*": version "1.19.2" resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0" @@ -10371,7 +10398,7 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.0, bn.js@^4.11.6, bn.js@^4.11.8, bn.js@^ resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== -bn.js@^5.0.0, bn.js@^5.1.2, bn.js@^5.2.0, bn.js@^5.2.1: +bn.js@^5.0.0, bn.js@^5.2.0, bn.js@^5.2.1: version "5.2.1" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== @@ -14613,6 +14640,16 @@ ethereum-cryptography@^0.1.3: secp256k1 "^4.0.1" setimmediate "^1.0.5" +ethereum-cryptography@^2.0.0: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-2.1.3.tgz#1352270ed3b339fe25af5ceeadcf1b9c8e30768a" + integrity sha512-BlwbIL7/P45W8FGW2r7LGuvoEZ+7PWsniMvQ4p5s2xCyw9tmaDlpfsN9HjAucbF+t/qpVHwZUisgfK24TCW8aA== + dependencies: + "@noble/curves" "1.3.0" + "@noble/hashes" "1.3.3" + "@scure/bip32" "1.3.3" + "@scure/bip39" "1.2.2" + ethereumjs-common@^1.3.2, ethereumjs-common@^1.5.0: version "1.5.2" resolved "https://registry.yarnpkg.com/ethereumjs-common/-/ethereumjs-common-1.5.2.tgz#2065dbe9214e850f2e955a80e650cb6999066979" @@ -14639,17 +14676,6 @@ ethereumjs-util@^6.0.0: ethjs-util "0.1.6" rlp "^2.2.3" -ethereumjs-util@^7.1.0: - version "7.1.5" - resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.5.tgz#9ecf04861e4fbbeed7465ece5f23317ad1129181" - integrity sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg== - dependencies: - "@types/bn.js" "^5.1.0" - bn.js "^5.1.2" - create-hash "^1.1.2" - ethereum-cryptography "^0.1.3" - rlp "^2.2.4" - ethers@4.0.0-beta.3: version "4.0.0-beta.3" resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.0-beta.3.tgz#15bef14e57e94ecbeb7f9b39dd0a4bd435bc9066" @@ -25990,7 +26016,7 @@ ripemd160@^2.0.0, ripemd160@^2.0.1, ripemd160@^2.0.2: hash-base "^3.0.0" inherits "^2.0.1" -rlp@^2.2.3, rlp@^2.2.4: +rlp@^2.2.3: version "2.2.7" resolved "https://registry.yarnpkg.com/rlp/-/rlp-2.2.7.tgz#33f31c4afac81124ac4b283e2bd4d9720b30beaf" integrity sha512-d5gdPmgQ0Z+AklL2NVXr/IoSjNZFfTVvQWzL/AM2AOcSzYP2xjlb0AC8YyCLc41MSNf6P6QVtjgPdmVtzb+4lQ== @@ -29032,7 +29058,7 @@ util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== -util@^0.12.0, util@^0.12.4: +util@^0.12.0, util@^0.12.4, util@^0.12.5: version "0.12.5" resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA== @@ -29470,6 +29496,13 @@ web3-core@1.2.4: web3-core-requestmanager "1.2.4" web3-utils "1.2.4" +web3-errors@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/web3-errors/-/web3-errors-1.1.4.tgz#5667a0a5f66fc936e101ef32032ccc1e8ca4d5a1" + integrity sha512-WahtszSqILez+83AxGecVroyZsMuuRT+KmQp4Si5P4Rnqbczno1k748PCrZTS1J4UCPmXMG2/Vt+0Bz2zwXkwQ== + dependencies: + web3-types "^1.3.1" + web3-eth-abi@1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/web3-eth-abi/-/web3-eth-abi-1.2.4.tgz#5b73e5ef70b03999227066d5d1310b168845e2b8" @@ -29610,6 +29643,11 @@ web3-shh@1.2.4: web3-core-subscriptions "1.2.4" web3-net "1.2.4" +web3-types@^1.3.1, web3-types@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/web3-types/-/web3-types-1.5.0.tgz#35b5c0ab149b0d566efeaed8ddaa40db159c748e" + integrity sha512-geWuMIeegQ8AedKAO6wO4G4j1gyQ1F/AyKLMw2vud4bsfZayyzWJgCMDZtjYMm5uo2a7i8j1W3/4QFmzlSy5cw== + web3-utils@1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/web3-utils/-/web3-utils-1.2.4.tgz#96832a39a66b05bf8862a5b0bdad2799d709d951" @@ -29624,18 +29662,27 @@ web3-utils@1.2.4: underscore "1.9.1" utf8 "3.0.0" -web3-utils@^1.2.4: - version "1.9.0" - resolved "https://registry.yarnpkg.com/web3-utils/-/web3-utils-1.9.0.tgz#7c5775a47586cefb4ad488831be8f6627be9283d" - integrity sha512-p++69rCNNfu2jM9n5+VD/g26l+qkEOQ1m6cfRQCbH8ZRrtquTmrirJMgTmyOoax5a5XRYOuws14aypCOs51pdQ== +web3-utils@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/web3-utils/-/web3-utils-4.2.1.tgz#326bc6e9e4d047f7b38ba68bee1399c4f9f621e3" + integrity sha512-Fk29BlEqD9Q9Cnw4pBkKw7czcXiRpsSco/BzEUl4ye0ZTSHANQFfjsfQmNm4t7uY11u6Ah+8F3tNjBeU4CA80A== dependencies: - bn.js "^5.2.1" - ethereum-bloom-filters "^1.0.6" - ethereumjs-util "^7.1.0" - ethjs-unit "0.1.6" - number-to-bn "1.7.0" - randombytes "^2.1.0" - utf8 "3.0.0" + ethereum-cryptography "^2.0.0" + eventemitter3 "^5.0.1" + web3-errors "^1.1.4" + web3-types "^1.5.0" + web3-validator "^2.0.4" + +web3-validator@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/web3-validator/-/web3-validator-2.0.4.tgz#66f34c94f21a3c94d0dc2a2d30deb8a379825d38" + integrity sha512-qRxVePwdW+SByOmTpDZFWHIUAa7PswvxNszrOua6BoGqAhERo5oJZBN+EbWtK/+O+ApNxt5FR3nCPmiZldiOQA== + dependencies: + ethereum-cryptography "^2.0.0" + util "^0.12.5" + web3-errors "^1.1.4" + web3-types "^1.3.1" + zod "^3.21.4" web3@1.2.4: version "1.2.4" @@ -30442,6 +30489,11 @@ zero-crossings@^1.0.0: dependencies: cwise-compiler "^1.0.0" +zod@^3.21.4: + version "3.22.4" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" + integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg== + zwitch@^2.0.0, zwitch@^2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-2.0.4.tgz#c827d4b0acb76fc3e685a4c6ec2902d51070e9d7" From d70a976511e3ac6b50d66fb637eeb164a3bf4b10 Mon Sep 17 00:00:00 2001 From: OggyKUN <46613040+OggyKUN@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:32:54 +0300 Subject: [PATCH 35/39] fix(senate): fix unable to add comments (#1151) --- src/containers/governance/proposalsDetail.jsx | 8 ++- .../proposalsDetailTableComments.jsx | 72 ++++++++++++------- src/containers/governance/proposalsRoutes.jsx | 5 +- 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/containers/governance/proposalsDetail.jsx b/src/containers/governance/proposalsDetail.jsx index 305b66f93..75c82b725 100644 --- a/src/containers/governance/proposalsDetail.jsx +++ b/src/containers/governance/proposalsDetail.jsx @@ -298,7 +298,9 @@ function ProposalsDetail({ defaultAccount }) { proposalStatus={PROPOSAL_STATUS} /> - {addressActive !== null && addressActive.keys === 'keplr' ? ( + {addressActive !== null && + addressActive.keys === 'keplr' && + location.pathname === `/senate/${proposalId}/voters` ? ( setUpdateFunc((item) => item + 1)} addressActive={addressActive} /> - ) : ( + ) : addressActive === null ? ( - )} + ) : null} ); } diff --git a/src/containers/governance/proposalsDetailTableComments.jsx b/src/containers/governance/proposalsDetailTableComments.jsx index 611274aeb..f91774bf0 100644 --- a/src/containers/governance/proposalsDetailTableComments.jsx +++ b/src/containers/governance/proposalsDetailTableComments.jsx @@ -11,6 +11,10 @@ import ActionBarContainer from 'src/containers/Search/ActionBarContainer'; import Filters from 'src/containers/Search/Filters/Filters'; import { useBackend } from 'src/contexts/backend/backend'; import { useDevice } from 'src/contexts/device'; +import { useParams } from 'react-router-dom'; + +import { getIpfsHash } from 'src/utils/ipfs/helpers'; +import { encodeSlash } from '../../utils/utils'; import { IpfsContentType } from 'src/utils/ipfs/ipfs'; @@ -25,8 +29,11 @@ export const initialContentTypeFilterState = { const sortByLSKey = 'search-sort'; -function ProposalsDetailTableComments({ proposalId }) { +function ProposalsDetailTableComments() { + const { proposalId } = useParams(); + const { ipfsApi } = useBackend(); + const query = `bostrom proposal ${proposalId}`; const [proposalHash, setproposalHash] = useState(''); @@ -40,25 +47,54 @@ function ProposalsDetailTableComments({ proposalId }) { initialContentTypeFilterState ); const [sortBy, setSortBy] = useState( - localStorage.getItem(sortByLSKey) || SortBy.rank + localStorage.getItem(sortByLSKey) || SortBy.date ); const [linksTypeFilter, setLinksTypeFilter] = useState(LinksTypeFilter.all); - + + const { + data: items, + total, + error, + hasMore, + isInitialLoading, + refetch, + fetchNextPage: next, + } = useSearchData(proposalHash, { + sortBy, + linksType: linksTypeFilter, + }); const { isMobile: mobile } = useDevice(); useEffect(() => { setContentTypeFilter(initialContentTypeFilterState); setContentType({}); - (async () => { +(async () => { + try { let keywordHashTemp = ''; - - keywordHashTemp = await ipfsApi.addContent(query); - + keywordHashTemp = await getIpfsHash(encodeSlash(query)); setproposalHash(keywordHashTemp); - })(); - }, [query]); + } catch (error) { + console.error("Error getting hash from getIpfsHash:", error); + try { + keywordHashTemp = await ipfsApi.addContent(query); + setproposalHash(keywordHashTemp); + } catch (error) { + console.error("Error adding content using ipfsApi:", error); + } + } + })(); +}, [query]); + const updateComments = async () => { + try { + await refetch(); + setRankLink(null); + } finally { + console.error('Error updating comments:', error); + } +}; + const onClickRank = async (key) => { if (rankLink === key) { setRankLink(null); @@ -67,19 +103,6 @@ function ProposalsDetailTableComments({ proposalId }) { } }; - const { - data: items, - total, - error, - hasMore, - isInitialLoading, - refetch, - fetchNextPage: next, - } = useSearchData(proposalHash, { - sortBy, - linksType: linksTypeFilter, - }); - const renderItems = items .filter((item) => { const { cid } = item; @@ -160,10 +183,7 @@ function ProposalsDetailTableComments({ proposalId }) { { - refetch(); - setRankLink(null); - }} + update={updateComments} rankLink={rankLink} />
diff --git a/src/containers/governance/proposalsRoutes.jsx b/src/containers/governance/proposalsRoutes.jsx index b8dd7c584..270dc292d 100644 --- a/src/containers/governance/proposalsRoutes.jsx +++ b/src/containers/governance/proposalsRoutes.jsx @@ -20,10 +20,7 @@ function ProposalsRoutes({ index element={} /> - } - /> + } /> Date: Mon, 15 Apr 2024 18:16:15 +0530 Subject: [PATCH 36/39] build(deps): bump express from 4.18.2 to 4.19.2 (#1144) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/yarn.lock b/yarn.lock index 427659c20..cabdb7596 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10403,25 +10403,7 @@ bn.js@^5.0.0, bn.js@^5.2.0, bn.js@^5.2.1: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== -body-parser@1.20.1: - version "1.20.1" - resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.1.tgz#b1812a8912c195cd371a3ee5e66faa2338a5c668" - integrity sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw== - dependencies: - bytes "3.1.2" - content-type "~1.0.4" - debug "2.6.9" - depd "2.0.0" - destroy "1.2.0" - http-errors "2.0.0" - iconv-lite "0.4.24" - on-finished "2.4.1" - qs "6.11.0" - raw-body "2.5.1" - type-is "~1.6.18" - unpipe "1.0.0" - -body-parser@^1.16.0: +body-parser@1.20.2, body-parser@^1.16.0: version "1.20.2" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.2.tgz#6feb0e21c4724d06de7ff38da36dad4f57a747fd" integrity sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA== @@ -11840,10 +11822,10 @@ cookie-signature@1.0.6: resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" integrity sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ== -cookie@0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" - integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== +cookie@0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" + integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== cookiejar@^2.1.1: version "2.1.4" @@ -14908,16 +14890,16 @@ expect@^29.7.0: jest-util "^29.7.0" express@^4.14.0, express@^4.17.3: - version "4.18.2" - resolved "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz#3fabe08296e930c796c19e3c516979386ba9fd59" - integrity sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ== + version "4.19.2" + resolved "https://registry.yarnpkg.com/express/-/express-4.19.2.tgz#e25437827a3aa7f2a827bc8171bbbb664a356465" + integrity sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q== dependencies: accepts "~1.3.8" array-flatten "1.1.1" - body-parser "1.20.1" + body-parser "1.20.2" content-disposition "0.5.4" content-type "~1.0.4" - cookie "0.5.0" + cookie "0.6.0" cookie-signature "1.0.6" debug "2.6.9" depd "2.0.0" @@ -24699,16 +24681,6 @@ rate-limiter-flexible@^3.0.0: resolved "https://registry.yarnpkg.com/rate-limiter-flexible/-/rate-limiter-flexible-3.0.0.tgz#1dba6de44d4d5a5e6494774c2ff7657e82856673" integrity sha512-janAJkWxWxmLka0hV+XvCTo0M8keeSeOuz8ZL33cTXrkS4ek9mQ2VJm9ri7fm03oTVth19Sfqb1ijCmo7K/vAg== -raw-body@2.5.1: - version "2.5.1" - resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.1.tgz#fe1b1628b181b700215e5fd42389f98b71392857" - integrity sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig== - dependencies: - bytes "3.1.2" - http-errors "2.0.0" - iconv-lite "0.4.24" - unpipe "1.0.0" - raw-body@2.5.2: version "2.5.2" resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.2.tgz#99febd83b90e08975087e8f1f9419a149366b68a" From 60febe1721c83b4079a917cb4e3a859a429f61cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:16:46 +0530 Subject: [PATCH 37/39] build(deps): bump undici from 5.28.3 to 5.28.4 (#1147) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index cabdb7596..365d00546 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28661,9 +28661,9 @@ underscore@1.9.1: integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg== undici@^5.12.0: - version "5.28.3" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b" - integrity sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA== + version "5.28.4" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" + integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== dependencies: "@fastify/busboy" "^2.0.0" From dfd15839a765aae7d0357e6f382c4737fdb8061e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:37:43 +0530 Subject: [PATCH 38/39] build(deps): bump axios from 0.21.4 to 1.6.8 (#1152) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/yarn.lock b/yarn.lock index 365d00546..6ec7791e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9885,21 +9885,12 @@ axios@^0.27.2: follow-redirects "^1.14.9" form-data "^4.0.0" -axios@^1.3.3: - version "1.6.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.0.tgz#f1e5292f26b2fd5c2e66876adc5b06cdbd7d2102" - integrity sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg== - dependencies: - follow-redirects "^1.15.0" - form-data "^4.0.0" - proxy-from-env "^1.1.0" - -axios@^1.6.0: - version "1.6.7" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7" - integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== +axios@^1.3.3, axios@^1.6.0: + version "1.6.8" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" + integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== dependencies: - follow-redirects "^1.15.4" + follow-redirects "^1.15.6" form-data "^4.0.0" proxy-from-env "^1.1.0" @@ -15422,7 +15413,7 @@ fnv1a@^1.0.1: resolved "https://registry.yarnpkg.com/fnv1a/-/fnv1a-1.1.1.tgz#4e01d51bae60735d00e54ffde02581fe2e74f465" integrity sha512-S2HviLR9UyNbt8R+vU6YeQtL8RliPwez9DQEVba5MAvN3Od+RSgKUSL2+qveOMt3owIeBukKoRu2enoOck5uag== -follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.9, follow-redirects@^1.15.0, follow-redirects@^1.15.4: +follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.9, follow-redirects@^1.15.6: version "1.15.6" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== From e78e65f8fab3a95cc8d334837fe971a2f25703ab Mon Sep 17 00:00:00 2001 From: Dima Date: Fri, 19 Apr 2024 13:56:51 +0300 Subject: [PATCH 39/39] fix(app): sync acc in tabs (#1122) --- .../Header/SwitchAccount/SwitchAccount.tsx | 14 +++---- src/contexts/signerClient.tsx | 39 ++----------------- src/pages/Keys/ActionBar/actionBar.tsx | 13 ++++--- .../channels/BroadcastChannelSender.ts | 11 ++++++ .../channels/RxBroadcastChannelListener.ts | 6 ++- src/services/backend/types/services.ts | 8 +++- src/utils/config.ts | 10 +---- 7 files changed, 39 insertions(+), 62 deletions(-) diff --git a/src/containers/application/Header/SwitchAccount/SwitchAccount.tsx b/src/containers/application/Header/SwitchAccount/SwitchAccount.tsx index 83c691fa4..48b10007c 100644 --- a/src/containers/application/Header/SwitchAccount/SwitchAccount.tsx +++ b/src/containers/application/Header/SwitchAccount/SwitchAccount.tsx @@ -8,17 +8,17 @@ import useOnClickOutside from 'src/hooks/useOnClickOutside'; import { routes } from 'src/routes'; import usePassportByAddress from 'src/features/passport/hooks/usePassportByAddress'; -import { useAppDispatch, useAppSelector } from 'src/redux/hooks'; +import { useAppSelector } from 'src/redux/hooks'; import Pill from 'src/components/Pill/Pill'; import { useSigningClient } from 'src/contexts/signerClient'; +import BroadcastChannelSender from 'src/services/backend/channels/BroadcastChannelSender'; +import { useBackend } from 'src/contexts/backend/backend'; import { AvataImgIpfs } from '../../../portal/components/avataIpfs'; import styles from './SwitchAccount.module.scss'; import networkStyles from '../SwitchNetwork/SwitchNetwork.module.scss'; import useMediaQuery from '../../../../hooks/useMediaQuery'; import robot from '../../../../image/temple/robot.png'; import Karma from '../../Karma/Karma'; -import { setDefaultAccount } from '../../../../redux/features/pocket'; -import { useBackend } from 'src/contexts/backend/backend'; // should be refactored function AccountItem({ @@ -96,7 +96,6 @@ function SwitchAccount() { const [controlledVisible, setControlledVisible] = React.useState(false); const { defaultAccount, accounts } = useAppSelector((state) => state.pocket); - const dispatch = useAppDispatch(); const useGetAddress = defaultAccount?.account?.cyber?.bech32 || null; @@ -121,11 +120,8 @@ function SwitchAccount() { const isReadOnly = defaultAccount.account?.cyber.keys === 'read-only'; const onClickChangeActiveAcc = async (key: string) => { - dispatch( - setDefaultAccount({ - name: key, - }) - ); + const broadcastChannel = new BroadcastChannelSender(); + broadcastChannel.postSetDefaultAccount(key); setControlledVisible(false); }; diff --git a/src/contexts/signerClient.tsx b/src/contexts/signerClient.tsx index b4c7fe4e6..deec75966 100644 --- a/src/contexts/signerClient.tsx +++ b/src/contexts/signerClient.tsx @@ -5,17 +5,12 @@ import React, { useMemo, useState, } from 'react'; -import _ from 'lodash'; import { SigningCyberClient } from '@cybercongress/cyber-js'; import { CYBER } from 'src/utils/config'; import configKeplr, { getKeplr } from 'src/utils/keplrUtils'; import { OfflineSigner } from '@cybercongress/cyber-js/build/signingcyberclient'; import { Option } from 'src/types'; -import { useAppDispatch, useAppSelector } from 'src/redux/hooks'; -import { Keplr } from '@keplr-wallet/types'; -import { addAddressPocket, setDefaultAccount } from 'src/redux/features/pocket'; -import { accountsKeplr } from 'src/utils/utils'; -import usePrevious from 'src/hooks/usePrevious'; +import { useAppSelector } from 'src/redux/hooks'; // TODO: interface for keplr and OfflineSigner // type SignerType = OfflineSigner & { @@ -56,37 +51,11 @@ export function useSigningClient() { } function SigningClientProvider({ children }: { children: React.ReactNode }) { - const { defaultAccount, accounts } = useAppSelector((state) => state.pocket); - const dispatch = useAppDispatch(); + const { defaultAccount } = useAppSelector((state) => state.pocket); const [signer, setSigner] = useState(); const [signerReady, setSignerReady] = useState(false); const [signingClient, setSigningClient] = useState(); - const prevAccounts = usePrevious(accounts); - - const selectAddress = useCallback( - async (keplr: Keplr) => { - if (!accounts || _.isEqual(prevAccounts, accounts)) { - return; - } - const keyInfo = await keplr.getKey(CYBER.CHAIN_ID); - - const findAccount = Object.keys(accounts).find((key) => { - if (accounts[key].cyber.bech32 === keyInfo.bech32Address) { - return key; - } - - return undefined; - }); - - if (findAccount) { - dispatch(setDefaultAccount({ name: findAccount })); - } else { - dispatch(addAddressPocket(accountsKeplr(keyInfo))); - } - }, - [accounts, prevAccounts, dispatch] - ); useEffect(() => { (async () => { @@ -105,8 +74,6 @@ function SigningClientProvider({ children }: { children: React.ReactNode }) { const initSigner = useCallback(async () => { const windowKeplr = await getKeplr(); if (windowKeplr && windowKeplr.experimentalSuggestChain) { - selectAddress(windowKeplr); - windowKeplr.defaultOptions = { sign: { preferNoSetFee: true, @@ -125,7 +92,7 @@ function SigningClientProvider({ children }: { children: React.ReactNode }) { setSigner(offlineSigner); setSigningClient(clientJs); } - }, [selectAddress]); + }, []); useEffect(() => { (async () => { diff --git a/src/pages/Keys/ActionBar/actionBar.tsx b/src/pages/Keys/ActionBar/actionBar.tsx index 0a8be4601..6a47d2e0a 100644 --- a/src/pages/Keys/ActionBar/actionBar.tsx +++ b/src/pages/Keys/ActionBar/actionBar.tsx @@ -1,19 +1,19 @@ import { useEffect, useState } from 'react'; import { Pane, ActionBar as ActionBarGravity } from '@cybercongress/gravity'; import { useSigningClient } from 'src/contexts/signerClient'; -import ActionBarKeplr from './actionBarKeplr'; -import ActionBarUser from './actionBarUser'; -import ActionBarConnect from './actionBarConnect'; import waitForWeb3 from 'components/web3/waitForWeb3'; import { NETWORKSIDS } from 'src/utils/config'; -import imgLedger from 'src/image/ledger.svg'; import imgKeplr from 'src/image/keplr-icon.svg'; import imgRead from 'src/image/duplicate-outline.svg'; import Button from 'src/components/btnGrd'; import { useDispatch, useSelector } from 'react-redux'; import { RootState } from 'src/redux/store'; -import { deleteAddress, setDefaultAccount } from 'src/redux/features/pocket'; +import { deleteAddress } from 'src/redux/features/pocket'; +import BroadcastChannelSender from 'src/services/backend/channels/BroadcastChannelSender'; +import ActionBarConnect from './actionBarConnect'; +import ActionBarUser from './actionBarUser'; +import ActionBarKeplr from './actionBarKeplr'; const STAGE_INIT = 1; const STAGE_CONNECT = 2; @@ -161,7 +161,8 @@ function ActionBar({ )?.[0]; if (accountName) { - dispatch(setDefaultAccount({ name: accountName })); + const broadcastChannel = new BroadcastChannelSender(); + broadcastChannel.postSetDefaultAccount(accountName); } } diff --git a/src/services/backend/channels/BroadcastChannelSender.ts b/src/services/backend/channels/BroadcastChannelSender.ts index 6c7b411e3..eed45a0d4 100644 --- a/src/services/backend/channels/BroadcastChannelSender.ts +++ b/src/services/backend/channels/BroadcastChannelSender.ts @@ -1,4 +1,6 @@ import { updateSenseList } from 'src/features/sense/redux/sense.redux'; +import { setDefaultAccount } from 'src/redux/features/pocket'; +import { Account } from 'src/types/defaultAccount'; import { SenseListItem } from '../types/sense'; import { BroadcastChannelMessage, @@ -39,6 +41,15 @@ class BroadcastChannelSender { } } + public postSetDefaultAccount(name: string, account?: Account) { + this.channel.postMessage( + setDefaultAccount({ + name, + account, + }) + ); + } + post(msg: BroadcastChannelMessage) { this.channel.postMessage(msg); } diff --git a/src/services/backend/channels/RxBroadcastChannelListener.ts b/src/services/backend/channels/RxBroadcastChannelListener.ts index fb7a7b9ef..46dc3add1 100644 --- a/src/services/backend/channels/RxBroadcastChannelListener.ts +++ b/src/services/backend/channels/RxBroadcastChannelListener.ts @@ -4,6 +4,7 @@ import { bufferTime, filter } from 'rxjs/operators'; import { BC_MSG_LOAD_COMMUNITY, + BC_MSG_SET_DEFAULT_ACCOUNT, BroadcastChannelMessage, getBroadcastChannemMessageKey, } from '../types/services'; @@ -24,7 +25,10 @@ class RxBroadcastChannelListener { const channel = new BroadcastChannel(CYB_BROADCAST_CHANNEL); channel.onmessage = (msg: MessageEvent) => { - if (msg.data.type === BC_MSG_LOAD_COMMUNITY) { + if ( + msg.data.type === BC_MSG_LOAD_COMMUNITY || + msg.data.type === BC_MSG_SET_DEFAULT_ACCOUNT + ) { dispatch(msg.data); return; } diff --git a/src/services/backend/types/services.ts b/src/services/backend/types/services.ts index afccbbade..38b7a8dc8 100644 --- a/src/services/backend/types/services.ts +++ b/src/services/backend/types/services.ts @@ -1,4 +1,5 @@ import { SyncCommunityResult } from 'src/services/community/community'; +import { setDefaultAccount } from 'src/redux/features/pocket'; import { IndexedDbWriteMessage } from '../../CozoDb/types/types'; export type SyncEntryName = @@ -71,6 +72,10 @@ export type LoadCommunityMessage = { value: SyncCommunityResult; }; +export const BC_MSG_SET_DEFAULT_ACCOUNT = setDefaultAccount.type; + +export type SetDefaultAccountMessage = typeof setDefaultAccount; + // export type SenseListUpdate = { // type: 'sense_list_update'; // list: SenseListItem[]; @@ -81,7 +86,8 @@ export type BroadcastChannelMessage = | SyncEntryMessage | IndexedDbWriteMessage | ServiceStatusMessage - | LoadCommunityMessage; + | LoadCommunityMessage + | SetDefaultAccountMessage; // | SenseListUpdate // | SenseListRemove; diff --git a/src/utils/config.ts b/src/utils/config.ts index 047a718b1..1e1e63286 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -75,9 +75,8 @@ const COSMOS = { BECH32_PREFIX_ACC_ADDR_COSMOS: 'cosmos', }; -const LOCALSTORAGE_CHAIN_ID = localStorage.getItem('chainId'); +const LOCALSTORAGE_CHAIN_ID = Networks.BOSTROM; -const CHAIN_PARAMS_LOCALSTORAGE = localStorage.getItem('CHAIN_PARAMS'); let CHAIN_PARAMS = { CHAIN_ID: process.env.CHAIN_ID || Networks.BOSTROM, DENOM_CYBER: 'boot', @@ -119,13 +118,6 @@ if (LOCALSTORAGE_CHAIN_ID === 'space-pussy') { }; } -if (CHAIN_PARAMS_LOCALSTORAGE !== null && LOCALSTORAGE_CHAIN_ID !== null) { - const CHAIN_PARAMS_LOCALSTORAGE_DATA = JSON.parse(CHAIN_PARAMS_LOCALSTORAGE); - if (CHAIN_PARAMS_LOCALSTORAGE_DATA[LOCALSTORAGE_CHAIN_ID]) { - CHAIN_PARAMS = { ...CHAIN_PARAMS_LOCALSTORAGE_DATA[LOCALSTORAGE_CHAIN_ID] }; - } -} - const CYBER = { CYBER_CONGRESS_ADDRESS: 'bostrom1xszmhkfjs3s00z2nvtn7evqxw3dtus6yr8e4pw', DIVISOR_CYBER_G: 10 ** 9,