Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bifrost polkadot network support to Bifrost space, #1051 #1052

Merged
merged 9 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/packages/backend/src/consts/networks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const networks = Object.freeze({
statemine: "statemine",
statemint: "statemint",
bifrost: "bifrost",
bifrost: "bifrost", // bifrost is bifrost-kusama
bifrostPolkadot: "bifrost-polkadot",
karura: "karura",
kusama: "kusama",
polkadot: "polkadot",
Expand Down
13 changes: 12 additions & 1 deletion backend/packages/backend/src/scripts/spaces/bifrost.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ const bifrostConfig = {
accessibility: Accessibility.PUBLIC,
networks: [
{
network: networks.bifrost,
network: networks.bifrostPolkadot,
ss58Format: 6,
assets: [
{
symbol: "BNC",
decimals: 12,
votingThreshold: "10000000000",
},
],
},
{
network: networks.bifrost, // Bifrost Kusama
ss58Format: 6,
assets: [
{
Expand Down
3 changes: 2 additions & 1 deletion backend/packages/node-api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ KHA_ENDPOINTS=wss://khala.api.onfinality.io/public-ws
PHA_ENDPOINTS=wss://api.phala.network/ws
STATEMINE_ENDPOINTS=wss://kusama-asset-hub-rpc.polkadot.io
STATEMINT_ENDPOINTS=wss://polkadot-asset-hub-rpc.polkadot.io;wss://sys.dotters.network/statemint
BNC_ENDPOINTS=wss://bifrost-parachain.api.onfinality.io/public-ws;wss://bifrost-rpc.liebi.com/ws;wss://us.bifrost-rpc.liebi.com/ws;wss://eu.bifrost-rpc.liebi.com/ws
BNC_KSM_ENDPOINTS=wss://bifrost-parachain.api.onfinality.io/public-ws;wss://bifrost-rpc.liebi.com/ws;wss://us.bifrost-rpc.liebi.com/ws;wss://eu.bifrost-rpc.liebi.com/ws
BNC_DOT_ENDPOINTS=wss://bifrost-polkadot-rpc.dwellir.com;wss://bifrost-polkadot.ibp.network;wss://bifrost-polkadot.dotters.network
KINT_ENDPOINTS=wss://kintsugi.api.onfinality.io/public-ws;wss://api-kusama.interlay.io/parachain
INTR_ENDPOINTS=wss://interlay.api.onfinality.io/public-ws;wss://api.interlay.io/parachain
ACA_ENDPOINTS=wss://acala-polkadot.api.onfinality.io/public-ws;wss://acala-rpc.dwellir.com;wss://acala-rpc-0.aca-api.network;wss://acala-rpc-1.aca-api.network;wss://acala-rpc-3.aca-api.network/ws
Expand Down
3 changes: 2 additions & 1 deletion backend/packages/node-api/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const chains = {
phala: "phala",
statemine: "statemine",
statemint: "statemint",
bifrost: "bifrost",
bifrost: "bifrost", // bifrost is bifrost-kusama
bifrostPolkadot: "bifrost-polkadot",
kintsugi: "kintsugi",
interlay: "interlay",
acala: "acala",
Expand Down
3 changes: 2 additions & 1 deletion backend/packages/node-api/src/env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const chainEndpointPrefixMap = {
[chains.phala]: "PHA",
[chains.statemine]: "STATEMINE",
[chains.statemint]: "STATEMINT",
[chains.bifrost]: "BNC",
[chains.bifrost]: "BNC_KSM",
[chains.bifrostPolkadot]: "BNC_DOT",
[chains.kintsugi]: "KINT",
[chains.polkadex]: "PDEX",
[chains.interlay]: "INTR",
Expand Down
2 changes: 1 addition & 1 deletion backend/packages/node-api/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = (app) => {

for (const r of chainFeatureRouters) {
router.use(
`/:chain(${Object.keys(chains).join("|")})`,
`/:chain(${Object.values(chains).join("|")})`,
r.routes(),
r.allowedMethods({ throw: true }),
);
Expand Down
2 changes: 1 addition & 1 deletion next/components/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
showConnectSelector,
showHeaderMenuSelector,
} from "../store/reducers/showConnectSlice";
import { ChainIcon } from "@osn/common-ui";
import { ChainIcon } from "components/chainIcon";
import IdentityOrAddr from "@/components/identityOrAddr";
import { useMetaMaskEventHandlers } from "services/metamask";
import { useOnClickOutside, useWindowSize } from "frontedUtils/hooks";
Expand Down
3 changes: 2 additions & 1 deletion next/components/assetList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import styled from "styled-components";
import { p_14_medium, p_12_normal } from "../styles/textStyles";
import { ChainIcon, FlexBetween } from "@osn/common-ui";
import { FlexBetween } from "@osn/common-ui";
import { Tooltip } from "@osn/common-ui";
import { ChainIcon } from "components/chainIcon";

const Wrapper = styled.div`
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion next/components/author.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components";

import Avatar from "./avatar";
import { ChainIcon } from "@osn/common-ui";
import { ChainIcon } from "components/chainIcon";
import IdentityOrAddr from "@/components/identityOrAddr";

const Wrapper = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion next/components/chain/blockHeightInput.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from "styled-components";
import Input from "@osn/common-ui/es/styled/Input";
import { ChainIcon } from "@osn/common-ui";
import { ChainIcon } from "components/chainIcon";
import { ReactComponent as Loading } from "public/imgs/icons/loading.svg";
import { useDispatch, useSelector } from "react-redux";
import {
Expand Down
14 changes: 14 additions & 0 deletions next/components/chainIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import camalCase from "lodash.camelcase";
import { ChainIcon as _ChainIcon, Tooltip } from "@osn/common-ui";
import { normalizeChainName } from "frontedUtils/chain";

export function ChainIcon({ chainName, size }) {
const normalizedChainName = normalizeChainName(chainName);
return (
<Tooltip content={normalizedChainName}>
<div>
<_ChainIcon chainName={camalCase(normalizedChainName)} size={size} />
</div>
</Tooltip>
);
}
5 changes: 3 additions & 2 deletions next/components/chainSelector.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState, useEffect } from "react";
import styled, { css } from "styled-components";
import { p_14_medium } from "../styles/textStyles";
import { ChainIcon } from "@osn/common-ui";
import { ChainIcon } from "components/chainIcon";
import DropdownSelector from "@osn/common-ui/es/DropdownSelector";
import { normalizeChainName } from "frontedUtils/chain";

const Wrapper = styled.div`
margin-bottom: 8px;
Expand Down Expand Up @@ -42,7 +43,7 @@ const ChainItem = ({ header, chainName }) => {
<ItemWrapper header={header}>
<ChainIcon chainName={chainName} />
<div>
<Text>{chainName}</Text>
<Text>{normalizeChainName(chainName)}</Text>
</div>
</ItemWrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion next/components/listInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
p_20_semibold,
} from "../../styles/textStyles";
import SpaceLogo from "@/components/spaceLogo";
import { ChainIcon } from "@osn/common-ui";
import { ChainIcon } from "components/chainIcon";
import ValueDisplay from "../valueDisplay";
import Modal from "@osn/common-ui/es/Modal";
import { useState } from "react";
Expand Down
2 changes: 1 addition & 1 deletion next/components/newSpace/sider/assets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from "styled-components";
import { Name, Value } from "./styled";
import { ChainIcon } from "@osn/common-ui";
import { ChainIcon } from "components/chainIcon";
import { Tooltip } from "@osn/common-ui";

const Wrapper = styled.div`
Expand Down
7 changes: 4 additions & 3 deletions next/components/postCreate/more.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { FlexBetween } from "@osn/common-ui";
import DropdownSelector from "@osn/common-ui/es/DropdownSelector";
import { hasSocietyVoteStrategyOnly } from "frontedUtils/strategy";
import dayjs from "dayjs";
import { normalizeChainName } from "frontedUtils/chain";

const Wrapper = styled.div`
min-width: 302px;
Expand Down Expand Up @@ -124,11 +125,11 @@ export default function More({ onPublish, space }) {

const isSocietyOnly = hasSocietyVoteStrategyOnly(space.weightStrategy);
useEffect(() => {
if (authoringStartDate) {
if (isSocietyOnly && authoringStartDate) {
const endDate = dayjs(authoringStartDate).add(14, "day").toDate();
dispatch(setEndTimestamp(endDate.getTime()));
}
}, [dispatch, authoringStartDate]);
}, [dispatch, isSocietyOnly, authoringStartDate]);

return (
<Wrapper>
Expand Down Expand Up @@ -177,7 +178,7 @@ export default function More({ onPublish, space }) {
<SnapshotHeightPicker space={space} />
{space.networks?.map((network) => (
<Snapshot className="snapshot" key={network.network}>
<NetworkName>{network.network}</NetworkName>
<NetworkName>{normalizeChainName(network.network)}</NetworkName>
{snapshotHeights.find(
(snapshotHeight) => snapshotHeight.network === network.network,
)?.height || <TextGrey>-</TextGrey>}
Expand Down
18 changes: 13 additions & 5 deletions next/components/postDetail/postInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import styled from "styled-components";
import moment from "moment";

import ExternalLink from "@osn/common-ui/es/ExternalLink";
import { capitalize, getExplorer } from "../../frontedUtils";
import { ChainIcon } from "@osn/common-ui";
import { getExplorer } from "../../frontedUtils";
import { ChainIcon } from "components/chainIcon";
import { Tooltip } from "@osn/common-ui";
import Panel from "@/components/postDetail/panel";
import SideSectionTitle from "@/components/sideBar/sideSectionTitle";
import AssetList from "../assetList";
import { getSpaceAssets } from "frontedUtils/getSpaceAssets";
import { hasBalanceStrategy } from "frontedUtils/strategy";
import { normalizeChainName } from "frontedUtils/chain";

const Capitalize = styled.span`
text-transform: capitalize;
`;

const Wrapper = styled(Panel)`
> :not(:first-child) {
Expand Down Expand Up @@ -93,9 +98,12 @@ export default function PostInfo({ data, space }) {
return (
<Tooltip
key={networkName}
content={`${capitalize(
networkName,
)} ${height.toLocaleString()}`}
content={
<Capitalize>
{normalizeChainName(networkName)}{" "}
{height.toLocaleString()}
</Capitalize>
}
size="fit"
>
<div>
Expand Down
8 changes: 8 additions & 0 deletions next/frontedUtils/chain/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { networks } from "frontedUtils/consts/chains/networks";

export function normalizeChainName(chainName) {
if (chainName === networks.bifrost) {
return "bifrost-kusama";
}
return chainName;
}
9 changes: 9 additions & 0 deletions next/frontedUtils/consts/chains/bifrostPolkadot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { networks } from "./networks";

const bifrost = {
ss58Format: 6,
hasProxy: true,
identity: networks.bifrostPolkadot,
};

export default bifrost;
6 changes: 4 additions & 2 deletions next/frontedUtils/consts/chains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import polkadot from "./polkadot";
import kusama from "./kusama";
import acala from "./acala";
import altair from "./altair";
import bifrost from "./bifrost";
import bifrostKusama from "./bifrostKusama";
import bifrostPolkadot from "./bifrostPolkadot";
import centrifuge from "./centrifuge";
import crust from "./crust";
import interlay from "./interlay";
Expand All @@ -29,7 +30,8 @@ export const chainConfigsMap = {
kusama,
acala,
altair,
bifrost,
bifrost: bifrostKusama,
"bifrost-polkadot": bifrostPolkadot,
centrifuge,
crust,
interlay,
Expand Down
3 changes: 2 additions & 1 deletion next/frontedUtils/consts/chains/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const networks = Object.freeze({
karura: "karura",
khala: "khala",
phala: "phala",
bifrost: "bifrost",
bifrost: "bifrost", // bifrost is bifrost-kusama
bifrostPolkadot: "bifrost-polkadot",
kintsugi: "kintsugi",
polkadex: "polkadex",
interlay: "interlay",
Expand Down
3 changes: 2 additions & 1 deletion next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@osn/common": "^1.3.5",
"@osn/common-ui": "^1.22.0",
"@osn/common-ui": "^1.24.0",
"@osn/constants": "^1.1.2",
"@osn/icons": "^1.100.0",
"@osn/polkadot-react-identicon": "^1.0.10",
Expand All @@ -27,6 +27,7 @@
"ethereum-blockies-base64": "^1.0.2",
"ethers": "^5.6.1",
"http-proxy": "^1.18.1",
"lodash.camelcase": "^4.3.0",
"lodash.debounce": "^4.0.8",
"lodash.isempty": "^4.4.0",
"lodash.isnil": "^4.0.0",
Expand Down
28 changes: 18 additions & 10 deletions next/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ __metadata:
resolution: "@collaboration/voting@workspace:."
dependencies:
"@osn/common": ^1.3.5
"@osn/common-ui": ^1.22.0
"@osn/common-ui": ^1.24.0
"@osn/constants": ^1.1.2
"@osn/eslint-config": ^1.0.2
"@osn/icons": ^1.100.0
Expand All @@ -1470,6 +1470,7 @@ __metadata:
identity-obj-proxy: ^3.0.0
jest: ^27.3.0
jest-environment-node: ^27.3.0
lodash.camelcase: ^4.3.0
lodash.debounce: ^4.0.8
lodash.isempty: ^4.4.0
lodash.isnil: ^4.0.0
Expand Down Expand Up @@ -2547,12 +2548,12 @@ __metadata:
languageName: node
linkType: hard

"@osn/common-ui@npm:^1.22.0":
version: 1.22.0
resolution: "@osn/common-ui@npm:1.22.0"
"@osn/common-ui@npm:^1.24.0":
version: 1.24.0
resolution: "@osn/common-ui@npm:1.24.0"
dependencies:
"@floating-ui/react": ^0.26.6
"@osn/icons": ^1.131.0
"@osn/icons": ^1.138.0
"@osn/polkadot-react-identicon": ^1.0.10
"@radix-ui/react-dialog": ^1.0.5
"@radix-ui/react-tooltip": ^1.0.7
Expand All @@ -2578,7 +2579,7 @@ __metadata:
semantic-ui-css: ^2.4.1
semantic-ui-react: ^2.1.3
styled-components: ^6.1.6
checksum: bc85da8819f81f83829008c0340ab6a6519c98ce8335bd9b13217af5f0eb65f86d0d1768688ea54e77c7877e9c9e4b5f4dfc9ab55a3bf0613842c70743fbe868
checksum: 12af1367e90f24ecde3a567e6733b1189986647b6d1488606dd2c1b387330e5146416ff88e13699cede2a862bf55d8151548856ed2a7df3762535548467a799d
languageName: node
linkType: hard

Expand Down Expand Up @@ -2624,10 +2625,10 @@ __metadata:
languageName: node
linkType: hard

"@osn/icons@npm:^1.131.0":
version: 1.131.0
resolution: "@osn/icons@npm:1.131.0"
checksum: efde477fe4692d300b1c169d3bf039eb0cb0b1039e10ff360c902b4ab49b69767ea63b1cb5786ee5fda425781090b543ccc9475e32c92b06e3422c5a20074d75
"@osn/icons@npm:^1.138.0":
version: 1.138.0
resolution: "@osn/icons@npm:1.138.0"
checksum: f98ac3545b9814046a77347bc86c31efd1bcee13a13303ebc9630c0bf40ba6d142e9462f83cd2e61ea53b4fb6e0c30b592f6245d05fe7653cba0ecd26bff866c
languageName: node
linkType: hard

Expand Down Expand Up @@ -8630,6 +8631,13 @@ __metadata:
languageName: node
linkType: hard

"lodash.camelcase@npm:^4.3.0":
version: 4.3.0
resolution: "lodash.camelcase@npm:4.3.0"
checksum: cb9227612f71b83e42de93eccf1232feeb25e705bdb19ba26c04f91e885bfd3dd5c517c4a97137658190581d3493ea3973072ca010aab7e301046d90740393d1
languageName: node
linkType: hard

"lodash.debounce@npm:^4.0.8":
version: 4.0.8
resolution: "lodash.debounce@npm:4.0.8"
Expand Down
Loading