penumbra-zone / web

Apache License 2.0
12 stars 15 forks source link

react wrapper for penumbra transport and client use #1293

Closed turbocrime closed 2 months ago

turbocrime commented 3 months ago

current status:

provider and hooks work.

but the provider is complex. in order to expose a single 'state' that represents not only connection status but also any actions taken internally, or by a caller, and to represent any pending status of various promises, plus failures, it's necessary to track a lot of state. this could be refactored into a useReducer state machine.

minifront edits are mostly for testing use of the provider and hooks, and will be reverted in favor of a larger PR.

check out the current readme. https://github.com/penumbra-zone/web/blob/1cb96c4e7487269296022b296fd4d115f264422c/packages/react/README.md

much testing code is still present, will clean up soon.

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: ac7fd33f05c0284cf40e18883d2bf05983e7f8e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages | Name | Type | | ------------------------------- | ----- | | @penumbra-zone/react | Major | | @penumbra-zone/transport-dom | Patch | | minifront | Patch | | @penumbra-zone/client | Patch | | @penumbra-zone/services | Patch | | @penumbra-zone/transport-chrome | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

turbocrime commented 2 months ago

among other edits, the README.md of the react package now contains a state flowchart of the provider.

https://github.com/penumbra-zone/web/blob/1cb96c4e7487269296022b296fd4d115f264422c/packages/react/README.md

this could ship but it might be better to refactor as FSM with useReducer.

much testing code is still present, will clean up soon.

stateDiagram-v2
    classDef GoodState fill:green
    classDef BadState fill:red
    state global_exists <<choice>>
    [*] --> global_exists: window[Symbol.for('penumbra')][validOrigin]
    global_exists --> Absent: undefined
    global_exists --> Injected: defined
    state manifest_present <<choice>>
    Injected --> manifest_present: fetch(injection.manifest)
    manifest_present --> Present: json
    state make_request <<choice>>
    Present --> make_request: makeApprovalRequest
    note left of Present
        Methods on the injection may
        be called after this point.
    end note
    Requested --> Pending
    make_request --> Requested: true
    make_request --> Pending: false
    Pending --> Connected
    note left of Connected
        Port is acquired and
        transports become active.
    end note
    Present --> Disconnected
    Requested --> Disconnected
    Pending --> Disconnected
    Connected --> Disconnected
    manifest_present --> Failed
    Requested --> Failed
    Pending --> Failed
    Disconnected --> Failed
    Absent:::BadState --> [*]
    Failed:::BadState --> [*]
    Disconnected --> [*]
    Connected:::GoodState --> [*]
turbocrime commented 2 months ago

closed to be rewritten after #1420