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

chore: initialize #3

Open
wants to merge 49 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f6708d9
chore: initialize
kingsley-einstein Sep 26, 2024
f64e5c3
chore: made updates
kingsley-einstein Sep 26, 2024
a648dea
chore: made updates
kingsley-einstein Sep 26, 2024
6726d0f
feat: add providers list modal
kingsley-einstein Sep 27, 2024
f8f571e
feat: create functions to interact with blockchain
kingsley-einstein Oct 2, 2024
001d880
chore: make requested changes
kingsley-einstein Oct 2, 2024
95d2015
chore: made requested changes
kingsley-einstein Oct 3, 2024
5a9ea09
feat: begin working on minting page
kingsley-einstein Oct 5, 2024
2182135
chore: small update to let the guys know I'm still on this
kingsley-einstein Oct 11, 2024
e320389
chore: update ui
kingsley-einstein Oct 12, 2024
cb8adb1
chore: add tailwindcss for convenience
kingsley-einstein Oct 19, 2024
0addf0f
chore: update minting page
kingsley-einstein Oct 19, 2024
7e705c1
chore: update mint.ts
kingsley-einstein Oct 22, 2024
6a0e398
chore: made updates
kingsley-einstein Oct 23, 2024
67f5d1a
chore: finish minting page
kingsley-einstein Oct 25, 2024
5be5157
chore: finish
kingsley-einstein Oct 25, 2024
393f476
chore: finish
kingsley-einstein Oct 26, 2024
e0a6a68
chore: made requested changes
kingsley-einstein Oct 27, 2024
e8ecee2
chore: effect changes
kingsley-einstein Oct 28, 2024
c10d37c
chore: effect changes
kingsley-einstein Oct 28, 2024
ef28c3e
feat: add QA helper scripts
rndquu Oct 29, 2024
b444135
Merge pull request #1 from rndquu/feat/qa-helper-scripts
kingsley-einstein Oct 30, 2024
6995d6e
chore: apply requested changes
kingsley-einstein Oct 30, 2024
d7baf39
feat: add increase UUSD thresholds helper script
rndquu Oct 31, 2024
fbdf50a
Merge pull request #2 from rndquu/feat/add-increase-uusd-thresholds
kingsley-einstein Oct 31, 2024
4e0aeb5
chore: apply required changes
kingsley-einstein Oct 31, 2024
8bdc118
chore: apply required changes
kingsley-einstein Oct 31, 2024
1deeb47
chore: made fixes
kingsley-einstein Nov 8, 2024
809ec2e
fix: knip issues
kingsley-einstein Nov 8, 2024
283223e
feat: add UBQ fund test script
rndquu Nov 11, 2024
6fe4bf0
Merge pull request #3 from rndquu/chore/add-ubq-fund-helper
kingsley-einstein Nov 11, 2024
f07a96b
chore: remove hardcoded decimals
kingsley-einstein Nov 11, 2024
f3e8c47
chore: implement updates
kingsley-einstein Nov 29, 2024
0e3599d
chore: implement updates
kingsley-einstein Nov 29, 2024
b34b57c
chore: implement requested updates
kingsley-einstein Dec 4, 2024
2baee72
chore: implement updates
kingsley-einstein Dec 12, 2024
7a2b220
chore: implement updates
kingsley-einstein Dec 12, 2024
ec3a5c7
chore: add runtime type validation
0x4007 Dec 13, 2024
0764687
chore: implement ui fixes
kingsley-einstein Dec 13, 2024
0333eaf
chore: implement ui fixes
kingsley-einstein Dec 13, 2024
61d1096
Merge branch 'development' of github.com:kingsley-einstein/uusd.ubq.f…
kingsley-einstein Dec 13, 2024
4302bb4
chore: fix buttons display issue
kingsley-einstein Dec 17, 2024
608ca63
chore: drop slippage requirement
kingsley-einstein Dec 22, 2024
a89eecd
chore: fix issues
kingsley-einstein Dec 26, 2024
7a02d38
chore: fix issues
kingsley-einstein Dec 26, 2024
6e6c30e
chore: disable inputs when in allowance
kingsley-einstein Dec 29, 2024
8d2d31a
chore: remove setInterval polling
kingsley-einstein Dec 30, 2024
8328f62
chore: remove setInterval polling
kingsley-einstein Dec 30, 2024
d849153
chore: made requested updates
kingsley-einstein Jan 14, 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
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir"],
"words": ["dataurl", "devpool", "outdir", "servedir", "viem", "uusd", "ufaucet", "Inpage"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
{ "selector": ["function", "variable"], "format": ["strictCamelCase"] }
]
}
}
}
6 changes: 2 additions & 4 deletions .github/workflows/sync-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Sync branch to template
on:
workflow_dispatch:
schedule:
- cron: '14 0 1 * *'
- cron: "14 0 1 * *"

jobs:
sync:
Expand All @@ -23,7 +23,7 @@ jobs:
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Sync branch to template
env:
GH_TOKEN: ${{ steps.get_installation_token.outputs.token }}
Expand All @@ -45,5 +45,3 @@ jobs:
git commit -m "chore: sync template"
git push "$original_remote" "$pr_branch"
gh pr create --title "Sync branch to template" --body "This pull request merges changes from the template repository." --head "$pr_branch" --base "$branch_name"


9 changes: 3 additions & 6 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import esbuild from "esbuild";
const typescriptEntries = ["static/main.ts"];
// const cssEntries = ["static/style.css"];
const entries = [
...typescriptEntries,
// ...cssEntries
];
const typescriptEntries = ["src/main.ts"];
// const cssEntries = ["static/style/*.css"];
const entries = [...typescriptEntries];

export const esBuildContext: esbuild.BuildOptions = {
sourcemap: true,
Expand Down
2 changes: 1 addition & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default defineConfig({
// implement node event listeners here
},
experimentalStudio: true,
baseUrl: "http://localhost:8080",
baseUrl: "http://localhost:10090",
kingsley-einstein marked this conversation as resolved.
Show resolved Hide resolved
},
});
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"prepare": "husky install",
"test": "jest --setupFiles dotenv/config --coverage",
"cy:open": "cypress open",
"cy:run": "cypress run"
"cy:run": "cypress run",
"tailwind:watch": "npx tailwindcss -i ./static/style/tailwind.css -o ./static/style/style.css --watch"
},
"keywords": [
"typescript",
Expand All @@ -30,7 +31,10 @@
"open-source"
],
"dependencies": {
"dotenv": "^16.4.4"
"@metamask/providers": "^17.2.0",
kingsley-einstein marked this conversation as resolved.
Show resolved Hide resolved
"daisyui": "^4.12.13",
kingsley-einstein marked this conversation as resolved.
Show resolved Hide resolved
"dotenv": "^16.4.4",
"viem": "^2.21.14"
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@commitlint/cli": "^18.6.1",
Expand Down Expand Up @@ -60,6 +64,7 @@
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.14",
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
"ts-jest": "29.1.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
Expand Down
21 changes: 21 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as wallet from "./scripts/connect-wallet";
import * as ui from "./scripts/ui";
import * as mint from "./scripts/mint";

export async function mainModule() {
ui.initUiEvents();

wallet.updateConnectButtonText("");

await wallet.connectIfAuthorized();
await mint.initCollateralList();
kingsley-einstein marked this conversation as resolved.
Show resolved Hide resolved
Copy link

Choose a reason for hiding this comment

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

mint and redeem collateralList is the same, but idk if its worth asking for this change at this point

await mint.initUiEvents();
}

mainModule()
.then(() => {
console.log("mainModule loaded");
})
.catch((error) => {
console.error(error);
});
144 changes: 144 additions & 0 deletions src/scripts/connect-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { createWalletClient, custom } from "viem";
import { mainnet } from "viem/chains";
import { truncateString } from "./utils";
import { connectButtons, connectPrompt, whiteContainer, providersModal } from "./ui";
import { unwatchForPrices, watchForPrices } from "./price-polling";
import { type MetaMaskInpageProvider } from "@metamask/providers";

let client: ReturnType<typeof createWalletClient> | null = null;

type ModifiedWindow = Window &
typeof globalThis & {
ethereum: MetaMaskInpageProvider & {
isCoinbaseWallet: boolean;
isTrust: boolean;
providers?: (MetaMaskInpageProvider & { isCoinbaseWallet: boolean; isTrust: boolean })[];
};
};

export function updateConnectButtonText(text: string, isConnecting: boolean = false) {
let innerHtml = `<span>Connect Wallet</span>`;

if (isConnecting) innerHtml = `<span>Connecting...</span>`;
else if (client !== null) innerHtml = `<span>${text}</span>`;

connectButtons.forEach((connectButton) => {
connectButton.innerHTML = innerHtml;
});
}

export async function connectWallet(providerType: "metamask" | "trust" | "coinbase") {
const ethereum = (window as ModifiedWindow).ethereum;
if (typeof ethereum !== "undefined" && ethereum !== null) {
let provider = ethereum;

if (ethereum.providers?.length) {
switch (providerType) {
case "metamask":
provider = ethereum.providers.find((p) => p.isMetaMask) as typeof ethereum;
break;
case "trust":
provider = ethereum.providers.find((p) => p.isTrust) as typeof ethereum;
break;
case "coinbase":
provider = ethereum.providers.find((p) => p.isCoinbaseWallet) as typeof ethereum;
break;
}
}
try {
updateConnectButtonText("", true);
const accounts = await provider.request<string[]>({ method: "eth_requestAccounts" });
client = createWalletClient({
account: accounts?.[0] as `0x${string}`,
chain: mainnet,
transport: custom(provider),
});

updateConnectButtonText(truncateString(accounts?.[0] as string));
wireEvents(provider);

watchForPrices();

connectPrompt.classList.add("hidden");
whiteContainer.classList.replace("hidden", "flex");

if (providersModal.open) {
providersModal.close();
}
} catch (error) {
updateConnectButtonText("");
}
}
}

export async function disconnectWallet() {
const ethereum = (window as ModifiedWindow).ethereum;
if (typeof ethereum !== "undefined" && ethereum !== null) {
try {
let provider = ethereum;

if (ethereum.providers?.length) {
provider = ethereum.providers.find((p) => p.isCoinbaseWallet || p.isMetaMask || p.isTrust) as typeof ethereum;
}
await provider.request({ method: "wallet_revokePermissions", params: [{ eth_accounts: {} }] });
client = null;

unwatchForPrices();

updateConnectButtonText("Connect Wallet");
connectPrompt.classList.remove("hidden");
whiteContainer.classList.replace("flex", "hidden");
} catch (error) {
updateConnectButtonText("");
}
}
}

export async function connectIfAuthorized() {
const ethereum = (window as ModifiedWindow).ethereum;

let provider = ethereum;

if (ethereum.providers?.length) {
provider = ethereum.providers.find((p) => p.isCoinbaseWallet || p.isMetaMask || p.isTrust) as typeof ethereum;
}

if (provider) {
const accounts = await provider.request<string[]>({ method: "eth_accounts" });

if (accounts && accounts.length) {
const [account] = accounts;
client = createWalletClient({
account: account as `0x${string}`,
chain: mainnet,
transport: custom(provider),
});

watchForPrices();
updateConnectButtonText(truncateString(account as string));
connectPrompt.classList.add("hidden");
whiteContainer.classList.replace("hidden", "flex");
}
}
}

function wireEvents(provider: MetaMaskInpageProvider & { isCoinbaseWallet: boolean; isTrust: boolean }) {
provider.on("accountsChanged", (accounts: unknown) => {
const [account] = accounts as `0x${string}`[];
client = createWalletClient({
account,
chain: mainnet,
transport: custom(provider),
});

updateConnectButtonText(truncateString(account));
});

provider.on("disconnect", () => {
client = null;
});
}

export function getConnectedClient() {
return client;
}
Loading