Skip to content

Commit

Permalink
feat(gno/dao): remove previous approach
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelVallenet committed Jan 2, 2025
1 parent fcdd659 commit 4a78eda
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gno/r/dao_realm/dao_realm.gno
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func RegisterSelf() {
panic("already registered")
}

dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "DAO Realm", "Default testing DAO", "memberships based organization", "https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?w=1080&fit=max")
dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "DAO Realm", "Default testing DAO", "https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?w=1080&fit=max")
registered = true
}

Expand Down
9 changes: 3 additions & 6 deletions gno/r/dao_registry/dao_registry.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Registration struct {
CreatedAt time.Time `json:"createdAt"`
Name string `json:"name"`
Description string `json:"description"`
Kind string `json:"kind"`
ImageURI string `json:"imageURI"`
Getter DAOGetter `json:"-"`
}
Expand All @@ -31,18 +30,18 @@ var (

type DAOGetter func() dao_interfaces.IDAOCore

func Register(getter DAOGetter, name string, description string, kind string, imageURI string) {
func Register(getter DAOGetter, name string, description string, imageURI string) {
realm := std.PrevRealm()
pkgPath := realm.PkgPath()
if pkgPath == "" {
panic("caller is not a realm")
}

doRegister(getter, pkgPath, realm.Addr(), name, description, kind, imageURI)
doRegister(getter, pkgPath, realm.Addr(), name, description, imageURI)
}

// splitted for tests
func doRegister(getter DAOGetter, pkgPath string, addr std.Address, name string, description string, kind string, imageURI string) {
func doRegister(getter DAOGetter, pkgPath string, addr std.Address, name string, description string, imageURI string) {
if byPkgPath.Has(pkgPath) {
panic("already registered")
}
Expand All @@ -53,7 +52,6 @@ func doRegister(getter DAOGetter, pkgPath string, addr std.Address, name string,
CreatedAt: time.Now(),
Name: name,
Description: description,
Kind: kind,
ImageURI: imageURI,
Getter: getter,
}
Expand Down Expand Up @@ -120,7 +118,6 @@ func (r Registration) ToJSON() *json.Node {
"createdAt": jsonutil.TimeNode(r.CreatedAt),
"name": json.StringNode("", r.Name),
"description": json.StringNode("", r.Description),
"kind": json.StringNode("", r.Kind),
"imageURI": json.StringNode("", r.ImageURI),
})
}
6 changes: 3 additions & 3 deletions gno/r/dao_registry/dao_registry_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRegistry(t *testing.T) {
addr := std.DerivePkgAddr(pkgPath)
createdAt := time.Now()
core := dao_interfaces.NewDummyCore()
doRegister(func() dao_interfaces.IDAOCore { return core }, pkgPath, addr, "Test DAO", `This is a test DAO"\n\r\t\`+"\n\r\t", "kind", "https://example.com/image.png")
doRegister(func() dao_interfaces.IDAOCore { return core }, pkgPath, addr, "Test DAO", `This is a test DAO"\n\r\t\`+"\n\r\t", "https://example.com/image.png")

registrations = List("", "", 0, false)
if len(registrations) != 1 {
Expand All @@ -45,13 +45,13 @@ func TestRegistry(t *testing.T) {
}

registrationsJSON = ListJSON("", "", 0, false)
expected := ufmt.Sprintf(`[{"pkgPath":"gno.land/r/demo/test_dao","addr":"g1m56y6xlx95sykjchn9h9q4e7k5u2zte4as9rdr","createdAt":"2009-02-13T23:31:30Z","name":"Test DAO","description":"This is a test DAO\"\\n\\r\\t\\\n\r\t","kind":"kind","imageURI":"https://example.com/image.png"}]`)
expected := ufmt.Sprintf(`[{"pkgPath":"gno.land/r/demo/test_dao","addr":"g1m56y6xlx95sykjchn9h9q4e7k5u2zte4as9rdr","createdAt":"2009-02-13T23:31:30Z","name":"Test DAO","description":"This is a test DAO\"\\n\\r\\t\\\n\r\t","imageURI":"https://example.com/image.png"}]`)
if registrationsJSON != expected {
t.Fatal("expected JSON to match, got:\n" + registrationsJSON + "\nexpected:\n" + expected)
}

registrationJSON := GetJSON(pkgPath)
expected = ufmt.Sprintf(`{"pkgPath":"gno.land/r/demo/test_dao","addr":"g1m56y6xlx95sykjchn9h9q4e7k5u2zte4as9rdr","createdAt":"2009-02-13T23:31:30Z","name":"Test DAO","description":"This is a test DAO\"\\n\\r\\t\\\n\r\t","kind":"kind","imageURI":"https://example.com/image.png"}`)
expected = ufmt.Sprintf(`{"pkgPath":"gno.land/r/demo/test_dao","addr":"g1m56y6xlx95sykjchn9h9q4e7k5u2zte4as9rdr","createdAt":"2009-02-13T23:31:30Z","name":"Test DAO","description":"This is a test DAO\"\\n\\r\\t\\\n\r\t","imageURI":"https://example.com/image.png"}`)
if registrationJSON != expected {
t.Fatal("expected JSON to match, got:\n" + registrationJSON + "\nexpected:\n" + expected)
}
Expand Down
2 changes: 1 addition & 1 deletion gno/r/dao_roles_realm.gno/dao_roles_realm.gno
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func RegisterSelf() {
panic("already registered")
}

dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "DAO Realm", "Default testing DAO", "roles based organization", "https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?w=1080&fit=max")
dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "DAO Realm", "Default testing DAO", "https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?w=1080&fit=max")
registered = true
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/hooks/gno/useGnoDAOs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type GnoDAORegistration = {
name: string;
description: string;
imageURI: string;
kind: string;
};

export const useGnoDAOs = (networkId: string | undefined) => {
Expand Down
1 change: 0 additions & 1 deletion packages/hooks/useNSNameInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const gnoGetNSNameInfo = async (
public_name: res.name,
public_bio: res.description,
image: res.imageURI,
dao_kind: res.kind,
};
const user: NftInfoResponse = {
extension: data,
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/gnodao/generateMembershipDAOSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const generateMembershipDAOSource = (
profile.SetStringField(profile.Bio, "${conf.description}")
profile.SetStringField(profile.Avatar, "${conf.imageURI}")
dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "${conf.displayName}", "${conf.description}", "memberships based organization", "${conf.imageURI}")
dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "${conf.displayName}", "${conf.description}", "${conf.imageURI}")
}
func Render(path string) string {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/gnodao/generateRolesDAOSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func init() {
profile.SetStringField(profile.Bio, "${conf.description}")
profile.SetStringField(profile.Avatar, "${conf.imageURI}")
dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "${conf.displayName}", "${conf.description}", "roles based organization", "${conf.imageURI}")
dao_registry.Register(func() dao_interfaces.IDAOCore { return daoCore }, "${conf.displayName}", "${conf.description}", "${conf.imageURI}")
}
func Render(path string) string {
Expand Down

0 comments on commit 4a78eda

Please sign in to comment.