Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
BEPRO 2.9 (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
moshmage authored Feb 16, 2023
2 parents 7f10396 + 45bea40 commit 0f84136
Show file tree
Hide file tree
Showing 59 changed files with 415 additions and 258 deletions.
18 changes: 9 additions & 9 deletions assets/icons/transactions/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { SVGProps } from "react";
export default function SettingsIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg width="24" height="20" viewBox="0 0 24 20" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
<path d="M4 19V12" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4 8V1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 19V10" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 6V1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M20 19V14" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M20 10V1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M1 12H7" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M9 6H15" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M17 14H23" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4 19V12" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4 8V1" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 19V10" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 6V1" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M20 19V14" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M20 10V1" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M1 12H7" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M9 6H15" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M17 14H23" stroke="white" strokeWidth="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
);
}
2 changes: 1 addition & 1 deletion components/bounties/list-active-networks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function ListActiveNetworks() {
</span>
</span>
<span className="bg-dark-gray p-1 border-radius-8 px-2">
{network?.countIssues || 0}{" "}
{network?.totalIssues || 0}{" "}
<span className="text-uppercase text-white-40">
{t("label_other")}
</span>
Expand Down
1 change: 1 addition & 0 deletions components/bounty/tabs-sections/item-sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function ItemSections({ data, isProposal }: ItemProps) {
review: true
}))
}}
disabled={item?.status === "draft" ? true : false}
>
<span className="label-m text-white">
<Translation label={isProposal ? "actions.view-proposal" : "actions.review"} />
Expand Down
2 changes: 1 addition & 1 deletion components/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function MainNav() {
const { searchNetworks } = useApi();
const { getURLWithNetwork } = useNetworkTheme();

const noNeedNetworkInstance = ["/networks", "/new-network", "/explore", "/leaderboard"].includes(pathname);
const noNeedNetworkInstance = ["/","/networks", "/new-network", "/explore", "/leaderboard"].includes(pathname);
const fullLogoUrl = state.Service?.network?.active?.fullLogo;

useEffect(() => {
Expand Down
12 changes: 9 additions & 3 deletions components/network-list-item.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import BigNumber from "bignumber.js";

import NetworkLogo from "components/network-logo";
import PullRequestLabels from "components/pull-request-labels";

Expand Down Expand Up @@ -45,19 +47,23 @@ export default function NetworkListItem({

<div className="col-3 d-flex flex-row align-items-center justify-content-center">
<span className="caption-medium text-white">
{isNotUndefined(network?.totalBounties) ? formatNumberToNScale(network?.totalBounties, 0) : <Spinner />}
{isNotUndefined(network?.totalIssues) ? formatNumberToNScale(network?.totalIssues, 0) : <Spinner />}
</span>
</div>

<div className="col-3 d-flex flex-row align-items-center justify-content-center">
<span className="caption-medium text-white">
{isNotUndefined(network?.openBounties) ? formatNumberToNScale(network?.openBounties, 0) : <Spinner />}
{isNotUndefined(network?.totalOpenIssues) ? formatNumberToNScale(network?.totalOpenIssues, 0) : <Spinner />}
</span>
</div>

<div className="col-3 d-flex flex-row align-items-center justify-content-center gap-20">
<span className="caption-medium text-white ml-3">
{isNotUndefined(network?.tokensLocked) ? formatNumberToNScale(+network?.tokensLocked) : <Spinner />}
{isNotUndefined(network?.tokensLocked) ? (
formatNumberToNScale(BigNumber(network?.tokensLocked || 0).toFixed())
) : (
<Spinner />
)}
</span>

<span
Expand Down
53 changes: 5 additions & 48 deletions components/networks-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {Network} from "interfaces/network";

import {NetworksPageContext} from "pages/networks";

import {getCoinInfoByContract} from "services/coingecko";
import DAO from "services/dao-service";

import useApi from "x-hooks/use-api";
Expand Down Expand Up @@ -65,7 +64,8 @@ export default function NetworksList() {
searchNetworks({
isRegistered: true,
sortBy: "name",
order: "asc"
order: "asc",
isNeedCountsAndTokensLocked: true
})
.then(async ({ count, rows }) => {
if (count > 0) {
Expand All @@ -83,7 +83,7 @@ export default function NetworksList() {
useEffect(() => {
if (!networks.length) return;

if (!state.Service?.active || networks?.every(network => network?.openBounties !== undefined)) return;
if (!state.Service?.active) return;

const web3Host = state.Settings?.urls?.web3Provider;
const dao = new DAO({web3Host, skipWindowAssignment: true});
Expand All @@ -93,59 +93,16 @@ export default function NetworksList() {
const networkAddress = network?.networkAddress;
await dao.loadNetwork(networkAddress);

const [settlerTokenData, totalSettlerLocked, openBounties, totalBounties] = await Promise.all([
const [settlerTokenData] = await Promise.all([
dao.getSettlerTokenData().catch(() => undefined),
dao.getTotalNetworkToken().catch(() => 0),
dao.getOpenBounties().catch(() => 0),
dao.getTotalBounties().catch(() => 0)
]);

const mainCurrency = state.Settings?.currency?.defaultFiat || "eur";

const coinInfo = await getCoinInfoByContract(settlerTokenData?.symbol).catch(() => ({ prices: {} }));

const totalSettlerConverted = (coinInfo.prices[mainCurrency] || 0) * +totalSettlerLocked;

return { ...network,
openBounties,
totalBounties,
networkToken: settlerTokenData,
tokensLocked: totalSettlerLocked.toFixed(),
totalSettlerConverted: totalSettlerConverted.toFixed()
networkToken: settlerTokenData
}
})))
.then(setNetworks)
.catch(error => console.log("Failed to load network data", error, state.Service?.network?.active));

// Promise.all(networks.map(async (network: Network) => {
// const networkAddress = network?.networkAddress;
//
//
// await dao.loadNetwork(networkAddress);
//
// const [settlerTokenData, totalSettlerLocked, openBounties, totalBounties] = await Promise.all([
// dao.getSettlerTokenData().catch(() => undefined),
// dao.getTotalNetworkToken().catch(() => 0),
// dao.getOpenBounties().catch(() => 0),
// dao.getTotalBounties().catch(() => 0)
// ]);
//
// const mainCurrency = state.Settings?.currency?.defaultFiat || "eur";
//
// const coinInfo = await getCoinInfoByContract(settlerTokenData?.address).catch(() => ({ prices: {} }));
//
// const totalSettlerConverted = (coinInfo.prices[mainCurrency] || 0) * +totalSettlerLocked;
//
// return { ...network,
// openBounties,
// totalBounties,
// networkToken: settlerTokenData,
// tokensLocked: totalSettlerLocked.toFixed(),
// totalSettlerConverted: totalSettlerConverted.toFixed()
// }
// }))
// .then(setNetworks)
// .catch(error => console.log("Failed to load network data", error, state.Service?.network?.active));
}, [networks, state.Service?.active]);

return (
Expand Down
95 changes: 83 additions & 12 deletions components/profile/my-network-settings/registry-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
import { useEffect, useState } from "react";
import { Col, Row } from "react-bootstrap";

import { useTranslation } from "next-i18next";

import Button from "components/button";
import NetworkParameterInput from "components/custom-network/network-parameter-input";
import TreasuryAddressField from "components/custom-network/treasury-address-field";
import { FormGroup } from "components/form-group";
import TokensSettings from "components/profile/my-network-settings/tokens-settings";
import { WarningSpan } from "components/warning-span";

import { useAppState } from "contexts/app-state";
import { useNetworkSettings } from "contexts/network-settings";

import useBepro from "x-hooks/use-bepro";
import { useNetwork } from "x-hooks/use-network";

export default function RegistrySettings({ isGovernorRegistry = false }) {
const { t } = useTranslation(["common", "custom-network"]);
const { t } = useTranslation(["common", "custom-network", "setup"]);
const [networkCreationFeePercentage, setNetworkCreationFeePercentage] = useState<string>()
const [lockAmountForNetworkCreation, setLockAmountForNetworkCreation] = useState<string>()
const { fields, settings } = useNetworkSettings();

const {state} = useAppState();
const { updateActiveNetwork } = useNetwork();
const { handleFeeSettings } = useBepro();
const { handleFeeSettings, handleAmountNetworkCreation, handleFeeNetworkCreation } = useBepro();

async function saveFeeSettings() {
await handleFeeSettings(settings?.treasury?.closeFee?.value,
settings?.treasury?.cancelFee?.value).then(() => updateActiveNetwork(true));
}

async function saveCreateNetworkFee() {
await handleFeeNetworkCreation(Number(networkCreationFeePercentage)/100)
}

async function saveCreateNetworkAmount() {
await handleAmountNetworkCreation(lockAmountForNetworkCreation)
}

useEffect(() => {
if(!state.Service?.active) return;

state.Service.active.getRegistryCreatorAmount().then(v => setLockAmountForNetworkCreation(v.toFixed()))
state.Service.active.getRegistryCreatorFee().then(v => v.toString()).then(setNetworkCreationFeePercentage)

},[state.Service.active])

function exceedsFeesLimitsError(fee) {
if (+fee < 0 || +fee > 100)
return t("setup:registry.errors.exceeds-limit");

return undefined;
}

return (
<>
{isGovernorRegistry && (
Expand Down Expand Up @@ -62,7 +90,7 @@ export default function RegistrySettings({ isGovernorRegistry = false }) {
onChange={fields.cancelFee.setter}
/>
</Col>

<Col>
<NetworkParameterInput
disabled={!isGovernorRegistry}
Expand All @@ -74,14 +102,6 @@ export default function RegistrySettings({ isGovernorRegistry = false }) {
onChange={fields.closeFee.setter}
/>
</Col>

{!isGovernorRegistry && (
<Row className="mb-4">
<WarningSpan
text={t("custom-network:steps.network-settings.fields.other-settings.warning-registry")}
/>
</Row>
)}
{isGovernorRegistry && (
<Col xs={4}>
<Button onClick={saveFeeSettings} className="mt-4">
Expand All @@ -90,6 +110,57 @@ export default function RegistrySettings({ isGovernorRegistry = false }) {
</Col>
)}
</Row>
<Row className="mb-2">
<Col>
<FormGroup
label={t("setup:registry.fields.network-creation-fee.label")}
placeholder="0"
symbol="%"
value={networkCreationFeePercentage}
onChange={setNetworkCreationFeePercentage}
variant="numberFormat"
description={t("setup:registry.fields.network-creation-fee.description")}
error={exceedsFeesLimitsError(networkCreationFeePercentage)}
readOnly={!isGovernorRegistry}
/>
</Col>
{isGovernorRegistry && (
<Col xs={5}>
<Button
className="mt-4"
onClick={saveCreateNetworkFee}
disabled={exceedsFeesLimitsError(networkCreationFeePercentage) ? true : false}
>
<span>{t("custom-network:registry.save-create-network-fee")}</span>
</Button>
</Col>
)}
</Row>
<Row className="mb-2">
<FormGroup
label={t("setup:registry.fields.network-creation-amount.label")}
placeholder="0"
value={lockAmountForNetworkCreation}
onChange={setLockAmountForNetworkCreation}
variant="numberFormat"
description={t("setup:registry.fields.network-creation-amount.description")}
readOnly={!isGovernorRegistry}
/>
{isGovernorRegistry && (
<Col xs={5}>
<Button onClick={saveCreateNetworkAmount} className="mt-4">
<span>{t("custom-network:registry.save-create-network-amount")}</span>
</Button>
</Col>
)}
</Row>
{!isGovernorRegistry && (
<Row className="mb-4">
<WarningSpan
text={t("custom-network:steps.network-settings.fields.other-settings.warning-registry")}
/>
</Row>
)}

{isGovernorRegistry && <TokensSettings isGovernorRegistry={true} />}
</>
Expand Down
2 changes: 2 additions & 0 deletions components/transaction-type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default function TransactionType({ type }) {
[TransactionTypes.deployNetworkRegistry]: t("transactions.types.deploy-registry"),
[TransactionTypes.changeAllowedTokens]: t("transactions.types.change-allowed-tokens"),
[TransactionTypes.closeNetwork]: t("transactions.types.close-network"),
[TransactionTypes.amountForNetworkCreation]: t("transactions.types.amount-for-network-creation"),
[TransactionTypes.feeForNetworkCreation]: t("transactions.types.fee-for-network-creation"),
};

return (
Expand Down
4 changes: 3 additions & 1 deletion components/transactions-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export function TransactionIcon({ type } : TransactionIconProps) {
[TransactionTypes.configFees]: <SettingsIcon />,
[TransactionTypes.deployNetworkRegistry]: <CurrencyIcon />,
[TransactionTypes.changeAllowedTokens]: <SettingsIcon />,
[TransactionTypes.closeNetwork]: <CancelIcon />
[TransactionTypes.closeNetwork]: <CancelIcon />,
[TransactionTypes.amountForNetworkCreation]: <SettingsIcon />,
[TransactionTypes.feeForNetworkCreation]: <SettingsIcon />
};

if (icons[type]) return icons[type];
Expand Down
3 changes: 1 addition & 2 deletions db/config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const {info} = require("../../scripts/logging.js");
require("dotenv").config();

module.exports = {
Expand All @@ -10,7 +9,7 @@ module.exports = {
host: process.env.NEXT_DB_HOST || "localhost",
port: +process.env.NEXT_DB_PORT || 54320,
... (process.env.NEXT_DB_LOG ? {
logging: (sql) => { info(sql) },
logging: (sql) => { console.log(sql) },
} : {
logging: false
}),
Expand Down
5 changes: 5 additions & 0 deletions db/models/network.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class Network extends Model {
foreignKey: "network_id",
sourceKey: "id"
});
this.hasMany(models.issue, {
foreignKey: "network_id",
sourceKey: "id",
as: "openIssues"
});
this.hasMany(models.repositories, {
foreignKey: "network_id",
sourceKey: "id"
Expand Down
23 changes: 14 additions & 9 deletions helpers/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { formatDistanceStrict } from "date-fns";

export const formatDate = (date: number | string | Date, joiner = "/") => {
const d = ["string", "number"].includes(typeof date)
? new Date(date)
: (date as Date);
return [
`0${d.getDate()}`.slice(-2),
`0${d.getMonth() + 1}`.slice(-2),
d.getFullYear()
].join(joiner);
try {
const d = ["string", "number"].includes(typeof date)
? new Date(date)
: (date as Date);
return [
`0${d.getDate()}`.slice(-2),
`0${d.getMonth() + 1}`.slice(-2),
d.getFullYear()
].join(joiner);
} catch (e) {
console.debug(e);
return `0`;
}
};

export const getTimeDifferenceInWords = (date: Date, dateToCompare: Date) => {
try {
return formatDistanceStrict(date, dateToCompare);
} catch (e) {
console.error(e);
console.debug(e);
return `0`;
}
};
Loading

0 comments on commit 0f84136

Please sign in to comment.