Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dapp adjustments2 #8

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bb4266e
feat: created form with zod
andreabadesso Aug 23, 2024
8451ad1
feat: improved the form
andreabadesso Aug 23, 2024
c02ec81
feat: added bet screen
andreabadesso Aug 24, 2024
980cb9c
feat: added Results screen
andreabadesso Aug 25, 2024
ea933c9
feat: added thanks screen
andreabadesso Aug 25, 2024
873ca65
feat: added popover to walletconnect menu
andreabadesso Aug 25, 2024
a446459
refactor: removed unused component
andreabadesso Aug 25, 2024
4e6cf81
feat: walletconnect dependencies and component working
andreabadesso Aug 25, 2024
5ec0343
feat: create bet talking to app through walletconnect
andreabadesso Aug 26, 2024
b8fe670
feat: create nano contract working
andreabadesso Aug 27, 2024
409bb3f
feat: several changes to screens
andreabadesso Sep 2, 2024
b12a0ba
feat: wait network confirmation
andreabadesso Sep 5, 2024
376c56f
fix: total bet component called with old signature
andreabadesso Sep 5, 2024
ac71329
feat: added all bets screen
andreabadesso Sep 7, 2024
6685117
fix: stop using BASE_URL
andreabadesso Sep 10, 2024
6de9549
chore: showing connect when no session
andreabadesso Sep 11, 2024
453546c
refactor: several improvements
andreabadesso Sep 12, 2024
96bfcc8
chore: updated hathor logo
andreabadesso Sep 12, 2024
d37668a
chore: updated wallet-lib
andreabadesso Sep 12, 2024
e801dd4
fix: results screen showing no result
andreabadesso Sep 12, 2024
523a068
fix: added type to interval
andreabadesso Sep 12, 2024
32e854f
chore: using wallet-lib as a peer dependency
andreabadesso Sep 12, 2024
66c0090
fix: min text size on create and bet
andreabadesso Sep 16, 2024
054151f
chore: Create Dockerfile (#4)
luislhl Sep 16, 2024
6ccf7a9
feat: updated QR code on thanks page
andreabadesso Sep 16, 2024
0c89e25
refactor: using URL isntead of URL + BASE_PATH
andreabadesso Sep 17, 2024
015e7e3
fix: using tx_id instead of nc_id
andreabadesso Sep 17, 2024
05e9110
fix: createdAt -> created at
andreabadesso Sep 17, 2024
2d59055
fix: zero padding on tables
andreabadesso Sep 17, 2024
19a7bca
fix: stop capitalizing first letter of bet on tx history
andreabadesso Sep 17, 2024
35f8931
fix: using createdAt instead of timestamp on all bets initial ordering
andreabadesso Sep 17, 2024
958464b
feat: added creatorAddress to store who created the nano contract
andreabadesso Oct 30, 2024
34aca76
feat: API to filter by creator_address
andreabadesso Oct 30, 2024
5d0927a
refactor: EVC -> HTR
andreabadesso Oct 30, 2024
8fffd9e
fix: added missing creatorAddress
andreabadesso Nov 8, 2024
6ac4290
feat: added backgrounds and updated wallet connect
andreabadesso Nov 9, 2024
f351a3b
feat: UI updates
andreabadesso Nov 10, 2024
027adbe
feat: added first screen images
andreabadesso Nov 12, 2024
78ea16f
chore: updated deploy to serve images correctly
andreabadesso Nov 12, 2024
8875eb0
fix: background images and added bitcore-lib
andreabadesso Nov 12, 2024
5983795
fix: fixed margin on walletconnect header and logo in all_bets screen
andreabadesso Nov 12, 2024
949339e
refactor: removed createNc from all bets
andreabadesso Nov 29, 2024
c456172
chore: stop ignoring yarn patches
andreabadesso Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile

node_modules
.yarn/*
!.yarn/patches
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.direnv/
node_modules/
.yarn/
.yarn/*
!.yarn/patches/
!.yarn/patches/**
12 changes: 12 additions & 0 deletions .yarn/patches/bitcore-lib-npm-8.25.10-2b2055eaf2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/index.js b/index.js
index 4cbe6bf2ac69202558e0cfb8457fec21c2d48017..98cad3a403bacc0ebd2d1223d3c17adc23a53bc7 100644
--- a/index.js
+++ b/index.js
@@ -5,6 +5,7 @@ var bitcore = module.exports;
// module information
bitcore.version = 'v' + require('./package.json').version;
bitcore.versionGuard = function(version) {
+ return;
if (version !== undefined) {
var message = 'More than one instance of bitcore-lib found. ' +
'Please make sure to require bitcore-lib and check that submodules do' +
12 changes: 12 additions & 0 deletions .yarn/patches/bitcore-lib-npm-8.25.47-62066b9183.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/index.js b/index.js
index 4cbe6bf2ac69202558e0cfb8457fec21c2d48017..98cad3a403bacc0ebd2d1223d3c17adc23a53bc7 100644
--- a/index.js
+++ b/index.js
@@ -5,6 +5,7 @@ var bitcore = module.exports;
// module information
bitcore.version = 'v' + require('./package.json').version;
bitcore.versionGuard = function(version) {
+ return;
if (version !== undefined) {
var message = 'More than one instance of bitcore-lib found. ' +
'Please make sure to require bitcore-lib and check that submodules do' +
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* .yarnrc.yml ./
COPY packages/bet-dapp/package.json ./packages/bet-dapp/

COPY .yarn/patches .yarn/patches/

RUN corepack enable
RUN yarn set version 4.2.2

RUN \
yarn install

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED=1

ENV NEXT_PUBLIC_URL=https://betting.hathor.network/
ENV NEXT_PUBLIC_BASE_PATH=/public

COPY packages/bet-dapp ./packages/bet-dapp
RUN cp ./packages/bet-dapp/next.config.production.mjs ./packages/bet-dapp/next.config.mjs

RUN \
yarn workspace bet-dapp run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# # Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/packages/bet-dapp/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/packages/bet-dapp/public ./packages/bet-dapp/public/public
COPY --from=builder --chown=nextjs:nodejs /app/packages/bet-dapp/.next/static ./packages/bet-dapp/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/classic-level ./node_modules/classic-level

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "packages/bet-dapp/server.js"]
179 changes: 179 additions & 0 deletions SOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Bet-dapp - SOP

## Pre-requisites

### Tools

- Docker
- AWS CLI
- Terraform (Only if you need to change the infra. Not necessary to deploy new versions in the instance)

### AWS Access

You must configure access to the `Nano-testnet` account in AWS.

Run the following command:

```bash
aws configure sso
```

Set the following values when asked:

- SSO Session Name: `nano-testnet`
- SSO Start URL: `https://hathorlabs.awsapps.com/start`
- SSO Region: `us-east-1`
- SSO Registration Scopes: `sso:account:access`
- In the accounts list, select `Nano-testnet`
- CLI default client region: `us-east-1`
- CLI default output format: `None`
- CLI profile name: `nano-testnet`

Login to the account using the following command:

```bash
aws sso login --profile nano-testnet
```
## Deploying new versions

### Building and pushing the image

```bash
aws ecr get-login-password --region ap-southeast-1 --profile nano-testnet | docker login --username AWS --password-stdin 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com

docker build -t 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com/bet-dapp:latest .

docker push 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com/bet-dapp:latest
```

### Accessing the instance

```bash
# Get the instance IP from its name tag
aws ec2 describe-instances --profile nano-testnet --filters "Name=tag:Name,Values=bet-dapp" --query "Reservations[*].Instances[*].PublicIpAddress" --output text --region ap-southeast-1

ssh ec2-user@<instance-ip>
```

### Login to Docker in the instance

```bash
aws ecr get-login-password --region ap-southeast-1 | sudo docker login --username AWS --password-stdin 471112952246.dkr.ecr.ap-southeast-1.amazonaws.com
```

### Pulling the latest image

The following should be run inside the EC2 instance

```bash
# Inside the home directory (/home/ec2-user)
sudo docker compose pull
```

### Restarting the service

The following should be run inside the EC2 instance

```bash
# Inside the home directory (/home/ec2-user)
# Running this will pick up any changes in the configuration and recreate the container
sudo docker compose up -d
```

## Other operations in the instance

### Checking logs

The following should be run inside the EC2 instance

```bash
# Inside the home directory (/home/ec2-user)
sudo docker compose logs bet-dapp -f
```

### Stopping the service

The following should be run inside the EC2 instance

```bash
# Inside the home directory (/home/ec2-user)
sudo docker compose down
```

### Starting the service

The following should be run inside the EC2 instance

```bash
# Inside the home directory (/home/ec2-user)
sudo docker compose up -d
```

## Inspecting the DynamoDB table in AWS

Go to https://hathorlabs.awsapps.com/start and login to the `Nano-testnet` account.

You can find the table at:
- https://ap-southeast-1.console.aws.amazon.com/dynamodbv2/home?region=ap-southeast-1#table?name=NanoContracts

Click `Explore table items` to see the items in the table.

## Infra changes

The infra is currently defined in https://github.com/HathorNetwork/ops-tools/tree/master/terraform/bet-dapp

Make sure to run `make terraform-init` to setup the Terraform environment.

### Updating the DybamoDB table definition

The table is defined in the file `terraform/bet-dapp/dynamodb.tf`

Refer to the [Terraform documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table) for more information on how to define the table.

Apply the changes by running:

```bash
make apply
```

You'll be prompted to review the changes before they are applied.

### Changing the instance security group, instance type or other configurations

The instance is defined in the file `terraform/bet-dapp/ec2.tf`

Refer to the Terraform documentation on the following resources for more information on how to define the instance:
- [aws_instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance)
- [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group)
- [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role)
- [aws_iam_instance_profile](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile)
- [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy)

Apply the changes by running:

```bash
make apply
```

You'll be prompted to review the changes before they are applied.

### Changing the instance provisioning script

The provisioning script is defined in the file `terraform/bet-dapp/scripts/provision-instance.yaml.tftpl`

It's a cloud-init script that runs when the instance is created.

If changes are needed inside the instance, ideally they should be written in this script and the instance should be recreated by running `make apply`.

This will generate a downtime in the service, so it should be done with caution. To avoid this, you could create a new instance first, test the changes and then switch the Elastic IP to the new instance. Or just make the changes in the running instance, if you're in a hurry, then update the script later.

The Elastic IP is defined in the file `terraform/bet-dapp/ec2.tf`

### Changing the Cloudfront configuration

We had to add a rule in the Cloudfront distribution we use to serve `hathor.network`, in order to have the bet-dapp served under https://hathor.network/betting2024

To update this, you should:

- Login to the `Hathor-website` account through https://hathorlabs.awsapps.com/start
- Access the Cloudfront distribution at https://us-east-1.console.aws.amazon.com/cloudfront/v4/home?region=eu-central-1#/distributions/E2AT2JAIYAKNGG
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"packageManager": "[email protected]",
"workspaces": [
"packages/bet-dapp"
]
],
"resolutions": {
"bitcore-lib@npm:8.25.10": "patch:bitcore-lib@npm%3A8.25.47#~/.yarn/patches/bitcore-lib-npm-8.25.47-62066b9183.patch",
"bitcore-lib@npm:^8.25.10": "patch:bitcore-lib@npm%3A8.25.47#~/.yarn/patches/bitcore-lib-npm-8.25.47-62066b9183.patch"
}
}
1 change: 1 addition & 0 deletions packages/bet-dapp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
dynamodb_data/
11 changes: 11 additions & 0 deletions packages/bet-dapp/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.8'

services:
dynamodb:
image: amazon/dynamodb-local
container_name: dapp-dynamodb
ports:
- "8000:8000"
volumes:
- ./dynamodb_data:/home/dynamodblocal/data
command: -jar DynamoDBLocal.jar -sharedDb -dbPath /home/dynamodblocal/data --cors "http://localhost:3000"
14 changes: 13 additions & 1 deletion packages/bet-dapp/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
reactStrictMode: false,
webpack: config => {
config.externals.push('pino-pretty', 'lokijs', 'encoding');

return {
...config,
node: {
__dirname: true,
},
};
},
};

export default nextConfig;
18 changes: 18 additions & 0 deletions packages/bet-dapp/next.config.production.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
basePath: "",
assetPrefix: "https://betting.hathor.network/",
webpack: config => {
config.externals.push('pino-pretty', 'lokijs', 'encoding');

return {
...config,
node: {
__dirname: true,
},
};
},
};

export default nextConfig;
Loading