Offer explicit Telegram Stars consent in Entity Profile
This commit is contained in:
1 parent
ea3182b363
commit
6aa89ff852
8 files changed
+408
-33
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Add an optional, separate Telegram Stars consent action to the shared Profile authorization review.
|
||||
- Export the Telegram Mini App launch and Stars checkout client contract, including validation of catalog and invoice replies.
|
||||
- Build with Ziran 7fbc8152 and Kryon 3627ea8a, the Kryon without raylib, together with Plot, Game2D, CSS and Apps.
|
||||
- The `native-crypto` artifact's Android and Windows runtimes generate their C with the toolchain's own `zi2c` under the device's target conditions, so an ARMv7 build no longer cross-compiles a code generator against glibc symbols bionic lacks; Android consumers also link liblog, which the runtime's diagnostics use.
|
||||
|
||||
@@ -323,3 +323,10 @@ telegram-mini-app-test:
|
||||
printf 'Telegram Mini App VM fixture returned %s\n' "$$result" && test "$$result" = 0
|
||||
|
||||
test: telegram-mini-app-test
|
||||
|
||||
.PHONY: telegram-view-test
|
||||
telegram-view-test: build/entity.zx build/ziran/libziran.a
|
||||
LDLIBS='$(abspath build/ziran/libziran.a) -lpthread' $(ZIRAN) build --project $(LOCK_FLAGS) --target=c --entry telegram_view_test:main --exe -o build/telegram-view-test tests/telegram_view_test.zi
|
||||
build/telegram-view-test/telegram_view_test
|
||||
|
||||
test: telegram-view-test
|
||||
@@ -46,6 +46,23 @@ one Dew is 1,000,000 units. Display both from the catalog and render the title
|
||||
as text. The issuer configures an explicit XTR price for each enabled canonical
|
||||
pack. Telegram requires XTR for digital purchases in Mini Apps. [Telegram Stars payments](https://core.telegram.org/bots/payments-stars)
|
||||
|
||||
## Shared Profile authorization review
|
||||
|
||||
Hosts can offer Stars consent from the existing `entity.telegram` panel. Include
|
||||
the localized `stars_disclosure` (up to 2048 decoded UTF-8 bytes) and
|
||||
`approve_stars` button label (up to 255 bytes). Supply both with the complete
|
||||
`review` (up to 8192 bytes), `owner` (64 lowercase hex digits), and `request_id`
|
||||
(32 lowercase hex digits) for the same approval request. Use a Stars label
|
||||
distinct from the ordinary `approve` label. Set `busy: true` while the host is
|
||||
processing a request.
|
||||
|
||||
The Stars action becomes available after rendering the matching review. A click
|
||||
sends `{"operation":"approve_stars","owner":"…","request_id":"…"}` through
|
||||
`entity.telegram`. The host must recheck the active owner, pending request, and
|
||||
authorized terms before signing a Stars-enabled grant. Ordinary `approve` still
|
||||
sends the base authorization action. Hosts can omit the two additions to use
|
||||
the base approval flow.
|
||||
|
||||
## Invoice and settlement
|
||||
|
||||
| Method and path | Request | Successful response |
|
||||
|
||||
@@ -153,7 +153,8 @@ AchievementCommand :: (command: string) -> bool {
|
||||
return true
|
||||
}
|
||||
|
||||
AchievementWrappedHeight :: (value: string, width: float32, font: s32, scale: float32) -> float32 {
|
||||
AchievementWrappedHeight :: (value: string, width: float32, font: s32, scale: float32,
|
||||
line_breaks: s32 = 0) -> float32 {
|
||||
request: Vec(u8)
|
||||
BuilderPrint(*request, "{\"width\":%,\"font\":%,\"scale\":%,\"text\":", cast(s32)width, font, scale)
|
||||
EntityQuote(*request, value)
|
||||
@@ -169,7 +170,7 @@ AchievementWrappedHeight :: (value: string, width: float32, font: s32, scale: fl
|
||||
// standard Text still owns wrapping and all glyph rendering.
|
||||
columns := cast(s32)(width / (cast(float32)font * 2.0))
|
||||
if columns < 1 { columns = 1 }
|
||||
lines := (cast(s32)value.count + columns - 1) / columns + 1
|
||||
lines := (cast(s32)value.count + columns - 1) / columns + 1 + line_breaks
|
||||
return cast(float32)(lines * (font + cast(s32)(4.0 * scale)))
|
||||
|
||||
}
|
||||
|
||||
+139
-18
@@ -7,6 +7,7 @@ Scroll :: #import "kryon/scroll";
|
||||
#import "kryon/geometry"
|
||||
#import "achievement_view"
|
||||
#import "model"
|
||||
#import "std/json_document"
|
||||
#import "std/json_scan"
|
||||
#import "std/text_buffer"
|
||||
#import "std/c_string"
|
||||
@@ -14,15 +15,20 @@ Scroll :: #import "kryon/scroll";
|
||||
telegram_open: bool;
|
||||
telegram_scroll: s32;
|
||||
telegram_page: [16385]u8;
|
||||
telegram_stars: TelegramStarsReview;
|
||||
telegram_stars_key: u64 = 77014;
|
||||
telegram_stars_rendered: bool;
|
||||
|
||||
TelegramViewRoute :: (route: string) -> bool {
|
||||
if route != "telegram" || !AppSupports("entity.telegram") { return false }
|
||||
telegram_open = true
|
||||
telegram_scroll = 0
|
||||
TelegramClearStarsReview()
|
||||
return true
|
||||
}
|
||||
TelegramViewCommand :: (command: string) -> bool {
|
||||
if command == "reload" { telegram_open = false; telegram_page = .{}; return false }
|
||||
if command == "back" && telegram_open { telegram_open = false; AppReply("handled"); return true }
|
||||
if command == "reload" { telegram_open = false; telegram_page = .{}; TelegramClearStarsReview(); return false }
|
||||
if command == "back" && telegram_open { telegram_open = false; TelegramClearStarsReview(); AppReply("handled"); return true }
|
||||
return false
|
||||
}
|
||||
TelegramViewAction :: (operation: string) {
|
||||
@@ -31,20 +37,16 @@ TelegramViewAction :: (operation: string) {
|
||||
request_id: [33]u8
|
||||
unused ReadStringText(page, FieldAt(page, 0, "owner"), owner[:])
|
||||
unused ReadStringText(page, FieldAt(page, 0, "request_id"), request_id[:])
|
||||
out: Vec(u8)
|
||||
BuilderPrint(*out, "{\"operation\":\"%\",\"owner\":", operation)
|
||||
EntityQuote(*out, TextUntilNul(owner[:]))
|
||||
BuilderPrint(*out, ",\"request_id\":")
|
||||
EntityQuote(*out, TextUntilNul(request_id[:]))
|
||||
BuilderPrint(*out, "}")
|
||||
query := BuilderFinish(out)
|
||||
if AppService("entity.telegram", query) == "account" { AppReply("account") }
|
||||
AchievementRelease(query)
|
||||
TelegramClearStarsReview()
|
||||
TelegramSendAction(operation, TextUntilNul(owner[:]), TextUntilNul(request_id[:]))
|
||||
}
|
||||
TelegramViewFrame :: (navigation: bool) -> bool {
|
||||
if !telegram_open { return false }
|
||||
response := AppService("entity.telegram", "")
|
||||
if response.count < 2 || response.count >= telegram_page.count { return true }
|
||||
if response.count < 2 || response.count >= telegram_page.count {
|
||||
TelegramClearStarsReview()
|
||||
return true
|
||||
}
|
||||
unused CopyCString(response, telegram_page[:])
|
||||
document := TextUntilNul(telegram_page[:])
|
||||
status: [4097]u8
|
||||
@@ -70,19 +72,38 @@ TelegramViewFrame :: (navigation: bool) -> bool {
|
||||
width := area.width - 40.0 * scale
|
||||
if width > 680.0 * scale { width = 680.0 * scale }
|
||||
font := cast(s32)(16.0 * scale)
|
||||
stars: TelegramStarsReview
|
||||
stars_valid := width > 0.0 && area.height > 0.0 && font > 0 && document.count == response.count &&
|
||||
FieldAt(document, 0, "approve_stars") >= 0 && TelegramReadStarsReview(document, TextUntilNul(approve[:]), *stars)
|
||||
if !stars_valid { TelegramClearStarsReview() }
|
||||
review_text := ifx stars_valid then TextUntilNul(stars.review[:]) else TextUntilNul(review[:])
|
||||
disclosure := TextUntilNul(stars.disclosure[:])
|
||||
status_height := AchievementWrappedHeight(TextUntilNul(status[:]), width, font, scale) + 16.0 * scale
|
||||
review_height: float32 = ifx review[0] == 0 then 0.0 else AchievementWrappedHeight(TextUntilNul(review[:]), width, font, scale) + 16.0 * scale
|
||||
review_height: float32 = 0.0
|
||||
if review_text != "" {
|
||||
review_height = ifx stars_valid then TelegramReviewHeight(review_text, width, font, scale) else AchievementWrappedHeight(review_text, width, font, scale) + 16.0 * scale
|
||||
}
|
||||
authorization_height: float32 = ifx authorization[0] == 0 then 0.0 else AchievementWrappedHeight(TextUntilNul(authorization[:]), width, font, scale) + 16.0 * scale
|
||||
stars_height: float32 = ifx stars_valid then TelegramReviewHeight(disclosure, width, font, scale) else 0.0
|
||||
stars_extent: float32 = ifx stars_valid then stars_height + 60.0 * scale else 0.0
|
||||
scroll := Scroll.Draw(session, Scroll.Props.{.key = cast(u64)77000, .bounds = area,
|
||||
.content_height = cast(s32)(status_height + review_height + authorization_height + 380.0 * scale), .scroll_offset = telegram_scroll, .scale = scale})
|
||||
.content_height = cast(s32)(status_height + review_height + authorization_height + stars_extent + 380.0 * scale), .scroll_offset = telegram_scroll, .scale = scale})
|
||||
telegram_scroll = scroll.scroll_offset
|
||||
if !scroll.opened { return true }
|
||||
if !scroll.opened { TelegramClearStarsReview(); return true }
|
||||
if stars_valid && !TelegramSameStarsReview(*stars, *telegram_stars) {
|
||||
telegram_stars = stars
|
||||
telegram_stars_key += 1
|
||||
telegram_stars_rendered = false
|
||||
}
|
||||
x := scroll.content.x + (scroll.content.width - width) * 0.5
|
||||
y := scroll.content.y + 16.0 * scale
|
||||
if navigation {
|
||||
back := AppLocale("entity.back")
|
||||
if back == "" || back == "entity.back" { back = "Back" }
|
||||
if Button.Draw(session, Button.Props.{.id = 77001, .label = back, .bounds = Rectangle.{x, y, width, 44.0 * scale}}) != 0 { telegram_open = false }
|
||||
if Button.Draw(session, Button.Props.{.id = 77001, .label = back, .bounds = Rectangle.{x, y, width, 44.0 * scale}}) != 0 {
|
||||
telegram_open = false
|
||||
TelegramClearStarsReview()
|
||||
}
|
||||
y += 56.0 * scale
|
||||
}
|
||||
AchievementText(session, 77002, "Telegram", Rectangle.{x, y, width, 40.0 * scale}, cast(s32)(26.0 * scale))
|
||||
@@ -97,7 +118,7 @@ TelegramViewFrame :: (navigation: bool) -> bool {
|
||||
y += authorization_height
|
||||
}
|
||||
if review_height > 0.0 {
|
||||
AchievementText(session, 77006, TextUntilNul(review[:]), Rectangle.{x, y, width, review_height}, font)
|
||||
AchievementText(session, 77006, review_text, Rectangle.{x, y, width, review_height}, font)
|
||||
y += review_height
|
||||
}
|
||||
labels: [3]string = .[TextUntilNul(approve[:]), TextUntilNul(cancel[:]), TextUntilNul(disconnect[:])]
|
||||
@@ -108,6 +129,106 @@ TelegramViewFrame :: (navigation: bool) -> bool {
|
||||
.bounds = Rectangle.{x, y, width, 48.0 * scale}, .disabled = busy || (index == 0 && review_height <= 0.0)}) != 0 { TelegramViewAction(operations[index]) }
|
||||
y += 60.0 * scale
|
||||
}
|
||||
unused End(session)
|
||||
stars_pressed := false
|
||||
// A retained activation belongs to the key used by the previous frame.
|
||||
// Changing the review or leaving it invalidates that key before dispatch.
|
||||
stars_current := stars_valid && telegram_open && telegram_stars.owner[0] != 0
|
||||
if stars_current {
|
||||
AchievementText(session, 77013, disclosure, Rectangle.{x, y, width, stars_height}, font)
|
||||
y += stars_height
|
||||
ready := telegram_stars_rendered && !stars.busy
|
||||
stars_pressed = Button.Draw(session, Button.Props.{.id = 77014, .key = telegram_stars_key,
|
||||
.label = TextUntilNul(stars.label[:]), .bounds = Rectangle.{x, y, width, 48.0 * scale}, .disabled = !ready}) != 0 && ready
|
||||
}
|
||||
if End(session) && stars_current {
|
||||
telegram_stars_rendered = true
|
||||
if stars_pressed {
|
||||
TelegramClearStarsReview()
|
||||
TelegramSendAction("approve_stars", TextUntilNul(stars.owner[:]), TextUntilNul(stars.request_id[:]))
|
||||
}
|
||||
} else { TelegramClearStarsReview() }
|
||||
return true
|
||||
}
|
||||
|
||||
#scope_file
|
||||
|
||||
TelegramStarsReview :: struct {
|
||||
owner: [65]u8;
|
||||
request_id: [33]u8;
|
||||
review: [8193]u8;
|
||||
disclosure: [2049]u8;
|
||||
label: [256]u8;
|
||||
busy: bool;
|
||||
}
|
||||
|
||||
TelegramClearStarsReview :: () {
|
||||
telegram_stars.owner[0] = 0
|
||||
telegram_stars_rendered = false
|
||||
}
|
||||
|
||||
TelegramSameStarsReview :: (a: *TelegramStarsReview, b: *TelegramStarsReview) -> bool {
|
||||
return a.busy == b.busy && TextUntilNul(a.owner[:]) == TextUntilNul(b.owner[:]) &&
|
||||
TextUntilNul(a.request_id[:]) == TextUntilNul(b.request_id[:]) && TextUntilNul(a.review[:]) == TextUntilNul(b.review[:]) &&
|
||||
TextUntilNul(a.disclosure[:]) == TextUntilNul(b.disclosure[:]) && TextUntilNul(a.label[:]) == TextUntilNul(b.label[:])
|
||||
}
|
||||
|
||||
TelegramReviewHeight :: (text: string, width: float32, font: s32, scale: float32) -> float32 {
|
||||
line_breaks: s32 = 0
|
||||
for byte: text { if byte == 10 { line_breaks += 1 } }
|
||||
return AchievementWrappedHeight(text, width, font, scale, line_breaks) + 16.0 * scale
|
||||
}
|
||||
|
||||
TelegramReadStarsReview :: (page: string, base_label: string, review: *TelegramStarsReview) -> bool {
|
||||
doc: JsonDocument
|
||||
text: Vec(u8)
|
||||
defer { JsonReset(*doc); VecFree(doc.nodes); VecFree(text) }
|
||||
if !JsonRead(*doc, page) || JsonKindOf(*doc, doc.root) != .Object || JsonCount(*doc, doc.root) > 32 { return false }
|
||||
member := JsonFirst(*doc, doc.root)
|
||||
while member >= 0 {
|
||||
VecClear(text)
|
||||
if !JsonKeyInto(*doc, member, *text) || JsonMember(*doc, doc.root, TextView(VecSlice(text, 0, text.count))) != member { return false }
|
||||
member = JsonNext(*doc, member)
|
||||
}
|
||||
busy := JsonMember(*doc, doc.root, "busy")
|
||||
value, valid := JsonBool(*doc, busy)
|
||||
if busy >= 0 && !valid { return false }
|
||||
review.busy = value
|
||||
return TelegramReadReviewText(*doc, "owner", review.owner[:]) && TelegramReviewID(TextUntilNul(review.owner[:]), 64) &&
|
||||
TelegramReadReviewText(*doc, "request_id", review.request_id[:]) && TelegramReviewID(TextUntilNul(review.request_id[:]), 32) &&
|
||||
TelegramReadReviewText(*doc, "review", review.review[:]) &&
|
||||
TelegramReadReviewText(*doc, "stars_disclosure", review.disclosure[:]) &&
|
||||
TelegramReadReviewText(*doc, "approve_stars", review.label[:]) && TextUntilNul(review.label[:]) != base_label
|
||||
}
|
||||
|
||||
TelegramReadReviewText :: (doc: *JsonDocument, member: string, output: []u8) -> bool {
|
||||
bytes: Vec(u8)
|
||||
defer { VecFree(bytes) }
|
||||
if !JsonStringInto(doc, JsonMember(doc, doc.root, member), *bytes) || bytes.count >= output.count { return false }
|
||||
text := TextView(VecSlice(bytes, 0, bytes.count))
|
||||
has_text := false
|
||||
for byte: text {
|
||||
if (byte < 32 && byte != 9 && byte != 10 && byte != 13) || byte == 127 { return false }
|
||||
if byte > 32 { has_text = true }
|
||||
}
|
||||
return has_text && CopyCString(text, output)
|
||||
}
|
||||
|
||||
TelegramReviewID :: (text: string, length: s64) -> bool {
|
||||
if text.count != length { return false }
|
||||
for byte: text {
|
||||
if !((byte >= #char "0" && byte <= #char "9") || (byte >= #char "a" && byte <= #char "f")) { return false }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
TelegramSendAction :: (operation: string, owner: string, request_id: string) {
|
||||
out: Vec(u8)
|
||||
BuilderPrint(*out, "{\"operation\":\"%\",\"owner\":", operation)
|
||||
EntityQuote(*out, owner)
|
||||
BuilderPrint(*out, ",\"request_id\":")
|
||||
EntityQuote(*out, request_id)
|
||||
BuilderPrint(*out, "}")
|
||||
query := BuilderFinish(out)
|
||||
if AppService("entity.telegram", query) == "account" { AppReply("account") }
|
||||
AchievementRelease(query)
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
// Exercise the shipped Profile bundle and real retained button input without a display.
|
||||
#import "model"
|
||||
#import "kryon/app_context_host"
|
||||
#import "kryon/app_protocol"
|
||||
#import "kryon/hosted_values"
|
||||
#import "kryon/hosted_app"
|
||||
#import "kryon/widget_host"
|
||||
#import "kryon/session"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/pixmap"
|
||||
#import "kryon/tree"
|
||||
#import "kryon/tree_draw"
|
||||
#import "kryon/tree_input"
|
||||
#import "std/bundle_host"
|
||||
#import "std/byte_text_linux"
|
||||
#import "std/c_string"
|
||||
#import "std/text_buffer"
|
||||
#import "std/file"
|
||||
#import "std/vec"
|
||||
|
||||
OwnerA :: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
OwnerB :: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
RequestA :: "0123456789abcdef0123456789abcdef"
|
||||
RequestB :: "fedcba9876543210fedcba9876543210"
|
||||
Review :: "App access\nRead Lumi balance"
|
||||
MultiLineReview :: "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np"
|
||||
StarsLabel :: "Approve with Telegram Stars"
|
||||
StarsFields :: ",\"approve_stars\":\"Approve with Telegram Stars\",\"stars_disclosure\":\"Read Dew balance and buy Dew with Stars\""
|
||||
BaseLabel :: "Approve app access"
|
||||
|
||||
app: AppContext;
|
||||
profile: string;
|
||||
page: string;
|
||||
event: [256]u8;
|
||||
event_count: s32;
|
||||
failures: s32;
|
||||
|
||||
Allows :: (context: *void, name: string) -> bool {
|
||||
return name == "entity.telegram" || name == "AppServiceHost" || name == "AppLocaleHost" ||
|
||||
name == "ReadStoreHost" || name == "WriteStoreHost" || name == "ClipboardCopyHost"
|
||||
}
|
||||
|
||||
HostText :: (value: string) -> HostValue {
|
||||
return HostValue.{.kind = cast(s32)HostValueKind.HostString,
|
||||
.type_name = HostTextData("string"), .data = HostTextData(value), .length = cast(usize)value.count}
|
||||
}
|
||||
|
||||
Services :: (context: *void, module: *u8, function: *u8,
|
||||
args: *HostValue, count: s32, result: *HostValue) -> s32 {
|
||||
name := TextFromCString(function)
|
||||
if name == "AppServiceHost" && count == 2 {
|
||||
result.* = HostText("")
|
||||
if AppArgumentText(args[0]) != "entity.telegram" { return 1 }
|
||||
request := AppArgumentText(args[1])
|
||||
if request == "" { result.* = HostText(page); return 1 }
|
||||
unused CopyCString(request, event[:])
|
||||
event_count += 1
|
||||
return 1
|
||||
}
|
||||
if name == "AppLocaleHost" && count == 1 { result.* = HostText(AppArgumentText(args[0])); return 1 }
|
||||
if name == "WriteStoreHost" && count == 2 { result.* = HostScalar("bool", 1); return 1 }
|
||||
if name == "ReadStoreHost" && count == 2 && AppArgumentText(args[0]) == "entity.json" {
|
||||
output := args[1]
|
||||
if output.elements == null || output.length <= cast(usize)profile.count { return 0 }
|
||||
for index: 0..profile.count {
|
||||
byte := ifx index < profile.count then profile[index] else cast(u8)0
|
||||
output.elements[index].bits = cast(u64)byte
|
||||
output.elements[index].integer = cast(s64)byte
|
||||
}
|
||||
result.* = HostScalar("s32", profile.count)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
Expect :: (ok: bool, message: string) {
|
||||
if !ok { print("FAIL: %\n", message); failures += 1 }
|
||||
}
|
||||
|
||||
Assets :: (path: string) -> bool { return true }
|
||||
|
||||
Frame :: () {
|
||||
unused BeginFrame(app.session, 1, app.bounds)
|
||||
WidgetHostBegin(app.session, Assets)
|
||||
Expect(AppContextRun(*app, APP_FRAME), "production Profile frame runs")
|
||||
WidgetHostEnd()
|
||||
unused EndFrame(app.session)
|
||||
}
|
||||
|
||||
Find :: (label: string) -> s32 {
|
||||
for index: cast(s32)0..TreeCount(app.session) - 1 {
|
||||
if TreeNodeAt(app.session, index).semantic_label == label { return index }
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
Enabled :: (label: string) -> bool {
|
||||
node := Find(label)
|
||||
return node >= 0 && !TreeNodeAt(app.session, node).disabled
|
||||
}
|
||||
|
||||
Activate :: (label: string) -> bool {
|
||||
node := Find(label)
|
||||
return node >= 0 && TreeActivateAt(app.session, node)
|
||||
}
|
||||
|
||||
SetPage :: (owner: string, request_id: string, review: string, stars: string = StarsFields, busy: string = "false") {
|
||||
EntityFree(page)
|
||||
document: Vec(u8)
|
||||
BuilderPrint(*document, "{\"owner\":\"%\",\"request_id\":\"%\",\"status\":\"Authorization\",\"primary\":\"Connect\",\"approve\":\"%\",\"busy\":%,\"review\":", owner, request_id, BaseLabel, busy)
|
||||
EntityQuote(*document, review)
|
||||
BuilderPrint(*document, "%}", stars)
|
||||
page = BuilderFinish(document)
|
||||
}
|
||||
|
||||
EventMatches :: (operation: string, owner: string, request_id: string) -> bool {
|
||||
out: Vec(u8)
|
||||
BuilderPrint(*out, "{\"operation\":\"%\",\"owner\":\"%\",\"request_id\":\"%\"}", operation, owner, request_id)
|
||||
expected := BuilderFinish(out)
|
||||
defer { EntityFree(expected) }
|
||||
return TextUntilNul(event[:]) == expected
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
state := EntityDefault()
|
||||
state.controls = 0
|
||||
EntityAddExtension(*state, "telegram", "Review Telegram authorization")
|
||||
profile = EntityEncode(state)
|
||||
defer { EntityFree(profile); EntityFree(page) }
|
||||
bytes, ok := ReadEntireFile("build/entity.zx")
|
||||
if !ok { return 1 }
|
||||
defer { EntityFree(bytes) }
|
||||
app.session = SessionOpen()
|
||||
defer { unused SessionClose(app.session) }
|
||||
app.bounds = Rectangle.{0.0, 0.0, 480.0, 840.0}
|
||||
app.scale = 1.0
|
||||
app.expected_id = "entity"
|
||||
app.allows = Allows
|
||||
app.services = Services
|
||||
app.widgets = WidgetHostCall
|
||||
if !AppContextOpen(*app, bytes) { return 2 }
|
||||
defer { HostedAppClose(*app.app) }
|
||||
|
||||
SetPage(OwnerA, RequestA, Review, "")
|
||||
Frame()
|
||||
Expect(Activate("Review Telegram authorization"), "the shared Profile extension routes to Telegram")
|
||||
Frame()
|
||||
Frame()
|
||||
Expect(Find(StarsLabel) < 0 && Activate(BaseLabel), "legacy hosts expose only ordinary approval")
|
||||
Frame()
|
||||
Expect(event_count == 1 && EventMatches("approve", OwnerA, RequestA), "ordinary approval keeps the base event and scope")
|
||||
|
||||
SetPage(OwnerA, RequestA, Review)
|
||||
Frame()
|
||||
Expect(Find(Review) >= 0 && Find("Read Dew balance and buy Dew with Stars") >= 0, "both review and app disclosure render")
|
||||
Expect(Find(StarsLabel) >= 0 && !Activate(StarsLabel), "the first Stars frame is disabled")
|
||||
Frame()
|
||||
Expect(Activate(StarsLabel), "Stars consent is available after rendering the review")
|
||||
Frame()
|
||||
Expect(event_count == 2 && EventMatches("approve_stars", OwnerA, RequestA), "Stars emits a separate owner/request event")
|
||||
|
||||
Frame()
|
||||
Frame()
|
||||
Expect(Activate(StarsLabel), "queue an activation for the displayed owner")
|
||||
SetPage(OwnerB, RequestA, Review)
|
||||
Frame()
|
||||
Expect(event_count == 2 && !Enabled(StarsLabel), "an old owner's activation cannot approve the new owner")
|
||||
Frame()
|
||||
Expect(Activate(StarsLabel), "queue an activation for the displayed request")
|
||||
SetPage(OwnerB, RequestB, Review)
|
||||
Frame()
|
||||
Expect(event_count == 2 && !Enabled(StarsLabel), "an old request cannot approve a new request under the same owner")
|
||||
Frame()
|
||||
Expect(Activate(StarsLabel), "queue an activation before the terms change")
|
||||
SetPage(OwnerB, RequestB, "Different access terms")
|
||||
Frame()
|
||||
Expect(event_count == 2 && !Enabled(StarsLabel), "changed review text invalidates its retained activation")
|
||||
|
||||
Frame()
|
||||
Expect(Activate(StarsLabel), "queue an activation before the host becomes busy")
|
||||
SetPage(OwnerB, RequestB, Review, StarsFields, "true")
|
||||
Frame()
|
||||
Expect(event_count == 2 && Find(StarsLabel) >= 0 && !Activate(StarsLabel), "busy review suppresses both queued and new activations")
|
||||
SetPage(OwnerB, RequestB, Review)
|
||||
Frame()
|
||||
Expect(!Enabled(StarsLabel), "a busy review must render again after becoming idle")
|
||||
Frame()
|
||||
Expect(Activate(StarsLabel), "queue an activation before restarting the route")
|
||||
app.command = "back"
|
||||
Expect(AppContextRun(*app, APP_COMMAND), "close the Telegram review")
|
||||
Frame()
|
||||
Expect(Activate("Review Telegram authorization"), "open the same request again")
|
||||
Frame()
|
||||
Frame()
|
||||
Expect(event_count == 2 && Find(StarsLabel) >= 0 && !Enabled(StarsLabel), "closing and reopening clears retained consent")
|
||||
|
||||
SetPage(OwnerB, RequestB, "")
|
||||
Frame()
|
||||
Expect(Find(StarsLabel) < 0, "empty review hides Stars")
|
||||
SetPage(OwnerB, RequestB, Review, ",\"approve_stars\":\"Approve with Telegram Stars\"")
|
||||
Frame()
|
||||
Expect(Find(StarsLabel) < 0, "missing disclosure hides Stars")
|
||||
SetPage(OwnerB, "short", Review)
|
||||
Frame()
|
||||
Expect(Find(StarsLabel) < 0, "malformed request scope hides Stars")
|
||||
SetPage(OwnerB, RequestB, Review, ",\"approve_stars\":\"Approve with Telegram Stars\",\"stars_disclosure\":\"terms\\u0000hidden\"")
|
||||
Frame()
|
||||
Expect(Find(StarsLabel) < 0, "truncated disclosure cannot be approved")
|
||||
SetPage(OwnerB, RequestB, Review, ",\"approve_stars\":\"Approve with Telegram Stars\",\"stars_disclosure\":\"terms\",\"own\\u0065r\":\"duplicate\"")
|
||||
Frame()
|
||||
Expect(Find(StarsLabel) < 0 && event_count == 2, "ambiguous duplicate owner hides Stars")
|
||||
|
||||
SetPage(OwnerB, RequestB, MultiLineReview)
|
||||
Frame()
|
||||
review_node := Find(MultiLineReview)
|
||||
Expect(review_node >= 0 && TreeNodeAt(app.session, review_node).bounds.height >= 256.0,
|
||||
"the fallback layout reserves space for every review line")
|
||||
|
||||
SetPage(OwnerB, RequestB, Review)
|
||||
Frame()
|
||||
Frame()
|
||||
Expect(Activate(StarsLabel), "fresh matching review is usable")
|
||||
Frame()
|
||||
Expect(event_count == 3 && EventMatches("approve_stars", OwnerB, RequestB), "only fresh consent sends the new scope")
|
||||
if failures == 0 { print("Telegram Profile consent local test passed\n") }
|
||||
return failures
|
||||
}
|
||||
+11
-11
@@ -54,6 +54,15 @@
|
||||
"source": true,
|
||||
"url": "https://github.com/webmproject/libwebp.git"
|
||||
},
|
||||
{
|
||||
"commit": "08062f44b69500b27e0bf603fa9b04fa748277ef",
|
||||
"dependencies": {"crypto": "pc23fbf455e97614d", "oqs": "p7098ac9cd92f7e5f"},
|
||||
"dependency_refs": {"crypto": "master", "oqs": "master"},
|
||||
"id": "p3e75fb71e59471c7",
|
||||
"name": "mesh_client",
|
||||
"ref": "08062f44b69500b27e0bf603fa9b04fa748277ef",
|
||||
"url": "https://git.waozi.xyz/ziranlang/mesh-client.git"
|
||||
},
|
||||
{
|
||||
"commit": "f5f186bb13569ef13338f81366ff63fb9b9282f6",
|
||||
"dependencies": {"av1": "p5d7d12505a42f7b3", "dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db"},
|
||||
@@ -116,15 +125,6 @@
|
||||
"source": true,
|
||||
"url": "https://aomedia.googlesource.com/aom"
|
||||
},
|
||||
{
|
||||
"commit": "c1ac6095d01bcfdd4c5ae49c4636aaf9a0303449",
|
||||
"dependencies": {"crypto": "pc23fbf455e97614d", "oqs": "p7098ac9cd92f7e5f"},
|
||||
"dependency_refs": {"crypto": "master", "oqs": "master"},
|
||||
"id": "p8204ae87a845c1c3",
|
||||
"name": "mesh_client",
|
||||
"ref": "c1ac6095d01bcfdd4c5ae49c4636aaf9a0303449",
|
||||
"url": "https://github.com/ziranlang/mesh-client.git"
|
||||
},
|
||||
{
|
||||
"commit": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf",
|
||||
"dependencies": {},
|
||||
@@ -189,8 +189,8 @@
|
||||
}
|
||||
],
|
||||
"root": {
|
||||
"dependencies": {"curl": "p8da229d15597ab5c", "kryon": "pe02c713a1b0b858a", "mesh_client": "p8204ae87a845c1c3", "monocypher": "p966a7198f42a3ddc", "oqs": "p7098ac9cd92f7e5f", "qrcode": "p0dfa70137405b096", "zlib": "p82dbc05081cd4d96"},
|
||||
"dependency_refs": {"curl": "19b299005fbe2d895f4ad525cfdae62a2220c3ea", "kryon": "452813114e40e2385485bf5f6bc555cb90371d16", "mesh_client": "c1ac6095d01bcfdd4c5ae49c4636aaf9a0303449", "monocypher": "master", "oqs": "master", "qrcode": "master", "zlib": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf"},
|
||||
"dependencies": {"curl": "p8da229d15597ab5c", "kryon": "pe02c713a1b0b858a", "mesh_client": "p3e75fb71e59471c7", "monocypher": "p966a7198f42a3ddc", "oqs": "p7098ac9cd92f7e5f", "qrcode": "p0dfa70137405b096", "zlib": "p82dbc05081cd4d96"},
|
||||
"dependency_refs": {"curl": "19b299005fbe2d895f4ad525cfdae62a2220c3ea", "kryon": "452813114e40e2385485bf5f6bc555cb90371d16", "mesh_client": "08062f44b69500b27e0bf603fa9b04fa748277ef", "monocypher": "master", "oqs": "master", "qrcode": "master", "zlib": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf"},
|
||||
"name": "Entity"
|
||||
},
|
||||
"toolchain": {
|
||||
|
||||
+2
-2
@@ -64,8 +64,8 @@ git = "https://github.com/ziranlang/qrcode.git"
|
||||
ref = "master"
|
||||
|
||||
[dependencies.mesh_client]
|
||||
git = "https://github.com/ziranlang/mesh-client.git"
|
||||
ref = "c1ac6095d01bcfdd4c5ae49c4636aaf9a0303449"
|
||||
git = "https://git.waozi.xyz/ziranlang/mesh-client.git"
|
||||
ref = "08062f44b69500b27e0bf603fa9b04fa748277ef"
|
||||
|
||||
[dependencies.oqs]
|
||||
git = "https://github.com/ziranlang/oqs.git"
|
||||
|
||||
Reference in new issue
Block a user