community_demo.gno
    2.10 Kb ยท 69 lines
    
  
 1package community_demo
 2
 3import (
 4	"gno.land/p/zenao/basedao"
 5	"gno.land/p/zenao/communities"
 6	"gno.land/p/zenao/daocond"
 7	"gno.land/p/zenao/daokit"
 8	"gno.land/r/demo/profile"
 9	"gno.land/r/zenao/social_feed"
10)
11
12var (
13	DAO      daokit.DAO
14	localDAO daokit.DAO
15
16	community *communities.Community // XXX: needed for backward compatibility with frontend queries
17	feedId    string                 // XXX: workaround for "unexpected zero object id" issue
18)
19
20func init() {
21	feedId = social_feed.NewFeed(cross, "main", false, feedAuth) // XXX: workaround for "unexpected zero object id" issue
22}
23
24func init() {
25	zenaoAdmin := "g1djrkw9tf4px658j85cc6fhsvm50uf9s0g6kfsm"
26	creator := "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // replace w/ address of the user realm
27	conf := communities.Config{
28		ZenaoAdminAddr:   zenaoAdmin,
29		Administrators:   []string{creator},
30		Members:          []string{},
31		Events:           []string{},
32		DisplayName:      "Demo Community",
33		Description:      "This is a demo community for Zenao",
34		AvatarURI:        "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/Wiki-IMG_20200904_200004436.jpg/640px-Wiki-IMG_20200904_200004436.jpg",
35		BannerURI:        "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/Wiki-IMG_20200904_200004436.jpg/640px-Wiki-IMG_20200904_200004436.jpg",
36		GetProfileString: profile.GetStringField,
37		SetProfileString: profile.SetStringField,
38		CrossFn:          crossFn,
39		SetImplemFn:      setImplem,
40		FeedId:           feedId,
41		PrivateVarName:   "community",
42	}
43	community = communities.NewCommunity(&conf)
44}
45
46func Vote(_ realm, proposalID uint64, vote daocond.Vote) {
47	localDAO.Vote(proposalID, vote)
48}
49
50func Execute(_ realm, proposalID uint64) {
51	localDAO.Execute(proposalID)
52}
53
54func Render(path string) string {
55	return localDAO.Render(path)
56}
57
58func feedAuth() (string, bool) {
59	caller := community.DAOPrivate.CallerID() // XXX: this should be upgradable
60	return caller, basedao.MustGetMembersViewExtension(localDAO).IsMember(caller)
61}
62
63func crossFn(_ realm, cb func()) {
64	cb()
65}
66
67func setImplem(newLocalDAO daokit.DAO, newDAO daokit.DAO) {
68	localDAO, DAO = newLocalDAO, newDAO
69}