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

feat(gno/orgs): save & display kind of organizations #1469

Merged
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
2 changes: 1 addition & 1 deletion gno/p/dao_roles_voting_group/roles_voting_group.gno
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewRolesVotingGroup(rm *dao_roles_group.RolesGroup) *RolesVotingGroup {

func (v *RolesVotingGroup) Info() dao_interfaces.ModuleInfo {
return dao_interfaces.ModuleInfo{
Kind: "gno.land/p/teritori/dao_voting_group",
Kind: "gno.land/p/teritori/dao_roles_voting_group",
Version: "0.1.0",
}
}
Expand Down
38 changes: 38 additions & 0 deletions packages/hooks/dao/useDAOKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { GnoJSONRPCProvider } from "@gnolang/gno-js-client";
import { useQuery } from "@tanstack/react-query";

import { NetworkKind, parseUserId } from "@/networks";
import { extractGnoString } from "@/utils/gno";
import { extractDaoKind } from "@/utils/gnodao/helpers";

export const useDAOKind = (daoId: string | undefined) => {
const { data, ...other } = useQuery(
["daoKind", daoId],
async () => {
if (!daoId) {
return null;
}
const [network, packagePath] = parseUserId(daoId);
if (network?.kind !== NetworkKind.Gno) {
return null;
}
// Ensure is a DAO by checking the addr is a realm addr and not an EOA
if (!packagePath?.startsWith("gno.land/")) {
return null;
}

const provider = new GnoJSONRPCProvider(network.endpoint);
const info = extractGnoString(
await provider.evaluateExpression(
packagePath,
`daoCore.VotingModule().Info().String()`,
0,
),
);

return extractDaoKind(info);
},
{ staleTime: Infinity, enabled: !!daoId },
);
return { daoKind: data, ...other };
};
34 changes: 32 additions & 2 deletions packages/screens/UserPublicProfile/components/UPPIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { SocialButton } from "@/components/buttons/SocialButton";
import { SocialButtonSecondary } from "@/components/buttons/SocialButtonSecondary";
import { ProfileButton } from "@/components/hub/ProfileButton";
import { UserAvatarWithFrame } from "@/components/images/AvatarWithFrame";
import { useIsDAO } from "@/hooks/cosmwasm/useCosmWasmContractInfo";
import { useDAOKind } from "@/hooks/dao/useDAOKind";
import { usePremiumChannel } from "@/hooks/feed/usePremiumChannel";
import { usePremiumIsSubscribed } from "@/hooks/feed/usePremiumIsSubscribed";
import { useMaxResolution } from "@/hooks/useMaxResolution";
Expand All @@ -36,10 +38,11 @@ import { DEFAULT_NAME } from "@/utils/social-feed";
import {
neutral00,
neutral55,
neutralA3,
secondaryColor,
yellowPremium,
} from "@/utils/style/colors";
import { fontBold16, fontMedium14 } from "@/utils/style/fonts";
import { fontBold16, fontMedium14, fontSemibold12 } from "@/utils/style/fonts";
import { layout, RESPONSIVE_BREAKPOINT_S } from "@/utils/style/layout";
import { tinyAddress } from "@/utils/text";
import { normalizeTwitterId } from "@/utils/twitter";
Expand All @@ -51,6 +54,8 @@ export const UPPIntro: React.FC<{
}> = ({ userId, isUserOwner, setIsEditProfileModal = (val) => {} }) => {
const selectedWallet = useSelectedWallet();
const { metadata } = useNSUserInfo(userId);
const { isDAO } = useIsDAO(userId);
const { daoKind } = useDAOKind(userId);
const { copyToClipboard } = useCopyToClipboard();
const socialButtonStyle = { margin: layout.spacing_x0_75 };
const [network, userAddress] = parseUserId(userId);
Expand Down Expand Up @@ -285,7 +290,32 @@ export const UPPIntro: React.FC<{
@{metadata.tokenId || userAddress}
</BrandText>
</>

{isDAO && daoKind && (
<View
style={[
{
marginTop: layout.spacing_x1,
justifyContent: "center",
borderRadius: 4,
backgroundColor: "#1C1C1C",
height: 18,
paddingHorizontal: 4,
alignSelf: "flex-start",
},
]}
>
<BrandText
style={[
fontSemibold12,
{
color: neutralA3,
},
]}
>
{daoKind}
</BrandText>
</View>
)}
<BrandText
style={[
fontMedium14,
Expand Down
14 changes: 14 additions & 0 deletions packages/utils/gnodao/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ export const getPercent = (num: number | undefined): string => {
ret_num = ret_num > 100 ? 100 : ret_num;
return (ret_num / 100).toFixed(2);
};

export const extractDaoKind = (
votingModuleInfo: string,
): string | undefined => {
const rawDaoKind = votingModuleInfo.split("@v")[0];
switch (rawDaoKind) {
case "gno.land/p/teritori/dao_roles_voting_group":
return "roles based organization";
case "gno.land/p/teritori/dao_voting_group":
return "memberships based organization";
default:
return undefined;
}
};
Loading