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

Refactor #46

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ VITE_PK_ENCRYPTION_KEY=mycel
FAUCET_MNEMONIC=
FAUCET_AMOUNT=10000000
VITE_FAUCET_CLAIMABLE_THRESHOLD=1000000
VITE_PK_ENCRYPTION_KEY=
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

38 changes: 0 additions & 38 deletions .eslintrc.cjs

This file was deleted.

31 changes: 31 additions & 0 deletions .github/actions/setup-and-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Setup and cache
description: Setup for node, pnpm and cache for browser testing binaries
inputs:
node-version:
required: false
description: Node version for setup-node
default: 20.x
runs:
using: composite
steps:
- name: Install pnpm
uses: pnpm/action-setup@v2
- name: Set node version to ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Get installed Playwright version
id: playwright-version
shell: bash
run: |
PLAYWRIGHT_VERSION=$(cat pnpm-lock.yaml | grep /@playwright/test@ | sed 's/.*@\([^:]*\):.*/\1/')
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Playwright v${{ env.PLAYWRIGHT_VERSION }}
uses: actions/cache@v3
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-cache-${{ env.PLAYWRIGHT_VERSION }}
restore-keys: |
${{ runner.os }}-playwright-cache-
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
VITEST_SEGFAULT_RETRY: 3
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-and-cache
- name: Install
run: pnpm i
- name: Lint
run: pnpm run lint
- name: Format
run: pnpm run format
# typecheck:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: ./.github/actions/setup-and-cache
# - name: Install
# run: pnpm i
# - name: Build
# run: pnpm run build
# - name: Typecheck
# run: pnpm run typecheck
test-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-and-cache
with:
node-version: 20
- name: Install
run: pnpm i
- name: Vitest
run: pnpm run test:unit
test-e2e:
runs-on: ubuntu-latest
strategy:
matrix:
browser: [['Desktop Chrome', chromium]]
# browser: [['Desktop Chrome', chromium], ['Desktop Firefox', firefox], ['Desktop Safari', webkit], ['Pixel 5', 'Mobile Chrome'], 'iPhone 12', 'Mobile Safari']
timeout-minutes: 30
env:
BROWSER: ${{ matrix.browser[0] }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-and-cache
with:
node-version: 20
- uses: browser-actions/setup-chrome@v1
- uses: browser-actions/setup-firefox@v1
- uses: browser-actions/setup-edge@v1
id: setup-edge
with:
edge-version: stable
- name: Install
run: pnpm i
- name: Install Playwright Dependencies
run: pnpm exec playwright install --with-deps
- name: Build
run: pnpm run build
- name: Test e2e (playwright)
run: pnpm run test:e2e
env:
BROWSER: ${{ matrix.browser[1] }}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ dist-ssr

# Vercel
.vercel

# lefthook
lefthook-local.yml
/.lefthook-local/

# test
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

9 changes: 0 additions & 9 deletions .prettierrc

This file was deleted.

5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"biomejs.biome"
]
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Mycel Frontend

## Getting Started

Install Dependencies

```
yarn Install
pnpm Install
```

Set up enviroment

```
cp .env.example .env
```

Run Local Server

```
yarn run dev
pupm run dev
```

## Build

```
yarn build
pnpm build
```
71 changes: 71 additions & 0 deletions _api/faucet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'
import { DeliverTxResponse, SigningStargateClient } from '@cosmjs/stargate'
import { OfflineDirectSigner } from '@keplr-wallet/types'
import type { VercelRequest, VercelResponse } from '@vercel/node'
import * as dotenv from 'dotenv'
import { object, string } from 'yup'

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
function getErrorMessage(err: any) {
return {
code: -1,
rawLog: err,
}
}

async function claimFaucet(address: string) {
// Load environment variables
dotenv.config()
const amount = process.env.FAUCET_AMOUNT ?? '1000000'
const threashold = process.env.VITE_FAUCET_CLAIMABLE_THRESHOLD ?? '300000'
const faucetMnemonic = process.env.FAUCET_MNEMONIC ?? ''
const rpc = process.env.VITE_WS_TENDERMINT ?? ''

// Create faucet signer
const faucetSigner = (await DirectSecp256k1HdWallet.fromMnemonic(faucetMnemonic, {
prefix: 'mycel',
})) as OfflineDirectSigner
const faucetAddress = (await faucetSigner.getAccounts())[0].address
const faucetClient = await SigningStargateClient.connectWithSigner(rpc, faucetSigner)

// Check if faucet has enough balance
const balance = await faucetClient.getBalance(address, 'umycel')
if (balance.amount > threashold) {
return getErrorMessage('Faucet has insufficient balance')
}

// Send tokens
const response = await faucetClient
.sendTokens(faucetAddress, address, [{ denom: 'umycel', amount: amount }], {
amount: [{ denom: 'umycel', amount: amount }],
gas: '200000',
})
.then((res: DeliverTxResponse) => {
return res
})
.catch(err => {
console.log(err)
return err
})
return response
}

const faucetSchema = object({
address: string().required(),
})

export default function handler(req: VercelRequest, res: VercelResponse) {
faucetSchema
.validate(req.query)
.then(async validatedData => {
try {
const response = await claimFaucet(validatedData.address)
res.status(200).json({ response })
} catch (err) {
res.status(500).json(getErrorMessage(err.message))
}
})
.catch(err => {
res.status(400).json({ error: err.message })
})
}
70 changes: 0 additions & 70 deletions api/faucet.ts

This file was deleted.

Loading