diff --git a/instances/treasury-factory.near/aliases.mainnet.json b/instances/treasury-factory.near/aliases.mainnet.json index 294bc1aa..5233013e 100644 --- a/instances/treasury-factory.near/aliases.mainnet.json +++ b/instances/treasury-factory.near/aliases.mainnet.json @@ -2,16 +2,11 @@ "REPL_DEVHUB": "devhub.near", "REPL_DEVHUB_CONTRACT": "devhub.near", "REPL_BASE_DEPLOYMENT_ACCOUNT": "treasury-factory.near", + "REPL_DEVDAO_ACCOUNT": "treasury-devdao.near", "REPL_INSTANCE": "treasury-factory.near", "REPL_TREASURY": "devdao.sputnik-dao.near", "REPL_NEAR": "near", "REPL_MOB": "mob.near", "REPL_SOCIAL_CONTRACT": "social.near", - "REPL_RPC_URL": "https://rpc.mainnet.near.org", - "REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME": "polyprogrammist_near_devhub_prod_v1_proposals_with_latest_snapshot", - "REPL_X_HASURA_ROLE": "polyprogrammist_near", - "REPL_NEAR_TOKEN_ICON": "https://ipfs.near.social/ipfs/bafkreifnyxk6cssapw7j5vc6zuzwl7vt6o5ddspoo5lcmbvtdrcmfozqyu", - "REPL_PIKESPEAK_KEY": "36f2b87a-7ee6-40d8-80b9-5e68e587a5b5", - "REPL_STAKE_ICON": "https://ipfs.near.social/ipfs/bafkreicjylnnugawkpvhtwjqegc2y6rhdmaqrzdo3cixr2epj5wlxz6ts4", - "REPL_UNSTAKE_ICON": "https://ipfs.near.social/ipfs/bafkreiepl6mvtyvd4hxiy3s4jpij4ep6e5fea324bvbujitmjup63iexea" + "REPL_RPC_URL": "https://rpc.mainnet.near.org" } diff --git a/instances/treasury-factory.near/widget/app.jsx b/instances/treasury-factory.near/widget/app.jsx index ce6c5841..a8e02db6 100644 --- a/instances/treasury-factory.near/widget/app.jsx +++ b/instances/treasury-factory.near/widget/app.jsx @@ -9,22 +9,17 @@ const { page, ...passProps } = props; const { AppLayout } = VM.require( "${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.templates.AppLayout" ) || { AppLayout: () => <> }; - -const instance = "${REPL_INSTANCE}"; - -const { Theme } = VM.require(`${instance}/widget/config.css`) || { +const { Theme } = VM.require( + `${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/config.css` +) || { Theme: () => <>, }; -const propsToSend = { ...passProps, instance: instance }; +const propsToSend = { ...passProps }; return ( - + ; -} - -const { treasuryDaoID, navbarLinks, logo } = VM.require( - `${instance}/widget/config.data` -); - -const [showMenu, setShowMenu] = useState(false); - -const { href: linkHref } = VM.require("${REPL_DEVHUB}/widget/core.lib.url") || { - href: () => {}, -}; - -const MenuIcon = () => ( - - - -); - -const Navbar = styled.div` - padding: 1.5rem 1rem; - background-color: var(--theme-color); - color: var(--text-color); - display: flex; - flex-direction: row; - justify-content: space-between; - align-items: center; - - @media screen and (max-width: 768px) { - padding: 1.2rem 1rem; - } - - .account-container { - background-color: #e3e6e8; - color: #2c3e50; - font-size: 14px; - font-weight: 700; - } -`; - -const LinksContainer = styled.div` - font-size: 17px; - display: flex; - flex-direction: row; - align-items: center; - gap: 1.5rem; - - @media screen and (max-width: 768px) { - display: none; - } -`; - -const MobileMenu = styled.button` - all: unset; - display: none; - - @media screen and (max-width: 768px) { - display: block; - } -`; - -const MobileNav = styled.div` - display: none; - - @media screen and (max-width: 768px) { - display: flex; - } - - position: absolute; - top: 0; - right: 0; - - width: auto; - flex-direction: column; - align-items: flex-end; - gap: 1rem; - flex-shrink: 0; - - border-radius: 0px 0px 0px 16px; - background: rgba(41, 41, 41, 0.6); - backdrop-filter: blur(5px); - - z-index: 50; -`; - -const MobileLink = styled.a` - font-size: 17px; - font-style: normal; - font-weight: 400; - line-height: 15px; - margin-bottom: 1rem; -`; - -const isActive = (link) => - (link ?? "").toLowerCase() === props.page ? "active" : ""; - -function getTitle(text) { - return text.replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase()); -} - -return ( - -
- {logo ? ( - logo - ) : ( -
{getTitle(page ?? "dashboard")}
- )} -
- {treasuryDaoID} -
-
-
- - {(navbarLinks ?? []).map((link) => ( - - {link.title} - - ))} - - setShowMenu(!showMenu)}> - - -
- {showMenu && ( - -
setShowMenu(!showMenu)} - style={{ cursor: "pointer" }} - > - -
-
- {(navbarLinks ?? []).map((link, idx) => ( - - {link.title} - - ))} -
-
- )} -
-); diff --git a/instances/treasury-factory.near/widget/components/OffCanvas.jsx b/instances/treasury-factory.near/widget/components/OffCanvas.jsx deleted file mode 100644 index c7733f0f..00000000 --- a/instances/treasury-factory.near/widget/components/OffCanvas.jsx +++ /dev/null @@ -1,65 +0,0 @@ -const { isNearSocial } = VM.require( - "${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/lib.common" -) || { - isNearSocial: false, -}; - -const showCanvas = props.showCanvas; -const onClose = props.onClose; -const title = props.title; -const children = props.children; - -const Container = styled.div` - opacity: 1 !important; - .offcanvas.offcanvas-end { - width: 30% !important; - } - - @media screen and (max-width: 1200px) { - .offcanvas.offcanvas-end { - width: 50% !important; - } - } - - @media screen and (max-width: 768px) { - .offcanvas.offcanvas-end { - width: 100% !important; - } - } - - .offcanvas { - border-top-left-radius: 1rem !important; - border-bottom-left-radius: 1rem !important; - overflow: auto; - } -`; - -return ( - -
-
- -
- {title} -
-
- -
- {children} -
-
-
-); diff --git a/instances/treasury-factory.near/widget/components/ProfileAutocomplete.jsx b/instances/treasury-factory.near/widget/components/ProfileAutocomplete.jsx deleted file mode 100644 index ee8a966b..00000000 --- a/instances/treasury-factory.near/widget/components/ProfileAutocomplete.jsx +++ /dev/null @@ -1,136 +0,0 @@ -const { onClose, onSelect } = props; -if (!context.accountId || !props.term) return <>; - -let results = []; -const profilesData = Social.get("*/profile/name", "final") || {}; -const followingData = Social.get( - `${context.accountId}/graph/follow/**`, - "final" -); - -if (!profilesData || !followingData) return <>; - -const profiles = Object.entries(profilesData); -const term = (props.term || "").replace(/\W/g, "").toLowerCase(); -const limit = 5; - -for (let i = 0; i < profiles.length; i++) { - let score = 0; - const accountId = profiles[i][0]; - const accountIdSearch = profiles[i][0].replace(/\W/g, "").toLowerCase(); - const nameSearch = (profiles[i][1]?.profile?.name || "") - .replace(/\W/g, "") - .toLowerCase(); - const accountIdSearchIndex = accountIdSearch.indexOf(term); - const nameSearchIndex = nameSearch.indexOf(term); - - if (accountIdSearchIndex > -1 || nameSearchIndex > -1) { - score += 10; - - if (accountIdSearchIndex === 0) { - score += 10; - } - if (nameSearchIndex === 0) { - score += 10; - } - if (followingData[accountId] === "") { - score += 30; - } - - results.push({ - accountId, - score, - }); - } -} - -results.sort((a, b) => b.score - a.score); -results = results.slice(0, limit); - -const [open, setOpen] = useState(false); - -useEffect(() => { - if (results.length > 0) setOpen(true); -}, [results]); - -function onResultClick(id) { - onSelect(id); - onClose(); -} - -const Wrapper = styled.div` - position: relative; -`; - -const Scroller = styled.div` - position: relative; - - display: flex; - flex-direction: column; - width: 100%; - gap: 2px - overflow: auto; - scroll-behavior: smooth; - - > * { - max-width: 200px; - text-align: left; - flex-grow: 0; - flex-shrink: 0; - } -`; - -const Selection = styled.div` - font-size: 14px; - padding: 5px 0; - width: 100%; - background: transparent; - - &:hover { - cursor: pointer; - } -`; - -const CloseButton = styled.button` - position: absolute; - top: 0; - right: 10px; - background: none; - border: none; - display: block; - color #687076; - transition: all 200ms; - - &:hover { - color: #000; - } -`; - -if (results.length === 0) return <>; - -return ( - - - - - - - {results.map((result) => { - return ( - onResultClick(result.accountId)} - > - - - ); - })} - - -); diff --git a/instances/treasury-factory.near/widget/components/create-treasury/AddMemberForm.jsx b/instances/treasury-factory.near/widget/components/create-treasury/AddMemberForm.jsx index ea845190..b84bdd24 100644 --- a/instances/treasury-factory.near/widget/components/create-treasury/AddMemberForm.jsx +++ b/instances/treasury-factory.near/widget/components/create-treasury/AddMemberForm.jsx @@ -1,4 +1,4 @@ -const { fields, onClose, onSubmit } = props; +const { fields, setFields, onClose, onSubmit } = props; const FormFields = styled.div` .rbt-token { @@ -20,44 +20,30 @@ const PERMISSIONS = { }; const [open, setOpen] = useState(false); -const [memberAccount, setMemberAccount] = useState(fields.accountId ?? ""); -const [permissions, setPermissions] = useState(fields.permissions ?? []); return (
- { - setMemberAccount(e.target.value); - setOpen(true); + { + fields.accountId = value ?? fields.accountId; + setFields(fields); + }, + maxWidth: "100%", }} /> - - {open && ( - { - setMemberAccount(value); - fields.accountId = value; - }, - onClose: () => setOpen(false), - }} - /> - )}
{ - setPermissions(value); - fields.permissions = value; + fields.permissions = value ?? fields.permissions; + setFields(fields); }} options={Object.values(PERMISSIONS)} positionFixed @@ -65,12 +51,14 @@ return ( />
-
+
Close
0 && permissions.length > 0 ? "" : "disabled" + fields.accountId?.length > 0 && fields.permissions?.length > 0 + ? "" + : "disabled" }`} onClick={onSubmit} > diff --git a/instances/treasury-factory.near/widget/components/create-treasury/AddMembersStep.jsx b/instances/treasury-factory.near/widget/components/create-treasury/AddMembersStep.jsx index 85682d43..dd8e31a0 100644 --- a/instances/treasury-factory.near/widget/components/create-treasury/AddMembersStep.jsx +++ b/instances/treasury-factory.near/widget/components/create-treasury/AddMembersStep.jsx @@ -46,6 +46,8 @@ useEffect(() => { }); }, [members]); +console.log(members); + const ListItem = ({ member, key }) => (
@@ -109,12 +111,28 @@ function onSubmit() { newMembers.map((m) => m.accountId).lastIndexOf(el.accountId) === i ); setMembers(newMembers); + setFields({}); onClose(); } return ( <>
+ + ), + confirmLabel: "Confirm", + showCanvas: showAddMemberModal, + onClose, + }} + />

Add Members

Set up who can access the treasury and what they can do. You can also do @@ -137,18 +155,18 @@ return (

-
{ - setShowAddMemberModal(true); setFields({}); + setShowAddMemberModal(true); }} > Add member -
+
Back @@ -160,21 +178,5 @@ return ( Next
- - - ), - confirmLabel: "Confirm", - showCanvas: showAddMemberModal, - onClose, - }} - /> ); diff --git a/instances/treasury-factory.near/widget/components/create-treasury/CreateAppAccountStep.jsx b/instances/treasury-factory.near/widget/components/create-treasury/CreateAppAccountStep.jsx index 93bc1b9d..30eea82f 100644 --- a/instances/treasury-factory.near/widget/components/create-treasury/CreateAppAccountStep.jsx +++ b/instances/treasury-factory.near/widget/components/create-treasury/CreateAppAccountStep.jsx @@ -25,7 +25,7 @@ return (
Back diff --git a/instances/treasury-factory.near/widget/components/create-treasury/CreateSputnikAccountStep.jsx b/instances/treasury-factory.near/widget/components/create-treasury/CreateSputnikAccountStep.jsx index 12d052ba..8c560f79 100644 --- a/instances/treasury-factory.near/widget/components/create-treasury/CreateSputnikAccountStep.jsx +++ b/instances/treasury-factory.near/widget/components/create-treasury/CreateSputnikAccountStep.jsx @@ -44,7 +44,7 @@ return (
Back diff --git a/instances/treasury-factory.near/widget/components/create-treasury/SummaryStep.jsx b/instances/treasury-factory.near/widget/components/create-treasury/SummaryStep.jsx index 6d6c99c2..1ef6a02e 100644 --- a/instances/treasury-factory.near/widget/components/create-treasury/SummaryStep.jsx +++ b/instances/treasury-factory.near/widget/components/create-treasury/SummaryStep.jsx @@ -1,7 +1,5 @@ const { formFields } = props; -console.log(formFields); - const Section = styled.div` display: flex; flex-direction: column; @@ -41,8 +39,8 @@ function createDao() { } const ListItem = ({ member }) => ( - -
+ +
( />
-
+
{member.permissions.map((permission, i) => ( {permission} ))} @@ -126,8 +124,16 @@ return ( )} -
+
+
); diff --git a/instances/treasury-factory.near/widget/components/templates/AppLayout.jsx b/instances/treasury-factory.near/widget/components/templates/AppLayout.jsx index 96cd7ac9..a910b061 100644 --- a/instances/treasury-factory.near/widget/components/templates/AppLayout.jsx +++ b/instances/treasury-factory.near/widget/components/templates/AppLayout.jsx @@ -38,22 +38,11 @@ const Container = styled.div` width: 100%; `; -const AppHeader = ({ page, instance }) => ( - -); - -function AppLayout({ page, instance, skipHeader, children }) { +function AppLayout({ children }) { return ( - {!skipHeader && }
{children}
diff --git a/instances/treasury-factory.near/widget/config/css.jsx b/instances/treasury-factory.near/widget/config/css.jsx index 2e9139cc..c189bbcd 100644 --- a/instances/treasury-factory.near/widget/config/css.jsx +++ b/instances/treasury-factory.near/widget/config/css.jsx @@ -8,15 +8,22 @@ const Theme = styled.div` --border-color: rgba(226, 230, 236, 1); --light-grey-color: rgba(185, 185, 185, 1); --dark-grey-color: rgba(103, 103, 103, 1); + font-family: Inter; - .btn-outline-plain { - padding-block: 8px; - padding-inline: 10px; - border-radius: 0.375rem; - border: 1.5px solid #e2e6ec; - background-color: transparent; - color: black !important; + .btn { + display: flex; + align-items: center; + justify-content: center; + height: 40px; + border-radius: 8px; + font-size: 15px; + font-weight: 500; + + &:active, + &:focus { + border: 0; + } &:hover { text-decoration: none; @@ -25,6 +32,24 @@ const Theme = styled.div` } } + .btn-outline-plain { + border: 1px solid #e2e6ec; + background-color: transparent; + color: black !important; + + &:active, + &:focus { + border: 1px solid #e2e6ec; + } + } + + .btn-primary { + &:hover { + font-weight: 500 !important; + color: white !important; + } + } + .nav a { text-decoration: none; color: var(--link-inactive-color) !important; @@ -37,15 +62,6 @@ const Theme = styled.div` } } - button { - &.btn-primary { - background-color: var(--theme-color); - color: var(--text-color); - border: none !important; - padding-block: 0.7rem !important; - } - } - .page-header { color: var(--page-header-color); } diff --git a/instances/treasury-factory.near/widget/config/data.jsx b/instances/treasury-factory.near/widget/config/data.jsx deleted file mode 100644 index c63947d0..00000000 --- a/instances/treasury-factory.near/widget/config/data.jsx +++ /dev/null @@ -1,31 +0,0 @@ -return { - appName: "Treasury", - navbarLinks: [ - { - title: "Dashboard", - href: "?page=dashboard", - }, - { - title: "Payments", - href: "?page=payments", - }, - // { - // title: "Stake Delegation", - // href: "?page=stake-delegation", - // }, - // { - // title: "Asset Exchange", - // href: "?page=asset-exchange", - // }, - { - title: "Settings", - href: "?page=settings", - }, - ], - treasuryDaoID: "${REPL_TREASURY}", - proposalIndexerQueryName: "${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}", - proposalIndexerHasuraRole: "${REPL_X_HASURA_ROLE}", - showProposalSelection: true, - showKYC: true, - showReferenceProposal: true, -}; diff --git a/instances/treasury-factory.near/widget/lib/common.jsx b/instances/treasury-factory.near/widget/lib/common.jsx deleted file mode 100644 index 342ab661..00000000 --- a/instances/treasury-factory.near/widget/lib/common.jsx +++ /dev/null @@ -1,327 +0,0 @@ -function getApproversAndThreshold(treasuryDaoID, kind) { - const daoPolicy = Near.view(treasuryDaoID, "get_policy", {}); - const groupWithPermission = (daoPolicy.roles ?? []).filter((role) => { - const transferPermissions = [ - "*:*", - `${kind}:*`, - `${kind}:VoteApprove`, - `${kind}:VoteReject`, - `${kind}:VoteRemove`, - "*:VoteApprove", - "*:VoteReject", - "*:VoteRemove", - ]; - return (role?.permissions ?? []).some((i) => - transferPermissions.includes(i) - ); - }); - - let approversGroup = []; - let ratios = []; - let requiredVotes = null; - groupWithPermission.map((i) => { - approversGroup = approversGroup.concat(i.kind.Group ?? []); - if (i.vote_policy[kind].weight_kind === "RoleWeight") { - if (Array.isArray(i.vote_policy[kind].threshold)) { - ratios = ratios.concat(i.vote_policy[kind].threshold); - ratios = ratios.concat(i.vote_policy[kind].threshold); - } else { - requiredVotes = parseFloat(i.vote_policy[kind].threshold); - } - } - }); - - let numerator = 0; - let denominator = 0; - - if (ratios.length > 0) { - ratios.forEach((value, index) => { - if (index == 0 || index % 2 === 0) { - // Even index -> numerator - numerator += value; - } else { - // Odd index -> denominator - denominator += value; - } - }); - } - const approverAccounts = Array.from(new Set(approversGroup)); - - return { - approverAccounts, - requiredVotes: - requiredVotes || - Math.floor((numerator / denominator) * approverAccounts.length) + 1, - }; -} - -function getPolicyApproverGroup(treasuryDaoID) { - const daoPolicy = Near.view(treasuryDaoID, "get_policy", {}); - const groupWithPermission = (daoPolicy.roles ?? []).filter((role) => { - const policyPermissions = [ - "*:*", - "policy:AddProposal", - "policy:*", - "policy:VoteApprove", - "policy:VoteReject", - "policy:VoteRemove", - "*:VoteApprove", - "*:VoteReject", - "*:VoteRemove", - ]; - return (role?.permissions ?? []).some((i) => policyPermissions.includes(i)); - }); - - let approversGroup = []; - groupWithPermission.map((i) => { - approversGroup = approversGroup.concat(i.kind.Group ?? []); - }); - - return Array.from(new Set(approversGroup)); -} - -const filterFunction = (item, filterStatusArray, filterKindArray) => { - const kind = - typeof item.kind === "string" ? item.kind : Object.keys(item.kind)[0]; - if (filterStatusArray.length > 0 && filterKindArray.length > 0) { - return ( - filterStatusArray.includes(item.status) && filterKindArray.includes(kind) - ); - } else if (filterKindArray.length > 0) { - return filterKindArray.includes(kind); - } else if (filterStatusArray.length > 0) { - return filterStatusArray.includes(item.status); - } - return true; -}; - -function getFilteredProposalsByStatusAndKind({ - treasuryDaoID, - resPerPage, - isPrevPageCalled, - filterKindArray, - filterStatusArray, - offset, - lastProposalId, - currentPage, - isAssetExchange, - isStakeDelegation, -}) { - let newLastProposalId = typeof offset === "number" ? offset : lastProposalId; - let filteredProposals = []; - const limit = 30; - const promiseArray = []; - - if (isPrevPageCalled) { - let startIndex = newLastProposalId; - while (startIndex < lastProposalId) { - promiseArray.push( - Near.asyncView(treasuryDaoID, "get_proposals", { - from_index: startIndex, - limit: limit, - }) - ); - startIndex += limit; - } - } else { - while (newLastProposalId > 0) { - promiseArray.push( - Near.asyncView(treasuryDaoID, "get_proposals", { - from_index: - newLastProposalId - limit > 0 ? newLastProposalId - limit : 0, - limit: offset > 0 && offset < limit ? offset : limit, - }) - ); - newLastProposalId -= limit; - } - } - - const checkForExchangeProposals = (item) => { - const description = JSON.parse(item.description ?? "{}"); - return description.isAssetExchangeTxn; - }; - - const checkForStakeProposals = (item) => { - const description = JSON.parse(item.description ?? "{}"); - return description.isStakeRequest; - }; - - return Promise.all(promiseArray).then((res) => { - const proposals = [].concat(...res); - filteredProposals = proposals.filter((item) => { - const kindCondition = filterFunction( - item, - filterStatusArray, - filterKindArray - ); - // If isAssetExchange is true, check for description.isAssetExchangeTxn - if (isAssetExchange) { - return kindCondition && checkForExchangeProposals(item); - } - // If isStakeDelegation is true, check for description.isStakeRequest - if (isStakeDelegation) { - return kindCondition && checkForStakeProposals(item); - } - return kindCondition; - }); - const uniqueFilteredProposals = Array.from( - new Map(filteredProposals.map((item) => [item.id, item])).values() - ); - const sortedProposals = uniqueFilteredProposals.sort((a, b) => b.id - a.id); - const start = isPrevPageCalled ? currentPage * resPerPage : 0; - const end = isPrevPageCalled - ? currentPage * resPerPage + resPerPage - : resPerPage; - const newArray = sortedProposals.slice(start, end); - return { - filteredProposals: newArray, - totalLength: sortedProposals.length, - }; - }); -} - -const data = fetch(`https://httpbin.org/headers`); -const gatewayOrigin = data?.body?.headers?.Origin ?? ""; - -const isNearSocial = - gatewayOrigin.includes("near.social") || - gatewayOrigin.includes("127.0.0.1:8080") || - gatewayOrigin.includes("treasury-devdao.testnet.page") || - gatewayOrigin.includes("treasury-devdao.near.page"); - -function getMembersAndPermissions(treasuryDaoID) { - return Near.asyncView(treasuryDaoID, "get_policy", {}).then((daoPolicy) => { - const memberData = []; - - if (Array.isArray(daoPolicy.roles)) { - // Use a map to collect permissions and role names for each member - const memberMap = new Map(); - - daoPolicy.roles.forEach((role) => { - (role.kind.Group ?? []).forEach((member) => { - if (!memberMap.has(member)) { - memberMap.set(member, { - member: member, - permissions: [], - roles: [], - }); - } - - // Add permissions and role names - memberMap.get(member).permissions.push(...role.permissions); - memberMap.get(member).roles.push(role.name); - }); - }); - - // Convert map to array and remove duplicates - return Array.from(memberMap.values()).map((data) => ({ - member: data.member, - permissions: Array.from(new Set(data.permissions)), // Remove duplicate permissions - roles: Array.from(new Set(data.roles)), // Remove duplicate role names - })); - } - - return memberData; - }); -} - -function getDaoRoles(treasuryDaoID) { - const daoPolicy = Near.view(treasuryDaoID, "get_policy", {}); - if (Array.isArray(daoPolicy.roles)) { - return daoPolicy.roles.map((role) => role.name); - } - - return []; -} - -function hasPermission(treasuryDaoID, accountId, kindName, actionType) { - if (!accountId) { - return false; - } - const isAllowed = false; - const daoPolicy = Near.view(treasuryDaoID, "get_policy", {}); - if (Array.isArray(daoPolicy.roles)) { - const permissions = daoPolicy.roles.map((role) => { - if ( - Array.isArray(role.kind.Group) && - role.kind.Group.includes(accountId) - ) { - return ( - role.permissions.includes(`${kindName}:${actionType.toString()}`) || - role.permissions.includes(`${kindName}:*`) || - role.permissions.includes(`${kindName}:VoteApprove`) || - role.permissions.includes(`${kindName}:VoteReject`) || - role.permissions.includes(`${kindName}:VoteRemove`) || - role.permissions.includes(`*:${actionType.toString()}`) || - role.permissions.includes("*:*") - ); - } - }); - isAllowed = permissions.some((element) => element === true); - } - return isAllowed; -} - -function getPermissionsText(type) { - switch (type) { - case "Create Requests": - case "Create requests": - return "Enables users to initiate payment requests."; - case "Manage Members": { - return "Allows users to control treasury adminis and their access levels."; - } - case "Vote": { - return "Allows users to approve or request proposed payment requests."; - } - default: - return ""; - } -} - -function isBosGateway() { - return ( - // for tests - gatewayOrigin.includes("localhost:8080") || - gatewayOrigin.includes("near.social") || - gatewayOrigin.includes("dev.near.org") - ); -} -function formatNearAmount(amount) { - return Big(amount ?? "0") - .div(Big(10).pow(24)) - .toFixed(4); -} - -function getNearBalances(treasuryDaoID) { - const resp = fetch( - `https://api.fastnear.com/v1/account/${treasuryDaoID}/full` - ); - const locked = Big(resp?.body?.state?.storage_bytes ?? "0") - .mul(Big(10).pow(19)) - .toFixed(); - const total = Big(resp?.body?.state?.balance ?? "0").toFixed(); - const available = Big(resp?.body?.state?.balance ?? "0") - .minus(locked ?? "0") - .toFixed(); - return { - total, - available, - locked, - totalParsed: formatNearAmount(total), - availableParsed: formatNearAmount(available), - lockedParsed: formatNearAmount(locked), - }; -} - -return { - getApproversAndThreshold, - hasPermission, - getFilteredProposalsByStatusAndKind, - isNearSocial, - getMembersAndPermissions, - getDaoRoles, - getPolicyApproverGroup, - getPermissionsText, - isBosGateway, - getNearBalances, -}; diff --git a/instances/treasury-factory.near/widget/pages/treasury/Create.jsx b/instances/treasury-factory.near/widget/pages/treasury/Create.jsx index 1aad852e..d5925df5 100644 --- a/instances/treasury-factory.near/widget/pages/treasury/Create.jsx +++ b/instances/treasury-factory.near/widget/pages/treasury/Create.jsx @@ -1,5 +1,5 @@ const { isNearSocial } = VM.require( - "${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/lib.common" + "${REPL_DEVDAO_ACCOUNT}/widget/lib.common" ) || { isNearSocial: false, }; @@ -75,7 +75,7 @@ const Wrapper = ({ title, children }) => (
-