Skip to content

Commit

Permalink
Merge pull request #146 from whilefoo/nft-mint
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Jan 12, 2024
2 parents 923b2a9 + 88c8258 commit 057a657
Show file tree
Hide file tree
Showing 35 changed files with 3,691 additions and 3,729 deletions.
File renamed without changes.
2 changes: 2 additions & 0 deletions esbuild-config.ts → build/esbuild-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import esbuild from "esbuild";
import { invertColors } from "./plugins/invert-colors";
const typescriptEntries = [
"static/scripts/rewards/index.ts",
"static/scripts/audit-report/audit.ts",
Expand All @@ -11,6 +12,7 @@ export const entries = [...typescriptEntries, ...CSSEntries];
export let esBuildContext = {
sourcemap: true,
entryPoints: entries,
//plugins: [invertColors],
bundle: true,
minify: false,
loader: {
Expand Down
File renamed without changes.
54 changes: 54 additions & 0 deletions build/plugins/invert-colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import esbuild from "esbuild";
import fs from "fs";
import path, { basename, dirname } from "path";

export const invertColors: esbuild.Plugin = {
name: "invert-colors",
setup(build) {
build.onEnd(async result => {
console.log(result);
});
build.onLoad({ filter: /\.css$/ }, async args => {
const contents = await fs.promises.readFile(args.path, "utf8");

const updatedContents = contents.replace(/prefers-color-scheme: dark/g, "prefers-color-scheme: light");

// Invert greyscale colors and accommodate alpha channels in the CSS content
const invertedContents = updatedContents.replace(/#([0-9A-Fa-f]{3,6})([0-9A-Fa-f]{2})?\b/g, (match, rgb, alpha) => {
let color = rgb.startsWith("#") ? rgb.slice(1) : rgb;
if (color.length === 3) {
color = color
.split("")
.map((char: string) => char + char)
.join("");
}
const r = parseInt(color.slice(0, 2), 16);
const g = parseInt(color.slice(2, 4), 16);
const b = parseInt(color.slice(4, 6), 16);

// Check if the color is greyscale (R, G, and B components are equal)
if (r === g && g === b) {
// Invert RGB values
const invertedColorValue = (255 - r).toString(16).padStart(2, "0");
// Return the inverted greyscale color with alpha channel if present
return `#${invertedColorValue}${invertedColorValue}${invertedColorValue}${alpha || ""}`;
}

// If the color is not greyscale, return it as is, including the alpha channel if present
return `#${color}${alpha || ""}`;
});

// Define the output path for the new CSS file
const fileBasename = basename(args.path);
const fileDirname = dirname(args.path);
const outputPath = path.resolve(fileDirname, `inverted-${fileBasename}`);
const outputDir = path.dirname(outputPath);
await fs.promises.mkdir(outputDir, { recursive: true });
// Write the new contents to the output file
await fs.promises.writeFile(outputPath, invertedContents, "utf8");

// Return an empty result to esbuild since we're writing the file ourselves
return { contents: "", loader: "css" };
});
},
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"start": "run-s utils:hash start:sign start:ui",
"format": "prettier --write .",
"build": "run-s utils:hash utils:build",
"start:ui": "tsx server.ts",
"start:ui": "tsx build/esbuild-server.ts",
"start:sign": "tsx scripts/typescript/generate-permit2-url.ts",
"utils:build": "tsx esbuild.ts",
"utils:build": "tsx build/esbuild-build.ts",
"utils:hash": "git rev-parse --short HEAD > static/commit.txt",
"utils:get-invalidate-params": "forge script --via-ir scripts/solidity/GetInvalidateNonceParams.s.sol"
},
Expand All @@ -16,6 +16,7 @@
"@octokit/plugin-create-or-update-text-file": "^2.0.4",
"@octokit/plugin-throttling": "^5.1.0",
"@octokit/rest": "^19.0.7",
"@sinclair/typebox": "^0.31.28",
"@types/libsodium-wrappers": "^0.7.10",
"@types/node": "^18.15.11",
"@uniswap/permit2-sdk": "^1.2.0",
Expand All @@ -35,4 +36,4 @@
"engines": {
"node": ">=20.10.0"
}
}
}
58 changes: 39 additions & 19 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,41 @@
</a>
</header>
<div>
<div style="display: flex; flex-direction: row; align-items: center; align-self: center; margin-bottom: 10px">
<svg
id="previousTx"
height="12px"
width="12px"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 490 490"
xml:space="preserve"
style="cursor: pointer; padding: 10px"
>
<g>
<polygon points="332.668,490 82.631,244.996 332.668,0 407.369,76.493 235.402,244.996 407.369,413.507" />
</g>
</svg>

<div id="rewardsCount">1/x reward</div>

<svg
id="nextTx"
height="12px"
width="12px"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 490 490"
xml:space="preserve"
style="cursor: pointer; padding: 10px"
>
<g transform="matrix(-1, 0.0007910000276751816, 0, 1, 490.0000305175781, -0.1938260048627818)">
<polygon points="332.668,490 82.631,244.996 332.668,0 407.369,76.493 235.402,244.996 407.369,413.507" />
</g>
</svg>
</div>
<table>
<thead>
<tr>
Expand All @@ -62,18 +97,18 @@
<tbody>
<tr id="Amount">
<th><div>Amount</div></th>
<td id="transferDetails.requestedAmount"><div>Loading...</div></td>
<td id="rewardAmount"><div>Loading...</div></td>
</tr>
<tr id="Token">
<th><div>Token</div></th>
<td id="permit.permitted.token">
<td id="rewardToken">
<span class="full"><div></div></span>
<span class="short"><div>Loading...</div></span>
</td>
</tr>
<tr id="To">
<th><div>For</div></th>
<td id="transferDetails.to">
<td id="rewardRecipient">
<span class="full"><div></div></span>
<span class="short"><div>Loading...</div></span>
</td>
Expand Down Expand Up @@ -131,23 +166,8 @@
</div>
</td>
</tr>
<tr id="From">
<th><div>From</div></th>
<td id="owner"><div></div></td>
</tr>
<tr id="Allowance">
<th><div>Allowance</div></th>
<td class="tr-allowance">
<div>Loading...</div>
</td>
</tr>
<tr id="Balance">
<th><div>Balance</div></th>
<td class="tr-balance">
<div>Loading...</div>
</td>
</tr>
</tbody>
<tbody id="additionalDetailsTable"></tbody>
</table>
</div>
<footer>
Expand Down
4 changes: 2 additions & 2 deletions static/scripts/onboarding/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PERMIT2_ADDRESS } from "@uniswap/permit2-sdk";
import { JsonRpcSigner, Network } from "@ethersproject/providers";
import { parseUnits } from "ethers/lib/utils";
import { NetworkIds, Tokens, getNetworkName, networkNames } from "../rewards/constants";
import { daiAbi } from "../rewards/abis/daiAbi";
import { erc20Abi } from "../rewards/abis/erc20Abi";

const classes = ["error", "warn", "success"];
const inputClasses = ["input-warn", "input-error", "input-success"];
Expand Down Expand Up @@ -535,7 +535,7 @@ const step2Handler = async () => {
} else if (configChainIdHex === NetworkIds.Gnosis) {
token = Tokens.WXDAI;
}
const erc20 = new ethers.Contract(token, daiAbi, signer);
const erc20 = new ethers.Contract(token, erc20Abi, signer);
const decimals = await erc20.decimals();
const allowance = Number(allowanceInput.value);
if (allowance <= 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const daiAbi = [
export const erc20Abi = [
{ inputs: [{ internalType: "uint256", name: "chainId_", type: "uint256" }], payable: false, stateMutability: "nonpayable", type: "constructor" },
{
anonymous: false,
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/abis/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./daiAbi";
export * from "./erc20Abi";
export * from "./permit2Abi";
Loading

1 comment on commit 057a657

@ubiquibot
Copy link

@ubiquibot ubiquibot bot commented on 057a657 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.