# HG changeset patch # User bsw # Date 1647940762 -3600 # Node ID accb808d5b4aff27bbcaa1966e3e8b6386b3c882 # Parent c3dba3a85be30d4751dab9807a01b92429dff891 Added token based voting diff -r c3dba3a85be3 -r accb808d5b4a app/main/_prefork/10_init.lua --- a/app/main/_prefork/10_init.lua Thu Feb 03 16:10:39 2022 +0100 +++ b/app/main/_prefork/10_init.lua Tue Mar 22 10:19:22 2022 +0100 @@ -283,5 +283,21 @@ } end +if config.token then + assert(loadcached(encode.file_path(WEBMCP_BASE_PATH, "lib", "token", "sync.lua")))() + listen{ + { + proto = "interval", + name = "sync_token", + delay = 5, + handler = function() + sync_token() + end + }, + min_fork = 1, + max_fork = 1 + } +end + execute.inner() diff -r c3dba3a85be3 -r accb808d5b4a env/ui/supporter_count.lua --- a/env/ui/supporter_count.lua Thu Feb 03 16:10:39 2022 +0100 +++ b/env/ui/supporter_count.lua Tue Mar 22 10:19:22 2022 +0100 @@ -5,18 +5,34 @@ content = _"[calculating]" } elseif initiative.issue.closed == nil then - ui.tag { - attr = { class = "satisfiedSupporterCount" }, - content = _("#{count} supporter", { count = initiative.satisfied_supporter_count }) - } - if initiative.potential_supporter_count and - initiative.potential_supporter_count > 0 - then - slot.put ( " " ) + if config.token and initiative.issue.area.unit_id == config.token.unit_id then ui.tag { - attr = { class = "potentialSupporterCount" }, - content = _("(+ #{count} potential)", { count = initiative.potential_supporter_count }) + attr = { class = "satisfiedSupporterCount" }, + content = _("#{count} #{token_name}", { count = initiative.satisfied_supporter_count / 100, token_name = config.token.token_name }) } + if initiative.potential_supporter_count and + initiative.potential_supporter_count > 0 + then + slot.put ( " " ) + ui.tag { + attr = { class = "potentialSupporterCount" }, + content = _("(+ #{count} potential)", { count = initiative.potential_supporter_count / 100 }) + } + end + else + ui.tag { + attr = { class = "satisfiedSupporterCount" }, + content = _("#{count} supporter", { count = initiative.satisfied_supporter_count }) + } + if initiative.potential_supporter_count and + initiative.potential_supporter_count > 0 + then + slot.put ( " " ) + ui.tag { + attr = { class = "potentialSupporterCount" }, + content = _("(+ #{count} potential)", { count = initiative.potential_supporter_count }) + } + end end end end diff -r c3dba3a85be3 -r accb808d5b4a lib/token/sync.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/token/sync.lua Tue Mar 22 10:19:22 2022 +0100 @@ -0,0 +1,52 @@ +function _G.sync_token() + local request = [[ + { + "query": "query balanceNotificationMany($tokenSymbol: String) { + balanceNotificationMany(filter: { token_symbol: $tokenSymbol }) { + _id + account_pk + name + token_symbol + amount + contractAddress + owner + } + }", + "variables": { + "tokenSymbol": "]] .. config.token.token_name .. [[" + } + } + ]] + + local output, err, status = extos.pfilter(request, "curl", "--insecure", "-X", "POST", "-H", "Content-Type: application/json", "-H", "X-REQUEST-TYPE: GraphQL", "-d", "@-", config.token.graphql_url) + + local data = json.import(output) + + local privileges = Privilege:new_selector() + :add_where{ "unit_id = ?", config.token.unit_id } + :exec() + + for i, privilege in ipairs(privileges) do + privilege:destroy() + end + + for i, entry in ipairs(data.data.balanceNotificationMany) do + print(entry.account_pk, entry.amount) + local member = Member:new_selector() + :join("member_profile", nil, "member_profile.member_id = member.id") + :add_where{ "member_profile.profile->>'" .. config.token.key_profile_field .."' = ?", entry.account_pk } + :optional_object_mode() + :exec() + print(member.name) + if member then + local privilege = Privilege:new() + privilege.unit_id = config.token.unit_id + privilege.member_id = member.id + privilege.initiative_right = true + privilege.voting_right = true + privilege.weight = entry.amount + privilege:save() + end + end + +end \ No newline at end of file