# Gora QR Review
1. `/lib/qr.hoon`
- truly a masterful construction
- style points:
* `ub-to-td` and `td-to-ub` could be one-liners, though they are well styled in tall form.
* in data-trajectory, rather than escaping bucs, you can give buc a name: `=* dis-buc $` if you'd like, perhaps aiding in legibility.
* `lvl` could probably be just ?(%7 %15 %25 %30) or ?(%l %m %q %h) if necessary, and I would probably have moved it into the library rather than separating it to it's own sur file (*PENDING FURTHER INVESTIGATION TO DETERMINE IF THIS IS RIGHT*).
2. `/app/gora/plead.hoon`
- really impressed you were able to get through this sail portion so effectively
- css styling, even though minimal, is cute (like the buttons)
3. `/sur/gora.hoon`
- we probably need to version `manage-gora-2` if we really want to release this, as some people would not have that poke, causing crashing (this is probably also fine as it's not passed in a subscription)
3. Method of Execution
- Generate a QR code that will be stored in state:
```hoon
%create-gora-qr
=^ cards state
(manage act)
=- [- cards +.state]
%- crip
"Success"
```
and (and this next section is tight, like it!)
> Note: I probably would have gone with qr-gora to meet the width scheme, although I grant that it's not perfect as is
```hoon
%create-gora-qr
=/ key id.gal
=/ pw (sham eny.bol)
=/ qr-data
=/ res "{<key>}|{<our.bol>}|{<pw>}"
(main:qr:qr res %l)
=/ val [pw now.bol hours-valid.gal qr-data]
[~ state(gora-qrs (~(add ja gora-qrs) key val))]
```
- Attempt to claim a Gora by QR code:
```hoon
%claim-gora-qr
=^ cards state
(manage act)
=- [- cards +.state]
%- crip
"""
❗アラート: Asynchronous Operation❗
❗あなたは待たなければなりません❗
❗Do the needful: wait❗
"""
```
and
```hoon
%claim-gora-qr
=/ code-tape (trip code.man)
=/ sep-idxs (fand ~['|'] code-tape)
?> =((lent sep-idxs) 2)
=/ gor-id=@uv
=/ gor-id-tape
(swag [0 (snag 0 sep-idxs)] code-tape)
`@uv`(scan (slag 2 gor-id-tape) viz:ag)
=/ host=ship
=/ length
(sub (sub (snag 1 sep-idxs) (snag 0 sep-idxs)) 1)
=/ host-tape
(swag [(add (snag 0 sep-idxs) 1) length] code-tape)
`ship`(scan (slag 1 host-tape) fed:ag)
=/ pw=@uvH
=/ pw-tape
(slag (add (snag 1 sep-idxs) 1) code-tape)
`@uvH`(scan (slag 2 pw-tape) viz:ag)
=/ wir=path
/claim/(scot %uv gor-id)/(scot %p host)
:-
:~
=- [%pass wir %agent [host %gora] %poke -]
=- [%gora-transact-2 !>(`transact-2`-)]
[%claim gor-id pw our.bol]
==
state
```
- Process requests to claim a Gora by QR code:
> Note: nicely commented, but please only lower case
```hoon
%claim
:: Does the gora even exist in our pita?
?. (~(has by pita) id.tan)
~& ["No gora found for id" id.tan]
[~ state]
:: What are the qrs for a pita?
=/ lora-qr=(list gora-qr)
(~(get ja gora-qrs) id.tan)
:: Fail if there are no qrs for that pita
?: =((lent lora-qr) 0)
~& ["No qrs found for id" id.tan]
[~ state]
:: Extract all qrs that aren't expired yet
=/ remaining-qrs=(list gora-qr)
%+ skip lora-qr
|= a=gora-qr
?: =(duration-hrs.a 0)
%.n :: Never elapse if duration 0
=/ dur=@dr
(mul duration-hrs.a ~h1)
=/ elapsed=@dr
(sub now.bowl made.a)
(lte dur elapsed)
=/ separated
%+ skid remaining-qrs
|= a=gora-qr
=(pw.tan pw.a)
:: If we don't have exactly 1 match, we fail
?. =((lent p.separated) 1)
~& ["There were exactly" (lent p.separated) "but we need 1"]
[~ state]
=. remaining-qrs
q.separated
=^ new-cards state
%- manage:hc
[%send-gora id.tan `(set ship)`(silt [from.tan ~])]
:- new-cards
%= state
gora-qrs
(~(put by gora-qrs) id.tan remaining-qrs)
==
```
4. User Experience:
- I create a Gora QR
- I specify infinite availability or a limited duration in hours
- I click Generate QR
- I get a success modal indicating that a QR was generated, it now appears on the screen
- I now see how many hours are left in the viability of that QR code and can generate additional codes, should I choose to.
- I can scan that QR code using the Request Gora (plead) menu from another instance of Gora
- My request is processed by the host