Giter VIP home page Giter VIP logo

apps's Introduction

Magmo Apps

Welcome to the Magmo mono-repo, home of several proof-of-concept applications built on our state channel protocols.

For more information

On our website you will find links to our whitepapers and contact information. Whether you simply want to try out our apps, or get involved more deeply we would love to hear your thoughts. Deployed versions of our games may be accessed with these links:

Getting Started

Setting up development environment and running a game application

You will need yarn installed (see here for instructions). After cloning the code,

  1. In the top directory, run yarn install.

  2. Run npx lerna bootstrap.

  3. Start ganache by running yarn ganache:start in one of the package directories.

  4. (In a new shell) Run the wallet via yarn start in the wallet package directory

  5. (In a new shell) Run a game (either RPS or TTT) via yarn start in the relevant package directory.

  6. Add MetaMask to your browser, and point it to localhost:3001 to view the application. You will need to import one of our (testnet-only) seed accounts into metamask to have funds to transact.

    1. Open the metamask browser extension
    2. Click on the account icon (circle in the top right)
    3. Select "Import"
    4. Paste in one of these secret keys.

You may visit the app in two different browsers in order to play against yourself. We use Redux DevTools to develop and test our apps.

Configuration

All default configuration values are located in the .env and .env.production files. These can be overridden by adding a .env.local or .env.production.local and specifying values there.

To run storybook

We use Storybook to view our react components during development. You can start Storybook by running:

yarn storybook

in the relevant package directory. This will fire up the Storybook panel inside a browser.

To create an optimized production build:

  1. Optionally override the TARGET_NETWORK by setting the value in your .env.production.local file. Otherwise the application will be built against the ropsten test network.

  2. Build the application:

    yarn run build
    

To deploy smart contracts

  1. Add test eth to your account for the deployment using an eth faucet: https://faucet.ropsten.be/ or https://faucet.metamask.io.
  2. Set TARGET_NETWORK in your .env.local file to the network you want to deploy to: either 'development', 'ropsten', 'kovan' or 'rinkeby'.
  3. Deploy the contracts to the network: yarn deployContracts Alternatively, simply run, e.g. TARGET_NETWORK=ropsten yarn deployContracts.

Running Tests specific to a certain app

From the relevant subdirectory...

  • To run application tests in watch mode:
yarn test:app
  • To run smart contract tests:
yarn test:contracts
  • To run all tests relating (before submitting a PR):
yarn test
  • To update dependencies:
npx lerna bootstrap
  • To add a dependency:
npx lerna add [dependency name] --scope=[target package]

This installs the latest version of the dependency to the target package (ttt, rps or wallet). Use --dev flag to add the new package to devDependencies instead of dependencies.

  • To update the version of a dependency:
yarn upgrade [package-name@version-number]

Documentation

We are working hard to produce documenation for our applications. In the interim, please see our Developer Handbook, which as some of the hints and tips for developing on ethereum that we have used to develop our apps. You will also find some information in the /notes/ subdirectory of each app.

Problems?

Frequently, problems can be sorted by one or more of the following steps:

  • Resetting your MetaMask account (i.e. deleting transaction history), or simply switching to a different network and back again.
  • Restarting ganache
  • Running npx lerna bootstrap if you changed any dependencies

Otherwise, please check issues, someone else may have had the same experience. You may find a solution -- if not, please add to or create an issue.

Contributing

We welcome contributions! If you want to contribute, you should be aware of the following conventions:

Prettier

Prettier is configured via .prettierrc. Tests will fail if code does not satisfy the rules specificied in .prettierrc. We suggest that you configure your editor to auto-format using prettier, or that you run it in a pre-commit git hook. You can also run yarn prettier:write.

Naming

  • Directories and files should be kebab-cased.
// ok
foo/bar/foo-bar/foo-bar.ts

// ok
foo/bar/foo-bar/foo-bar.tsx

// tslint error
foo/bar/foo-bar/fooBar.ts

// tslint error
foo/bar/foo-bar/FooBar.tsx

// no tslint error, but please avoid this
foo/bar/fooBar/foo-bar.svg

// no tslint error, but please avoid this
foo/bar/foo-bar/FooBar.svg

apps's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

apps's Issues

Get resign -> withdraw flow working

For Player A (Xs) and Player B (Os).

Possibly also for Player A (Os) and Player B (Xs).

Seems to work, so far -- only the withdrawal transactions don't have any funds in them.. this seems to be the case in rps, too.

Handle when both players attempt to close the game on-chain at the same time

Currently when a game concludes, either player can send the concludeGame to the adjudicator. On slower networks this means both players can end up trying call concludeGame. We need to handle the case where this happens gracefully. It might also be a good idea to proactively send the other wallet a message that a player is calling concludeGame and display a message to avoid a failed transaction.

Handle an invalid message nicely

Currently if the app receives an invalid message we simply throw an error and the app stops working. We should show a message to the user.

Running a development build of the Wallet against Ropsten fails

It seems to fail in truffle with the following error:


ERROR: /Users/alexgap/code/apps/packages/wallet/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/src/index.js:50
      throw new Error("Mnemonic invalid or undefined");
^
Error: Mnemonic invalid or undefined
    at new v (/Users/alexgap/code/apps/packages/wallet/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/src/index.js:50:1)
    at Object.provider (/Users/alexgap/code/apps/packages/wallet/truffle.js:28:23)
    at Object.create (/Users/alexgap/code/apps/packages/wallet/node_modules/truffle/build/webpack:/packages/truffle-provider/index.js:15:1)
    at Config.get [as provider] (/Users/alexgap/code/apps/packages/wallet/node_modules/truffle/build/webpack:/packages/truffle-config/index.js:202:1)
    at Object.detect (/Users/alexgap/code/apps/packages/wallet/node_modules/truffle/build/webpack:/packages/truffle-core/lib/environment.js:59:1)
    at Object.<anonymous> (/Users/alexgap/code/apps/packages/wallet/node_modules/truffle/build/webpack:/packages/truffle-core/lib/commands/migrate.js:170:1)
    at cb (util.js:1420:39)
    at process._tickCallback (internal/process/next_tick.js:63:19)

upgrade fmg-core and fmg-simple-adjudicator

We are using an old version (0.1.6) at present (latest version 0.3.5).

Since this will introduce some breaking changes (most notably the use of structs), we ought to think carefully about when to do it (i.e. before or after ETHDenver).

Configure google storage bucket permission correctly

Currently when accessing wallet.magmo.com it defaults to displaying the asset manifest not the actual index.html. This causes sites to embed the wallet to fail until the user visits wallet.magmo.com/index.html for the first time. (Then it works consistently after that)

Get insufficient funds -> withdraw working

For Player A (Xs) and Player B (Os).

Possibly also for Player A (Os) and Player B (Xs).

Be warned: this can take up to around turnNum ~ 40, and upwards of 100 mouse-clicks to test through the UI.

Change Resign to Conclude?

Resign is not part of the language of our state machine. It would be nice for the UI to be consistent with the way we think about our code.

Get storybook working in the wallet

Currently fails with this error:

ERROR in ./node_modules/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'child_process' in '/Users/alexgap/code/apps/packages/wallet/node_modules/xmlhttprequest/lib'
 @ ./node_modules/xmlhttprequest/lib/XMLHttpRequest.js 15:12-36
 @ ./node_modules/ethers/utils/web.js
 @ ./node_modules/ethers/utils/index.js
 @ ./src/utils/transaction-generator.ts
 @ ./src/integration-tests/test-utils.ts
 @ ./src/redux/reducers/__tests__/test-scenarios.ts
 @ ./src/__stories__/index.tsx
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/core/dist/server/config/polyfills.js ./node_modules/@storybook/core/dist/server/config/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true

ERROR in ./node_modules/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'fs' in '/Users/alexgap/code/apps/packages/wallet/node_modules/xmlhttprequest/lib'
 @ ./node_modules/xmlhttprequest/lib/XMLHttpRequest.js 16:9-22
 @ ./node_modules/ethers/utils/web.js
 @ ./node_modules/ethers/utils/index.js
 @ ./src/utils/transaction-generator.ts
 @ ./src/integration-tests/test-utils.ts
 @ ./src/redux/reducers/__tests__/test-scenarios.ts
 @ ./src/__stories__/index.tsx
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/core/dist/server/config/polyfills.js ./node_modules/@storybook/core/dist/server/config/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true

Fix asynchronous game opening in TTT

When Player A funds and then picks a move before Player B clicks 'return to game' in the wallet, this move will not be reflected in Player B's app when they eventually do click 'return to game'. Moreover both players are now waiting for a move and the game cannot progress.

Needs an actionToRetry.

Address silent failures

There are multiple places in the wallet and the app where things will fail silently. Two places that are pretty pervasive:

  • The app getting back a something_FAILURE from the wallet.
  • The wallet reducer checking that its ourTurn or that a signature is valid, etc..

Figure out CircleCI failures

CircleCI was failing due a process being killed (see https://circleci.com/gh/magmo/apps/81)

I've upgraded the node docker image which has seemed to fix it for now but we should look into what the original cause was and if we can improve our process so we're not running into a memory/cpu limit.

Standardize actions

Currently we have separate actions to approve funding, closing etc..(IE: FUNDING_APPROVED, CONCLUDE_APPROVED).

Instead of having separate actions for various different states we could consolidate these into a standard set of actions (APPROVE, REJECT) and rely on the current state to figure out what these actions apply to.

We currently do something like with transactions as we have a set of actions that can apply to multiple states (TRANSACTION_SENT_TO_METAMASK, TRANSACTION_SUBMITTED, etc..)

Some actions will have to remain as state specific but a lot of them could be consolidated.

Handle when a user declines funding

Currently we offer the user the option to approve/decline funding but we don't handle it gracefully.

When a user declines funding we should probably show a message and then dump them back in the lobby.

We should also let the other user know so they're not waiting indefinitely for funding

Sanitize Contract Artifacts

Currently our prebuilt artifacts for the testnets contain hard coded paths to my local machine. We only use the abi, networks and bytecode section from these artifacts so we can sanitize the other information out.

Return success/failure for opening a channel

Currently we do not return any event from the wallet when a channel is opened successfully and if something goes wrong we fail silently. We should throw events for both cases.

ttt bot

For the initial implementation, the bot will use a random strategy

Run CircleCI tests for a package only if that package has changed

Ideally instead of running all the tests every time a PR occurs we could make CircleCI testing a bit smarter and only run the tests for a package has changed (or it's dependency has changed).

This means if a change was made to rps only the tests for rps would be run. (On the flipside a change to wallet-client would trigger all tests to run since all the other packages are dependent on it)

Redux upload state not working

To repro:

  1. Play as A and B through funding and one round of RPS.
  2. Download redux state for both players.
  3. Refresh both browsers.
  4. Upload one state.json file in each browser window.

At this point, you would expect to be able to play another round. But, one of the players gets stuck.

I am using Chrome for player A and Firefox for player B, but I doubt this issue is related to a specific browser.

Hook up the channel wallet

Could just be copy-and-paste from rps-poc. Might want to wait until we've finished the refactor and extraction.

From Tom: Can do this as the very last step. All this adds is the signatures, deposits and security. The entire app (e.g. the user experience) can basically work without this.

Reinstate / rewrite tests

The tests for an app which interfaces the new wallet are quite RPS-specific, so for now are simply omitted. May need some work to reinstate.

End-to-end testing of SimpleAdjudicator

input -> output tests of contracts that use the rps and/or ttt game libraries

While the fmg-simple-adjudicator package has good tests, they implement only a very simple game library (namely a Counting Game).

If those tests pass, and the game-specific validTransition function is also passing thorough tests, this ought to give us confidence that the whole thing works. However, end-to-end testing will give us more confidence and should help troubleshoot problems such as not getting refunded from a channel. Without the end-to-end tests, we couldn't be sure if the contracts were at fault, or simply that the app is not preparing the transactions correctly.

Fix asynchronous game opening

This card is stolen from the TTT zube: When Player A funds and then picks a move before Player B clicks 'return to game' in the wallet, this move will not be reflected in Player B's app when they eventually do click 'return to game'. Moreover both players are now waiting for a move and the game cannot progress.

Needs an actionToRetry.

Handle metamask errors gracefully

We need to handle any metamask errors and communicate them gracefully to the user.

A retry button might be good for the case where the user has the wrong account selected?

rps-poc -> rps

We should probably get rid of the poc suffix in all references to rps

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.