Skip to content

Commit c66923d

Browse files
committed
Merge branch 'main' into feat-rakki-terms-and-conditions
# Conflicts: # packages/screens/Rakki/RakkiScreen.tsx
2 parents 598d4e8 + 6402d06 commit c66923d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+8826
-463
lines changed

assets/lottie/confetti-lottie.json

Lines changed: 7555 additions & 0 deletions
Large diffs are not rendered by default.

gno/p/daocond/cond_and.gno

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package daocond
2+
3+
import (
4+
"gno.land/p/demo/json"
5+
)
6+
7+
func And(left Condition, right Condition) Condition {
8+
if left == nil || right == nil {
9+
panic("left or right is nil")
10+
}
11+
return &andCond{left: left, right: right}
12+
}
13+
14+
type andCond struct {
15+
// XXX: use a slice instead of only two children?
16+
left Condition
17+
right Condition
18+
}
19+
20+
// NewState implements Condition.
21+
func (a *andCond) NewState() State {
22+
return &andState{left: a.left.NewState(), right: a.right.NewState()}
23+
}
24+
25+
// Render implements Condition.
26+
func (a *andCond) Render() string {
27+
return "[" + a.left.Render() + " AND " + a.right.Render() + "]"
28+
}
29+
30+
// RenderJSON implements Condition.
31+
func (a *andCond) RenderJSON() *json.Node {
32+
return json.ObjectNode("", map[string]*json.Node{
33+
"type": json.StringNode("", "and"),
34+
"left": a.left.RenderJSON(),
35+
"right": a.right.RenderJSON(),
36+
})
37+
}
38+
39+
var _ Condition = (*andCond)(nil)
40+
41+
type andState struct {
42+
left State
43+
right State
44+
}
45+
46+
// RenderJSON implements State.
47+
func (a *andState) RenderJSON(votes map[string]Vote) *json.Node {
48+
return json.ObjectNode("", map[string]*json.Node{
49+
"type": json.StringNode("", "and"),
50+
"left": a.left.RenderJSON(votes),
51+
"right": a.right.RenderJSON(votes),
52+
})
53+
}
54+
55+
// Eval implements State.
56+
func (a *andState) Eval(votes map[string]Vote) bool {
57+
return a.left.Eval(votes) && a.right.Eval(votes)
58+
}
59+
60+
// HandleEvent implements State.
61+
func (a *andState) HandleEvent(evt Event, votes map[string]Vote) {
62+
a.left.HandleEvent(evt, votes)
63+
a.right.HandleEvent(evt, votes)
64+
}
65+
66+
var _ State = (*andState)(nil)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package daocond
2+
3+
import (
4+
"errors"
5+
6+
"gno.land/p/demo/json"
7+
"gno.land/p/demo/ufmt"
8+
)
9+
10+
func MembersThreshold(threshold float64, isMemberFn func(memberId string) bool, membersCountFn func() uint64) Condition {
11+
if threshold <= 0 || threshold > 1 {
12+
panic(errors.New("invalid threshold"))
13+
}
14+
if isMemberFn == nil {
15+
panic(errors.New("nil isMemberFn"))
16+
}
17+
if membersCountFn == nil {
18+
panic(errors.New("nil membersCountFn"))
19+
}
20+
return &membersThresholdCond{
21+
threshold: threshold,
22+
isMemberFn: isMemberFn,
23+
membersCountFn: membersCountFn,
24+
}
25+
}
26+
27+
type membersThresholdCond struct {
28+
isMemberFn func(memberId string) bool
29+
membersCountFn func() uint64
30+
threshold float64
31+
}
32+
33+
// NewState implements Condition.
34+
func (m *membersThresholdCond) NewState() State {
35+
return &membersThresholdState{
36+
cond: m,
37+
}
38+
}
39+
40+
// Render implements Condition.
41+
func (m *membersThresholdCond) Render() string {
42+
return ufmt.Sprintf("%g%% of members", m.threshold*100)
43+
}
44+
45+
// RenderJSON implements Condition.
46+
func (m *membersThresholdCond) RenderJSON() *json.Node {
47+
return json.ObjectNode("", map[string]*json.Node{
48+
"type": json.StringNode("", "members-threshold"),
49+
"threshold": json.NumberNode("", m.threshold),
50+
})
51+
}
52+
53+
var _ Condition = (*membersThresholdCond)(nil)
54+
55+
type membersThresholdState struct {
56+
cond *membersThresholdCond
57+
totalYes uint64
58+
}
59+
60+
// Eval implements State.
61+
func (m *membersThresholdState) Eval(_ map[string]Vote) bool {
62+
return float64(m.totalYes)/float64(m.cond.membersCountFn()) >= m.cond.threshold
63+
}
64+
65+
// HandleEvent implements State.
66+
func (m *membersThresholdState) HandleEvent(evt Event, votes map[string]Vote) {
67+
switch evt := evt.(type) {
68+
case *EventVote:
69+
if !m.cond.isMemberFn(evt.VoterID) {
70+
return
71+
}
72+
previousVote := votes[evt.VoterID]
73+
if previousVote == VoteYes && evt.Vote != VoteYes {
74+
m.totalYes -= 1
75+
} else if previousVote != VoteYes && evt.Vote == VoteYes {
76+
m.totalYes += 1
77+
}
78+
79+
case *EventMemberAdded:
80+
if votes[evt.MemberID] == VoteYes {
81+
m.totalYes += 1
82+
}
83+
84+
case *EventMemberRemoved:
85+
if votes[evt.MemberID] == VoteYes {
86+
m.totalYes -= 1
87+
}
88+
}
89+
}
90+
91+
// RenderJSON implements State.
92+
func (m *membersThresholdState) RenderJSON(_ map[string]Vote) *json.Node {
93+
return json.ObjectNode("", map[string]*json.Node{
94+
"type": json.StringNode("", "members-threshold"),
95+
"totalYes": json.NumberNode("", float64(m.totalYes)),
96+
})
97+
}
98+
99+
var _ State = (*membersThresholdState)(nil)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package daocond
2+
3+
import (
4+
"errors"
5+
6+
"gno.land/p/demo/json"
7+
"gno.land/p/demo/ufmt"
8+
)
9+
10+
func MembersThresholdFewVotes(threshold float64, isMemberFn func(memberId string) bool, membersCountFn func() uint64) Condition {
11+
if threshold <= 0 || threshold > 1 {
12+
panic(errors.New("invalid threshold"))
13+
}
14+
if isMemberFn == nil {
15+
panic(errors.New("nil isMemberFn"))
16+
}
17+
if membersCountFn == nil {
18+
panic(errors.New("nil membersCountFn"))
19+
}
20+
return &membersThresholdFewVotesCond{
21+
threshold: threshold,
22+
isMemberFn: isMemberFn,
23+
membersCountFn: membersCountFn,
24+
}
25+
}
26+
27+
type membersThresholdFewVotesCond struct {
28+
isMemberFn func(memberId string) bool
29+
membersCountFn func() uint64
30+
threshold float64
31+
}
32+
33+
// NewState implements Condition.
34+
func (m *membersThresholdFewVotesCond) NewState() State {
35+
return &membersThresholdFewVotesState{
36+
cond: m,
37+
}
38+
}
39+
40+
// Render implements Condition.
41+
func (m *membersThresholdFewVotesCond) Render() string {
42+
return ufmt.Sprintf("%g%% of members", m.threshold*100)
43+
}
44+
45+
// RenderJSON implements Condition.
46+
func (m *membersThresholdFewVotesCond) RenderJSON() *json.Node {
47+
return json.ObjectNode("", map[string]*json.Node{
48+
"type": json.StringNode("", "members-threshold"),
49+
"threshold": json.NumberNode("", m.threshold),
50+
})
51+
}
52+
53+
var _ Condition = (*membersThresholdFewVotesCond)(nil)
54+
55+
type membersThresholdFewVotesState struct {
56+
cond *membersThresholdFewVotesCond
57+
}
58+
59+
func (m *membersThresholdFewVotesState) totalYes(votes map[string]Vote) uint64 {
60+
totalYes := uint64(0)
61+
for userId, vote := range votes {
62+
if vote != VoteYes {
63+
continue
64+
}
65+
if !m.cond.isMemberFn(userId) {
66+
continue
67+
}
68+
totalYes += 1
69+
}
70+
return totalYes
71+
}
72+
73+
// Eval implements State.
74+
func (m *membersThresholdFewVotesState) Eval(votes map[string]Vote) bool {
75+
return float64(m.totalYes(votes))/float64(m.cond.membersCountFn()) >= m.cond.threshold
76+
}
77+
78+
// HandleEvent implements State.
79+
func (m *membersThresholdFewVotesState) HandleEvent(_ Event, _ map[string]Vote) {
80+
panic(errors.New("not implemented"))
81+
}
82+
83+
// RenderJSON implements State.
84+
func (m *membersThresholdFewVotesState) RenderJSON(votes map[string]Vote) *json.Node {
85+
return json.ObjectNode("", map[string]*json.Node{
86+
"type": json.StringNode("", "members-threshold"),
87+
"totalYes": json.NumberNode("", float64(m.totalYes(votes))),
88+
})
89+
}
90+
91+
var _ State = (*membersThresholdFewVotesState)(nil)

gno/p/daocond/cond_or.gno

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package daocond
2+
3+
import (
4+
"gno.land/p/demo/json"
5+
)
6+
7+
func Or(left Condition, right Condition) Condition {
8+
if left == nil || right == nil {
9+
panic("left or right is nil")
10+
}
11+
return &orCond{left: left, right: right}
12+
}
13+
14+
type orCond struct {
15+
// XXX: use a slice instead of only two children?
16+
left Condition
17+
right Condition
18+
}
19+
20+
// NewState implements Condition.
21+
func (a *orCond) NewState() State {
22+
return &orState{left: a.left.NewState(), right: a.right.NewState()}
23+
}
24+
25+
// Render implements Condition.
26+
func (a *orCond) Render() string {
27+
return "[" + a.left.Render() + " OR " + a.right.Render() + "]"
28+
}
29+
30+
// RenderJSON implements Condition.
31+
func (a *orCond) RenderJSON() *json.Node {
32+
return json.ObjectNode("", map[string]*json.Node{
33+
"type": json.StringNode("", "or"),
34+
"left": a.left.RenderJSON(),
35+
"right": a.right.RenderJSON(),
36+
})
37+
}
38+
39+
var _ Condition = (*andCond)(nil)
40+
41+
type orState struct {
42+
left State
43+
right State
44+
}
45+
46+
// Eval implements State.
47+
func (a *orState) Eval(votes map[string]Vote) bool {
48+
return a.left.Eval(votes) || a.right.Eval(votes)
49+
}
50+
51+
// HandleEvent implements State.
52+
func (a *orState) HandleEvent(evt Event, votes map[string]Vote) {
53+
a.left.HandleEvent(evt, votes)
54+
a.right.HandleEvent(evt, votes)
55+
}
56+
57+
// RenderJSON implements State.
58+
func (a *orState) RenderJSON(votes map[string]Vote) *json.Node {
59+
return json.ObjectNode("", map[string]*json.Node{
60+
"type": json.StringNode("", "and"),
61+
"left": a.left.RenderJSON(votes),
62+
"right": a.right.RenderJSON(votes),
63+
})
64+
}
65+
66+
var _ State = (*orState)(nil)

0 commit comments

Comments
 (0)