Skip to content

Commit

Permalink
chore: remove apps, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Mar 3, 2024
1 parent 6a6f90a commit 8b275bf
Show file tree
Hide file tree
Showing 60 changed files with 1,349 additions and 2,686 deletions.
43 changes: 19 additions & 24 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,31 @@
"useGitignore": true,
"language": "en",
"words": [
"binkey",
"binsec",
"chainlist",
"cirip",
"dataurl",
"devpool",
"Numberish",
"WXDAI",
"typebox",
"ethersproject",
"Rpcs",
"xmark",
"fract",
"gnosisscan",
"godb",
"greyscale",
"Claimability",
"XDAI",
"ubiquibot",
"TYPEHASH",
"cirip",
"rpcs",
"sonarjs",
"IERC",
"keccak",
"keypair",
"libsodium",
"Numberish",
"outdir",
"Rpcs",
"scalarmult",
"Keccak",
"chainlist",
"dataurl",
"SUPABASE",
"servedir",
"outdir",
"chainlist",
"solmate",
"sonarjs",
"typebox",
"TYPEHASH",
"ubiquibot",
"UBIQUIBOT",
"URLSAFE",
"WXDAI",
"XDAI",
"xmark"
"greyscale"
],
"dictionaries": ["typescript", "node", "software-terms", "html"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
Expand Down
42 changes: 21 additions & 21 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
"project": ["./tsconfig.json"],
},
"plugins": ["@typescript-eslint", "sonarjs"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:sonarjs/recommended"],
Expand All @@ -11,15 +11,15 @@
"prefer-arrow-callback": [
"warn",
{
"allowNamedFunctions": true
}
"allowNamedFunctions": true,
},
],
"func-style": [
"warn",
"declaration",
{
"allowArrowFunctions": false
}
"allowArrowFunctions": false,
},
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-non-null-assertion": "error",
Expand All @@ -35,8 +35,8 @@
"ignoreRestSiblings": true,
"vars": "all",
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
"argsIgnorePattern": "^_",
},
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-new": "error",
Expand All @@ -54,55 +54,55 @@
"format": ["PascalCase"],
"custom": {
"regex": "^I[A-Z]",
"match": false
}
"match": false,
},
},
{
"selector": "memberLike",
"modifiers": ["private"],
"format": ["camelCase"],
"leadingUnderscore": "require"
"leadingUnderscore": "require",
},
{
"selector": "typeLike",
"format": ["PascalCase"]
"format": ["PascalCase"],
},
{
"selector": "typeParameter",
"format": ["PascalCase"],
"prefix": ["T"]
"prefix": ["T"],
},
{
"selector": "variable",
"format": ["camelCase", "UPPER_CASE"],
"leadingUnderscore": "allow",
"trailingUnderscore": "allow"
"trailingUnderscore": "allow",
},
{
"selector": "variable",
"format": ["camelCase"],
"leadingUnderscore": "allow",
"trailingUnderscore": "allow"
"trailingUnderscore": "allow",
},
{
"selector": "variable",
"modifiers": ["destructured"],
"format": null
"format": null,
},
{
"selector": "variable",
"types": ["boolean"],
"format": ["PascalCase"],
"prefix": ["is", "should", "has", "can", "did", "will", "does"]
"prefix": ["is", "should", "has", "can", "did", "will", "does"],
},
{
"selector": "variableLike",
"format": ["camelCase"]
"format": ["camelCase"],
},
{
"selector": ["function", "variable"],
"format": ["camelCase"]
}
]
}
"format": ["camelCase"],
},
],
},
}
1 change: 1 addition & 0 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Conventional Commits

on:
push:
pull_request:

jobs:
conventional-commits:
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/kebab-case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Enforce kebab-case

on:
push:
pull_request:

jobs:
check-filenames:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Check For Non Kebab-Cased TypeScript Files
run: .github/workflows/scripts/kebab-case.sh
30 changes: 30 additions & 0 deletions .github/workflows/scripts/kebab-case.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
non_compliant_files=()
ignoreList=("^\.\/.git" "^\.\/\..*" "^\.\/[^\/]*$")
ignoreList+=("^\.\/node_modules")
while IFS= read -r line; do
ignoreList+=(".*$line")
done < .gitignore
while read -r file; do
basefile=$(basename "$file")
ignoreFile=false
for pattern in "${ignoreList[@]}"; do
if [[ "$file" =~ $pattern ]]; then
ignoreFile=true
break
fi
done
if $ignoreFile; then
continue
elif ! echo "$basefile" | grep -q -E "^([a-z0-9]+-)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$|^([a-z0-9]+_)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$"; then
non_compliant_files+=("$file")
echo "::warning file=$file::This file is not in kebab-case or snake_case"
fi
done < <(find . -type f -name '*.ts' -print | grep -E '/[a-z]+[a-zA-Z]*\.ts$')
if [ ${#non_compliant_files[@]} -ne 0 ]; then
echo "The following files are not in kebab-case or snake_case:"
for file in "${non_compliant_files[@]}"; do
echo " - $file"
done
exit 1
fi
31 changes: 31 additions & 0 deletions .github/workflows/scripts/kebabalize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
non_compliant_files=()
ignoreList=("^\.\/.git" "^\.\/\..*" "^\.\/[^\/]*$")
while IFS= read -r line; do
ignoreList+=(".*$line")
done < .gitignore
while read -r file; do
basefile=$(basename "$file")
ignoreFile=false
for pattern in "${ignoreList[@]}"; do
if [[ "$file" =~ $pattern ]]; then
ignoreFile=true
break
fi
done
if $ignoreFile; then
continue
elif ! echo "$basefile" | grep -q -E "^([a-z0-9]+-)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$|^([a-z0-9]+_)*[a-z0-9]+(\.[a-zA-Z0-9]+)?$"; then
non_compliant_files+=("$file")
echo "::warning file=$file::This file is not in kebab-case or snake_case"
newfile=$(dirname "$file")/$(echo "$basefile" | sed -r 's/([a-z0-9])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g')
mv "$file" "$newfile"
fi
done < <(find . -type f -name '*.ts' -print | grep -E '/[a-z]+[a-zA-Z]*\.ts$')
if [ ${#non_compliant_files[@]} -ne 0 ]; then
echo "The following files are not in kebab-case or snake_case:"
for file in "${non_compliant_files[@]}"; do
echo " - $file"
done
exit 1
fi
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,26 @@ http://localhost:8080?claim=eyJwZXJtaXQiOnsicGVybWl0dGVkIjp7InRva2VuIjoiMHgxMWZF
## How to test locally

1. Set `.env` variables.
2. In the project root run `npx http-server`. Set `env.FRONTEND_URL` to `http://localhost:8080`.
3. Run `npx tsx generate-permit2-url.ts` to generate an offline permit URL.
4. Open the generated permit URL in the `localhost`.
5. Connect the bounty hunter's address.
6. Click the "withdraw" button to get a reward.
2. Run `anvil --chain-id 31337 --fork-url https://rpc.gnosis.gateway.fm` in a separate terminal.
3. Run the Anvil commands (uses the Anvil default wallets).
4. In the project root run `yarn start`.
5. A permit URL for both ERC20 and ERC721 is generated in the terminal.
6. Open the generated permit URL defaulting to the variable values in the `.env` file.
7. Connect the bounty hunter's address.
8. Click the "withdraw" button to get a reward.
9. Testing the ERC721 permit is easiest deploying the `nft-rewards` contract from the [repository](https://github.com/ubiquity/nft-rewards)

#### Anvil commands

###### Using any other `--chain-id` will hit real RPC endpoints.

```
cast rpc anvil_impersonateAccount 0xba12222222228d8ba445958a75a0704d566bf2c8 &
cast send 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0xba12222222228d8ba445958a75a0704d566bf2c8 "transfer(address,uint256)(bool)" 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 337888400000000000000000 &
cast send 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 "approve(address,uint256)(bool)" 0x000000000022D473030F116dDEE9F6B43aC78BA3 9999999999999991111111119999999999999999 &
cast send 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --unlocked --from 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 "approve(address,uint256)(bool)" 0x000000000022D473030F116dDEE9F6B43aC78BA3 999999999999999111119999999999999999
```

## CloudFlare Setup (GitHub Secrets)

Expand Down
30 changes: 15 additions & 15 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import extraRpcs from "../lib/chainlist/constants/extraRpcs";
import esbuild from "esbuild";
import { execSync } from "child_process";
import * as dotenv from "dotenv";
const typescriptEntries = [
"static/scripts/rewards/index.ts",
"static/scripts/audit-report/audit.ts",
"static/scripts/onboarding/onboarding.ts",
"static/scripts/key-generator/keygen.ts",
];
const cssEntries = ["static/styles/rewards/rewards.css", "static/styles/audit-report/audit.css", "static/styles/onboarding/onboarding.css"];
import esbuild from "esbuild";
import extraRpcs from "../lib/chainlist/constants/extraRpcs";

const typescriptEntries = ["static/scripts/rewards/init.ts"];
const cssEntries = ["static/styles/rewards/rewards.css"];
export const entries = [...typescriptEntries, ...cssEntries];

const allNetworkUrls: Record<string, string[]> = {};
Expand All @@ -33,7 +30,10 @@ export const esBuildContext: esbuild.BuildOptions = {
".svg": "dataurl",
},
outdir: "static/out",
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], { extraRpcs: allNetworkUrls }),
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], {
extraRpcs: allNetworkUrls,
commitHash: execSync(`git rev-parse --short HEAD`).toString().trim(),
}),
};

esbuild
Expand All @@ -46,20 +46,20 @@ esbuild
process.exit(1);
});

function createEnvDefines(envVarNames: string[], extras: Record<string, unknown>): Record<string, string> {
function createEnvDefines(environmentVariables: string[], generatedAtBuild: Record<string, unknown>): Record<string, string> {
const defines: Record<string, string> = {};
dotenv.config();
for (const name of envVarNames) {
for (const name of environmentVariables) {
const envVar = process.env[name];
if (envVar !== undefined) {
defines[name] = JSON.stringify(envVar);
} else {
throw new Error(`Missing environment variable: ${name}`);
}
}
for (const key in extras) {
if (Object.prototype.hasOwnProperty.call(extras, key)) {
defines[key] = JSON.stringify(extras[key]);
for (const key in generatedAtBuild) {
if (Object.prototype.hasOwnProperty.call(generatedAtBuild, key)) {
defines[key] = JSON.stringify(generatedAtBuild[key]);
}
}
return defines;
Expand Down
14 changes: 2 additions & 12 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
export interface EthereumIsh {
autoRefreshOnNetworkChange: boolean;
chainId: string;
isMetaMask?: boolean;
isStatus?: boolean;
networkVersion: string;
selectedAddress: string;

on(event: "close" | "accountsChanged" | "chainChanged" | "networkChanged", callback: (payload: unknown) => void): void;
once(event: "close" | "accountsChanged" | "chainChanged" | "networkChanged", callback: (payload: unknown) => void): void;
}
import { Ethereum } from "ethereum-protocol";

declare global {
interface Window {
ethereum: EthereumIsh;
ethereum: Ethereum;
}
}
Loading

0 comments on commit 8b275bf

Please sign in to comment.