Git Product home page Git Product logo

ui's Introduction

Fedimint UI Projects

268047037-d648b83d-b676-44fe-98be-07f84f4d7465 268046987-3b480175-7f5e-4235-bed3-cab5c092c2e5

What's Inside

This project includes the following apps / packages:

Apps

  • guardian-ui: Web app experience for setting up and administering fedimints. This is used by the Fedimint guardians
  • gateway-ui: Web app experience for managing Fedimint gateways. This is used by Gateway administrators

Packages

  • ui: Shared React UI component library for building Fedimint UI experiences
  • utils: Shared utility functions like the current translation framework on Fedimint UI apps
  • eslint-config: Shared eslint configurations (includes eslint-plugin-react and eslint-config-prettier)
  • tsconfig: Shared tsconfig.jsons used throughout Fedimint UI apps

Testing

For detailed testing instructions, please refer to the testing.md file in this repository. It contains comprehensive information on how to set up and run local tests for the Fedimint UI projects.

Version Policy

Fedimint UI releases use semantic versioning (major.minor.patch)

  • Major and minor versions of fedimint/ui are made to be compatible major and minor versions of fedimint/fedimint
    • For instance, any 1.1.x release of the UI should work with any 1.1.x release of Fedimint
  • Patch versions of fedimint/ui are made independent of fedimint/fedimint
    • For instance, you could run fedimint/[email protected] against fedimint/[email protected] and vice versa
    • It is always recommended to run the latest patch release of any version as they may contain important fixes
  • The master branch of fedimint/ui attempts to track master of fedimint/fedimint
    • This tracking is a best effort, and sometimes the two will fall out of sync. Feel free to open an issue if you notice an incompatibility.
    • It is not recommended to run master in production as breaking changes may occur without warning

Running a Release

Build and Run from Source

Guardian UI

git clone [email protected]:fedimint/ui.git fedimint-ui
cd fedimint-ui/apps/guardian-ui
yarn install
PORT=3000 REACT_APP_FM_CONFIG_API="[app-address-here]" yarn build && yarn start

Replace PORT with a port of your choice, and REACT_APP_FM_CONFIG_API with the socket address of your deployed fedimintd server.

NOTE: The Guardian UI references a config.json specified at the root of where the UI is served from. The Dockerfile writes this file from ENV VARs but a static site deployment will want to customize this file.

Gateway UI

git clone [email protected]:fedimint/ui.git fedimint-ui
cd fedimint-ui/apps/gateway-ui
yarn install
PORT=3000 REACT_APP_FM_GATEWAY_API="[app-address-here]" REACT_APP_FM_GATEWAY_PASSWORD="[password-here]" yarn build && yarn start

Replace PORT with a port of your choice, REACT_APP_FM_GATEWAY_API with the http address, and REACT_APP_FM_GATEWAY_PASSWORD with the password of your deployed gatewayd server.

Run with Docker

Note: Docker images are only built for linux/amd64. Your docker will need to support virtualization to run on other platforms.

Guardian UI

The guardian UI container is available at fedimintui/guardian-ui

docker pull fedimintui/guardian-ui:0.1.0
docker run \
  --platform linux/amd64 \
  --env "REACT_APP_FM_CONFIG_API='[app-address-here]'" \
  -p 3000:3000 \
  fedimintui/guardian-ui:0.1.0

Replace -p 3000:3000 with a port of your choice, and REACT_APP_FM_CONFIG_API with the socket address of your deployed fedimintd server.

Gateway UI

The gateway UI container is available at fedimintui/gateway-ui

docker pull fedimintui/gateway-ui:0.1.0
docker run \
  --platform linux/amd64 \
  --env "REACT_APP_FM_GATEWAY_API='[app-address-here]'" \
  --env "REACT_APP_FM_GATEWAY_PASSWORD='[password-here]'" \
  -p 3000:3000 \
  fedimintui/gateway-ui:0.1.0

Replace -p 3000:3000 with a port of your choice, REACT_APP_FM_GATEWAY_API with the http address, and REACT_APP_FM_GATEWAY_PASSWORD with the password of your deployed gatewayd server.

Development

The development password for the gateway is theresnosecondbest. The development password for the guardians when using the nix-gateway or docker development environments is pass.

Option 1 - Running with Nix (preferred)

  1. Install Nix
    curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
  2. Add experimental-features = nix-command flakes to your /etc/nix/nix.conf file
  3. In terminal cd to the fedimint-ui repo root directory
  4. Enter the following command to start Nix development environment
    nix develop
  5. Run yarn nix-gateway or yarn nix-guardian Note: nix-gateway preconfigures the federation so you don't have to go through federation setup. nix-guardian starts separate guardian nodes that are connected into the federation when you run through the federation setup process.

Gateway UI

yarn nix-gateway

nix-gateway spins up these instances

instance url
gateway-ui http://127.0.0.1:3004/
guardian-ui http://127.0.0.1:3000/

Guardian UI

yarn nix-guardian

nix-guardian spins up these instances

instance url
guardian-ui-1 http://127.0.0.1:3000/
guardian-ui-2 http://127.0.0.1:3001/
guardian-ui-3 http://127.0.0.1:3002/
guardian-ui-4 http://127.0.0.1:3003/

Option 2 - Running with docker

  1. Install mprocs
  2. In terminal cd to the fedimint-ui repo root directory and run yarn install
  3. Run yarn docker

After running this command, you'll be present with the mprocs display. Along the left side are the list of processes currently available by mprocs. Along the bottom are hotkeys for navigating/interacting with mprocs. The main pane shows the shell output for the currently selected process.

The start-servers process shows combined logging for fedimintd, bitcoind, gatewayd, and lnd.

The stop-servers process can be used to stop all docker containers by hitting the s key to start the process. After doing so, you can return to the start-servers process and hit r to restart things.

The guardian-ui-1, guardian-ui-2, guardian-ui-3, guardian-ui-4 are instances of guardian-ui apps, each running on different ports and connected to a unique fedimintd server instance (running in the start-servers process).

The gateway-ui is an instance of gateway-ui app, connected to a gatewayd server instance (running in the start-servers process).

You can see more details by viewing the mprocs.yml file.

yarn mprocs spins up these instances

instance url
guardian-ui-1 http://127.0.0.1:3000/
guardian-ui-2 http://127.0.0.1:3001/
guardian-ui-3 http://127.0.0.1:3002/
guardian-ui-4 http://127.0.0.1:3003/
gateway-ui http://127.0.0.1:3004/

Option 3 - Running with Docker Compose and Yarn manually

From root repo directory:

  1. Ensure Docker and yarn/nodejs are installed.

  2. Run docker compose up - runs 4 fedimintd servers and a gatewayd server, plus associated services. See compose file for details

  3. yarn install (first time only)

  4. Run guardian-ui in development environment

      # first guardian
      PORT=3000 REACT_APP_FM_CONFIG_API="ws://127.0.0.1:18174" yarn dev:guardian-ui
      # second guardian
      PORT=3001 REACT_APP_FM_CONFIG_API="ws://127.0.0.1:18184" yarn dev:guardian-ui
      # third guardian
      PORT=3002 REACT_APP_FM_CONFIG_API="ws://127.0.0.1:18185" yarn dev:guardian-ui
      # fourth guardian
      PORT=3003 REACT_APP_FM_CONFIG_API="ws://127.0.0.1:18186" yarn dev:guardian-ui
  5. Run gateway-ui in development environment

      PORT=3004 REACT_APP_FM_GATEWAY_API="http://127.0.0.1:8175" REACT_APP_FM_GATEWAY_PASSWORD="theresnosecondbest" yarn dev:gateway-ui
  6. Run docker compose down when done. It might be worth deleting fm_*, directory from the repo. These are data directories mounted to Docker containers running fedmintd and are listed in .gitignore so are safe to remove.

Referencing Fedimint

The docker containers and devimint are for specific releases or commits of fedimint/fedimint. At present, the reference commit-hash is 819df733ce330e5ac77e32011f11e2b192a48948

Running with local Fedimint

If you would like to run the UIs against a particular version of fedimint, or using changes you have made locally to fedimint itself:

  1. Run cargo build in fedimint
  2. Run env DEVIMINT_BIN=$(realpath ../fedimint/target-nix/debug) yarn nix-guardian (assuming that you have ui and fedimint repos checked out in the same directory)

This will put binaries in fedimint/target-nix/debug at the front of your $PATH. Devimint will use these binaries instead of the ones installed via Nix.

Bumping referenced Fedimint

You can officially bump the referenced version of Fedimint using the following steps:

  1. Locate a desired hash from Fedimint

  2. Find and replace all instances of the current reference commit hash: c32bbe8ed8d95ae420b5879e92dda6ce48f5c914

  3. Run nix flake update at the root of the repo

  4. Restart your nix shell and validate the reference, then commit to complete bump

ui's People

Contributors

alexlwn123 avatar asifshiraz avatar benalleng avatar clarkmoody avatar dependabot[bot] avatar douglaz avatar dpc avatar elsirion avatar ethntuttle avatar garyray-k avatar getpsyched avatar gotlougit avatar igbopharaoh avatar isaacknjama avatar jkitman avatar jp1ac4 avatar justinmoon avatar kodylow avatar lone-starr avatar m1sterc001guy avatar maan2003 avatar maaxxs avatar mxz42 avatar ngutech21 avatar nicolals avatar okjodom avatar oleonardolima avatar wbobeirne avatar wilfredallyn avatar wiredhikari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ui's Issues

Authentication

Gateway webserver has authentication mechanics. For MVP, let's make the user to enter in this password instead of reading it from the environment. We'll need to make sure our MVP deployment scripts don't hardcode password so I can login to @okjodom's gateway :)

This may require fedimint changes but making the issue here so we get the end-to-end change.

Clarify UI handling of Setup API teardown

The config server shuts down as we finalize the configuration of the federation, currently, we just use a timer to wait for the transition to happen on the backend.

Yeah so the tricky thing is that once you start consensus, the config server shuts down and the regular api starts up, so it necessarily kills the socket. Ideally the config server would stay up long enough to respond to the rpc, indicating that it successfully started the server, and then shuts down. Worth an issue to improve the understandability of the code IMO.

I haven't spent enough time here to know if this is a reasonable timeout, but you are correct that it could hypothetically not be enough time. Unfortunately while I was working on this, this part of starting consensus would cause the backend to panic and crash. Might be worth some retries if we find it's prone to taking longer than this.

Originally posted by @wbobeirne in fedimint/fedimint#2360 (comment)

Guardian UI: Followers should watch for Leader to kick off DKG

We've run into a problem during some of our test setups that is easy to miss when you're developing solo, or setting up a 1 of 1 or 2 of 2 federation. Right now followers attempt to run DKG as soon as they approve the configuration. This is problematic if in e.g. a 2 of 3 federation, only the leader and follower 1 have joined. Follower 1 has not yet gotten any information about Follower 2 who will join shortly, so their DKG is incomplete. Once follower 2 attempts to run DKG, it'll fail because follower 1 will reject them.

We need to re-architect this so that followers go through the following flow:

  1. Follower pastes in leaders WS API URL
  2. Follower is presented with configuration from leader
  3. Follower hits approve on configuration
  4. Follower is presented with a screen that shows the status of all peers, and says that it's waiting for the leader to continue
  5. Follower sees that the leader's status has gone from SharingConfigGenParams to ReadyForConfigGen
  6. Follower transitions to the RunDKG screen and attempts to run DKG

Followers will not know how many guardians the leader intends for the federation to have, so they will not see the rows that indicate guardians that have not joined yet like the leader does.

type guard API methods

          We can type guard this using `'status' | 'set_password' | etc. etc.` so only certain strings can be used when making the call. It then also serves as a one stop point of reference for what RPC methods are supported. I believe that to be especially important if there's ever a time when we export this API as a package/library for use in other apps.

Originally posted by @EthnTuttle in #28 (comment)

Guardian and Gateway front end logic tests

We currently don't have unit tests on our Guardian UI components or logic. It seems the gateway UI is set up to use Jest but also doesn't have a lot of tests.

  • Settle on Jest or some other framework
  • Implement reusable testing patterns
  • Mock backend API calls for use in tests
  • Integration tests

Dockerfile.guardian-ui builds static assets at runtime

This is memory intensive. Failed on $6 digital ocean server. Eventually just embed the build/ directory when we create the container. This line:

CMD if [ ! -z "$REACT_APP_FM_CONFIG_API" ]; then yarn build;fi && serve -s apps/guardian-ui/build/

Local Storage invalid between federation clear and restart

I believe this should only impact dev environments since reproducing this is pretty far out there for an edge cases.

We default to local storage to hydrate SetupContext so if you restart/clear a federation in the middle of setup, the UI will see that there is already SetupContext state in local storage and hydrate the context. This will not match the actual state of the backend.

To reproduce:

  1. startup a local federation and continue through only part of the setup flow (stopping around verify guardians or some other intermediary step)
  2. Stop the fedimintd instances and clear the federation data.
  3. Restart fedimintd instances.
  4. Browse to Setup UI and refresh. You should see an error (The websocket is not opened) or similar.
  5. Check local storage cache and observe.
Screenshot 2023-06-12 at 7 58 19 AM

Gateway: Authentication

This requires backend change to fully work.

  • Create password screen
  • Authenticate later with ^^ password. This needs a design. Initial screen has options to "login" or "create password".
image

Dockerfiles are copying and building all apps unnecessarily

Each Dockerfile for each app should only copy and build the app in question. Running yarn install in the root directory installs all of the dependencies necessary for all packages and apps, and running yarn build in the root directory builds all apps. We should only copy and build the apps and packages that we need per app.

ConnectGuardians.tsx displays wrong value

        <CopyInput
          value={process.env.REACT_APP_FM_CONFIG_API || ''}
          size='lg'
          buttonLeftIcon={<Icon as={CopyIcon} />}
        />

We currently use the UI enviroment variable as the connection. However, this is incorrect and should be the FM_API_URL passed into the Coordinators config for fedimintd.

Move password storage to Context from API

Consolidate local storage keys to GuardianContext.tsx
Any other "state" should be handled here as well.

TBH I would like to get the password storage out of the API file altogether and move it in here. I'd much prefer that to just be a dumb class that takes all its inputs explicitly, rather than having some magic internal stuff going on.

Originally posted by @wbobeirne in fedimint/fedimint#2360 (comment)

Dynamic Graphing ability

From @justinmoon

One thing I would really like is a simple way to build little dashboard from a federation or gateway rockdb.

I would love to just have a jupyter notebook that I could easily write little scripts to measure things like:

  • graph of federation balances over time
  • lightning payment success rate over time
  • what percent of epochs does guardian N get into over time
  • average size of lightning payment over time
  • how frequently do lightning payments enter refund case

@elsirion mentioned promethius, too, but I'm not very familiar with it

What I'd like to avoid is really long development cycles where someone thinks of a graph while prototyping dashboard in figma, then it's implemented in admin API, then implemented in frontend, then deployed. The feedback loop there will be really slow that way.

Guardian: Reset Setup State

We should look to clear or reset SetupState persisted in local storage once the guardian UI transition from setup mode to Admin dashboard experience

CI builds preview deployments for UI-related pull requests

Could probably use something like Vercel to deploy the UI itself. But we'd need a backend to run against which would be a little tougher. But gateway UI has mock API implementation so for starters we could just used a mocked-out backend.

Number of Guardian Math on User Input

When inputting number of guardians, a user should be made aware of the 3*f+1=n where n is the total number of guardians, and f is the number of potential malicious guardians. Perhaps a link to the reasoning behind this can be included.

Internationalization of UI

Lay some framework for translating.

fwiw, I've seen json files work nicely for this.
i.e.

en.json

{
    "dashboard": {
        "title": "Fedimint Guardian Dashbaord"
    }
}

es.json

{
    "dashboard": {
        "title": "Panel de Guardian de Fedimint"
    }
}

It's then reference in typescript:

<Text>
    {i18n.dashboard.title}
</Text>

Improve fetching of own PeerId

/**
 * Given a map of peers, determine which one is you.
 */
export function getMyPeerId(peers: Record<string, Peer>) {
  // TODO: Find a better way to do this than using env var?
  const myApiUrl = new URL(process.env.REACT_APP_FM_CONFIG_API as string);
  return Object.entries(peers).find((peer) => {
    const apiUrl = new URL(peer[1].api_url);
    return myApiUrl.origin === apiUrl.origin;
  })?.[0];
}

Originally posted by @garyray-k in fedimint/fedimint#2360 (comment)

Guardian: Ability to restart setup state

If something goes wrong, we currently have no way to restart short of restarting fedimintd. Would be nice if we had a button + backend API to accomplish this.

Handle when a guardian starts consensus before sharing verification code

If you're setting up a federation, and one guardian starts consensus before sharing their verification code, you run into a problem where now they are no longer able to see their verification code, and all other guardians will be stuck on the VerifyGuardians step.

We should fix this in at least one of two ways, but probably both:

  1. Warn the user before proceeding that they must share their code, make them confirm they have
  2. Show the verification code somewhere after setup so they can rectify this if someone is stuck

Select bitcoin node to use in Guardian Setup

Enable a Guardian to input a node for their instance to use:

  • input node URL
  • show default node url from local config gen
  • confirm node connection w/ feedback
  • frontend ability to switch FM_BITCOIN_RPC_KIND

Docker-compose should provide 3 fedimintds

We recommend people setup with 2n + 1 fedimintd instances, and certain bugs (e.g. #83) only rear their ugly heads with 3 or more guardians in a federation. We should make this the default, and update our README instructions to reflect a 3 guardian setup.

Guardian: Implement no members or connected lightning nodes experience

When there's no members or a connected lightning node, guardian ui should show two message bars showing how to gateway operators can connect to the federation.

image

Tasks:

  • Implement message bar UX
  • Add appropriate message to show the guardian (clarify messaging and copy)
  • Detect state using guardian api and show / hide message bars

Ref:

Gracefully Handle Setup to Consensus API switch

In apps/guardian-ui/src/GuardianApi.ts the startConsensus method is flaky due to how we currently handle the API switch. The UI gets caught in a "setup" state but in reality, consensus has already started running. A refresh of the UI leads to "method not found" errors as it tries to determine where in the setup process is it.

I have tried a few approaches but none have yielded consistent results.

relevant Discord conversations:
https://discord.com/channels/990354215060795454/990354215878688860/1122657638388338819
https://discord.com/channels/990354215060795454/990354215878688860/1124158861876674571
https://discord.com/channels/990354215060795454/1105908596614627428/1121760876286976071

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.