GithubHelp home page GithubHelp logo

ilbertt / fortune-wheel-booth Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 2.0 17.44 MB

Fortune wheel game for your conference booth

Shell 13.80% Motoko 26.12% HTML 1.90% JavaScript 3.73% SCSS 4.90% TypeScript 49.54%
fortune-wheel icp internet-computer motoko

fortune-wheel-booth's Introduction

fortune-wheel-booth

Welcome to your new fortune-wheel-booth project and to the Internet Computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.

To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.

To learn more before you start working with fortune-wheel-booth, see the following documentation available online:

If you want to start working on your project right away, you might want to try the following commands:

cd fortune-wheel-booth/
dfx help
dfx canister --help

Requirements

Running the project locally

If you want to test your project locally, you can use the following commands:

# Install dependencies
pnpm install

# Starts the replica, running in the background
dfx start --background

# eventually pull the dependencies (only the first time)
dfx deps pull

# deploy all the canisters locally
./scripts/deploy-local-canisters.sh

Once the job completes, your application will be available at http://localhost:4943?canisterId={asset_canister_id}.

If you have made changes to your backend canister, you can generate a new candid interface with

dfx generate

at any time. This is recommended before starting the frontend development server, and will be run automatically any time you run dfx deploy.

If you are making frontend changes, you can start a development server with

pnpm start

Which will start a server at http://localhost:8080, proxying API requests to the replica at port 4943.

Usage

To get the latest extraction (you don't need to be authenticated), use the following command:

dfx canister call fortune-wheel-booth-backend getLatestExtraction

Admin

You are automatically set as an admin if you deploy the canister the first time.

The following methods are available for admins.

extract

To run an extraction as an admin, use the following command:

dfx canister call fortune-wheel-booth-backend extract '(principal "<the-principal-you-want-to-extract-for>")'

getExtraction

To fetch the extraction for a principal, use the following command:

dfx canister call fortune-wheel-booth-backend getExtraction '(principal "<the-principal-you-want-to-fetch-the-extraction-for>")'

getExtractions

To fetch all extractions, use the following command:

dfx canister call fortune-wheel-booth-backend getExtractions

manualTransfer

To manually send tokens to a principal, use the following command:

dfx canister call fortune-wheel-booth-backend manualTransfer '(
  record {
    tokens = variant { icp = 50_000_000 : nat }; # or ckBtc or ckEth or ckUsdc
    receiver = principal "<the-principal-you-want-to-send-to>";
  },
)'

You can use this method if you need to remove the tokens from the canister and send them back to your address.

addAdmin

To add an admin, use the following command:

dfx canister call fortune-wheel-booth-backend addAdmin '(principal "<the-principal-you-want-to-add-as-admin>")'

removeAdmin

To remove an admin, use the following command:

dfx canister call fortune-wheel-booth-backend removeAdmin '(principal "<the-principal-you-want-to-remove-as-admin>")'

getAdmins

To fetch the list of admins, use the following command:

dfx canister call fortune-wheel-booth-backend getAdmins

getAvailablePrizes

To fetch the available prizes, use the following command:

dfx canister call fortune-wheel-booth-backend getAvailablePrizes

For ICP and ckBTC, the amount is specified in the format: 1 ICP = 10^8 token amount.

For ckUSDC, the amount is specified in the format: 1 ckUSDC = 10^6 token amount.

For ckETH, the amount is specified in the format: 1 ckETH = 10^18 token amount.

setAvailablePrizes

To set the available prizes, use the following command (values as example):

dfx canister call fortune-wheel-booth-backend setAvailablePrizes '(
  vec {
    record { variant { icp = 8_200_000 : nat }; opt (8 : nat8) };
    record { variant { ckBtc = 1_500 : nat }; opt (4 : nat8) };
    record { variant { merch = "Tshirt" }; ?5 };
    record { variant { merch = "Pen" }; ?10 };
    record { variant { special = "jackpot" }; ?1 };
    record { variant { noPrize }; null };
  },
)'

We suggest to first fetch the available prizes with the getAvailablePrizes method and use that result to create the new available prizes array.

Scripts

Fetch backend canister balances

To fetch the balances of the backend canister in the ledgers, use the following command:

# use --network local to fetch balances on local network (default if not specified)
./scripts/backend-canister-balances.sh --network ic

Note on frontend environment variables

If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:

  • setDFX_NETWORK to ic if you are using Webpack
  • use your own preferred method to replace process.env.DFX_NETWORK in the autogenerated declarations
    • Setting canisters -> {asset_canister_id} -> declarations -> env_override to a string in dfx.json will replace process.env.DFX_NETWORK with the string in the autogenerated declarations
  • Write your own createActor constructor

fortune-wheel-booth's People

Contributors

fraank98 avatar ilbertt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sesi200

fortune-wheel-booth's Issues

Fortune wheel spinning after reload

On production, if there's a last prize, the wheel spins after reloading the page "extracting" the last extracted prize returned by the canister. We shouldn't allow it by avoiding extracting after the first fetch from the canister.

fix: handle principal parse error

When reading the QR code from the scanner, if the principal is not valid we need to show an error in the UI and avoid calling the backend

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.