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: add passkey #45

Open
wants to merge 14 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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ VITE_API_COSMOS=http://localhost:1317
VITE_WS_TENDERMINT=http://localhost:26657
VITE_WALLETCONNECT_PROJECT_ID=
VITE_ADDRESS_PREFIX=mycel
VITE_HOSTNAME=dashboard.mycel.domains
VITE_CHAIN_ID=mycel-local
VITE_CHAIN_NAME=Mycel Local
VITE_CHAIN_NAME="Mycel Local"
VITE_PK_ENCRYPTION_KEY=mycel
FAUCET_MNEMONIC=
FAUCET_AMOUNT=10000000
Expand Down
3 changes: 0 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
node_modules
dist
dist-ssr

src/hooks

35 changes: 19 additions & 16 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
extends: [
// By extending from a plugin config, we can get recommended rules without having to add them manually.
"eslint:recommended",
"plugin:react/recommended",
"plugin:import/recommended",
"plugin:jsx-a11y/recommended",
"plugin:@typescript-eslint/recommended",
'eslint:recommended',
'plugin:react/recommended',
'plugin:import/recommended',
'plugin:jsx-a11y/recommended',
'plugin:@typescript-eslint/recommended',
// This disables the formatting rules in ESLint that Prettier is going to be responsible for handling.
// Make sure it's always the last config, so it gets the chance to override other configs.
"plugin:prettier/recommended",
'plugin:prettier/recommended',
],
settings: {
react: {
// Tells eslint-plugin-react to automatically detect the version of React to use.
version: "detect",
version: 'detect',
},
// Tells eslint how to resolve imports
"import/resolver": {
alias: {
map: [["@", "./src"]],
extensions: [".js", ".jsx", ".ts", ".tsx"],
'import/resolver': {
typescript: {
project: './tsconfig.json',
},
// alias: {
// map: [['~', './src']],
// extensions: ['.js', '.jsx', '.ts', '.tsx'],
// },
node: {
paths: ["src"],
extensions: [".js", ".jsx", ".ts", ".tsx"],
paths: ['src'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
rules: {
"react/react-in-jsx-scope": "off",
'react/react-in-jsx-scope': 'off',
// Add your own rules here to override ones from the extended configs.
},
};
}
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

47 changes: 45 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

[ -f ~/.lefthookrc ] && . ~/.lefthookrc

call_lefthook()
{
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/')

if lefthook -h >/dev/null 2>&1
then
lefthook "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif command -v npx >/dev/null 2>&1
then
npx @evilmartians/lefthook "$@"
elif swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
}

call_lefthook run "pre-commit" "$@"
47 changes: 47 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

[ -f ~/.lefthookrc ] && . ~/.lefthookrc

call_lefthook()
{
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/')

if lefthook -h >/dev/null 2>&1
then
lefthook "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif command -v npx >/dev/null 2>&1
then
npx @evilmartians/lefthook "$@"
elif swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
}

call_lefthook run "prepare-commit-msg" "$@"
6 changes: 3 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"trailingComma": "all",
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"semi": false,
"singleQuote": true,
"printWidth": 120,
"endOfLine": "auto",
"useTabs": false
Expand Down
64 changes: 32 additions & 32 deletions api/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
import type { VercelRequest, VercelResponse } from "@vercel/node";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningStargateClient, DeliverTxResponse } from "@cosmjs/stargate";
import { OfflineDirectSigner } from "@keplr-wallet/types";
import * as dotenv from "dotenv";
import { object, string } from "yup";
import type { VercelRequest, VercelResponse } from '@vercel/node'
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'
import { SigningStargateClient, DeliverTxResponse } from '@cosmjs/stargate'
import { OfflineDirectSigner } from '@keplr-wallet/types'
import * as dotenv from 'dotenv'
import { object, string } from 'yup'

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 ?? "";
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);
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");
const balance = await faucetClient.getBalance(address, 'umycel')
if (balance.amount > threashold) {
return getErrorMessage("Faucet has insufficient balance");
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",
.sendTokens(faucetAddress, address, [{ denom: 'umycel', amount: amount }], {
amount: [{ denom: 'umycel', amount: amount }],
gas: '200000',
})
.then((res: DeliverTxResponse) => {
return res;
return res
})
.catch((err) => {
console.log(err);
return err;
});
return response;
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 });
const response = await claimFaucet(validatedData.address)
res.status(200).json({ response })
} catch (err) {
res.status(500).json(getErrorMessage(err.message));
res.status(500).json(getErrorMessage(err.message))
}
})
.catch((err) => {
res.status(400).json({ error: err.message });
});
res.status(400).json({ error: err.message })
})
}
6 changes: 6 additions & 0 deletions lefthook-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# lefthook-local.yml

# You can choose whatever name you want.
# You can share it between projects where you use lefthook.
# Make sure the path is absolute.
rc: ~/.lefthookrc
12 changes: 12 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pre-commit:
parallel: true
commands:
# packages-audit:
# run: pnpm audit
eslint:
glob: "*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}"
exclude: '^\.|/\.'
run: pnpm exec eslint --fix {staged_files}
prettier:
glob: "*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}"
run: pnpm exec prettier --write --ignore-unknown {staged_files}
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
"@dydxprotocol/v4-client-js": "^1.0.3",
"@headlessui/react": "^1.7.17",
"@headlessui/tailwindcss": "^0.2.0",
"@hexagon/base64": "^1.1.28",
"@hookform/resolvers": "^3.3.2",
"@peculiar/asn1-ecc": "^2.3.8",
"@peculiar/asn1-schema": "^2.3.8",
"@radix-ui/react-tooltip": "^1.0.7",
"@simplewebauthn/browser": "^8.3.4",
"@simplewebauthn/server": "^8.3.5",
"@vercel/node": "^3.0.9",
"@web3modal/ethereum": "^2.3.0",
"@web3modal/react": "^2.3.0",
"bignumber.js": "^9.1.0",
"cbor-x": "^1.5.6",
"classnames": "^2.3.2",
"crypto-js": "^4.1.1",
"dayjs": "^1.11.6",
Expand All @@ -39,7 +43,8 @@
"viem": "^1.19.9",
"vite-plugin-vercel-api": "^0.4.0",
"wagmi": "^1.4.5",
"yup": "^1.3.2"
"yup": "^1.3.2",
"zustand": "^4.4.7"
},
"devDependencies": {
"@keplr-wallet/types": "^0.11.14",
Expand All @@ -61,26 +66,26 @@
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-react": "^7.33.2",
"events": "^3.3.0",
"husky": "^8.0.3",
"jsdom": "^20.0.2",
"lint-staged": "^15.0.2",
"lefthook": "^1.5.5",
"node-stdlib-browser": "^1.2.0",
"postcss": "^8.4.31",
"prettier": "3.0.3",
"tailwind-merge": "^2.0.0",
"tailwindcss": "^3.3.5",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vite": "^5.0.11",
"vite-plugin-node-stdlib-browser": "^0.2.1"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0"
"node": ">=20.0.0",
"pnpm": ">=8.0.0"
},
"name": "mycel-frontend",
"private": true,
Expand All @@ -92,14 +97,10 @@
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
"lint:fix": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
"format": "prettier --write --ignore-path .gitignore './**/*.{js,jsx,ts,tsx,json}'",
"lint-format": "yarn lint:fix && yarn format",
"lint-format": "pnpm lint:fix && pnpm format",
"postinstall": "node postinstall.cjs",
"prepare": "node prepare.cjs && husky install"
"prepare": "node prepare.cjs && lefthook install"
},
"type": "module",
"version": "0.4.3",
"lint-staged": {
"*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}": "eslint --cache --fix",
"*.--write": "prettier --write"
}
"version": "0.4.3"
}
Loading