mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
Use 'const' instead of 'let' and use semicolons
This commit is contained in:
+29
-29
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2019, Ethereum Name Service
|
||||
|
||||
// The random number is a js implementation of the Xorshift PRNG
|
||||
let randseed = new Array(4) // Xorshift: [x, y, z, w] 32 bit values
|
||||
const randseed = new Array(4); // Xorshift: [x, y, z, w] 32 bit values
|
||||
|
||||
function seedrand(seed: string) {
|
||||
for (let i = 0; i < randseed.length; i++) {
|
||||
@@ -15,35 +15,35 @@ function seedrand(seed: string) {
|
||||
|
||||
function rand(): number {
|
||||
// Based on Java's String.hashCode(), expanded to 4 32bit values.
|
||||
let t = randseed[0] ^ (randseed[0] << 11)
|
||||
const t = randseed[0] ^ (randseed[0] << 11);
|
||||
|
||||
randseed[0] = randseed[1]
|
||||
randseed[1] = randseed[2]
|
||||
randseed[2] = randseed[3]
|
||||
randseed[3] = randseed[3] ^ (randseed[3] >> 19) ^ t ^ (t >> 8)
|
||||
randseed[0] = randseed[1];
|
||||
randseed[1] = randseed[2];
|
||||
randseed[2] = randseed[3];
|
||||
randseed[3] = randseed[3] ^ (randseed[3] >> 19) ^ t ^ (t >> 8);
|
||||
|
||||
return (randseed[3] >>> 0) / ((1 << 31) >>> 0)
|
||||
return (randseed[3] >>> 0) / ((1 << 31) >>> 0);
|
||||
}
|
||||
|
||||
function createColor(): string {
|
||||
// Saturation is the whole color spectrum.
|
||||
let h = Math.floor(rand() * 360);
|
||||
const h = Math.floor(rand() * 360);
|
||||
// Saturation goes from 40 to 100, it avoids greyish colors.
|
||||
let s = rand() * 60 + 40 + '%';
|
||||
const s = rand() * 60 + 40 + '%';
|
||||
// Lightness can be anything from 0 to 100, but probabilities are a bell curve around 50%.
|
||||
let l = (rand() + rand() + rand() + rand()) * 25 + '%';
|
||||
const l = (rand() + rand() + rand() + rand()) * 25 + '%';
|
||||
|
||||
return `hsl(${h}, ${s}, ${l})`;
|
||||
}
|
||||
|
||||
function createImageData(size: number): number[] {
|
||||
let width = size;
|
||||
let height = size;
|
||||
const width = size;
|
||||
const height = size;
|
||||
|
||||
let dataWidth = Math.ceil(width / 2);
|
||||
let mirrorWidth = width - dataWidth;
|
||||
const dataWidth = Math.ceil(width / 2);
|
||||
const mirrorWidth = width - dataWidth;
|
||||
|
||||
let data = [];
|
||||
const data = [];
|
||||
for (let y = 0; y < height; y++) {
|
||||
let row = [];
|
||||
for (let x = 0; x < dataWidth; x++) {
|
||||
@@ -51,7 +51,7 @@ function createImageData(size: number): number[] {
|
||||
// spot color has 13% chance
|
||||
row[x] = Math.floor(rand() * 2.3);
|
||||
}
|
||||
let r = row.slice(0, mirrorWidth);
|
||||
const r = row.slice(0, mirrorWidth);
|
||||
r.reverse();
|
||||
row = row.concat(r);
|
||||
|
||||
@@ -70,11 +70,11 @@ function createCanvas(
|
||||
bgcolor: string,
|
||||
spotcolor: string
|
||||
): HTMLCanvasElement {
|
||||
let c = document.createElement('canvas');
|
||||
let width = Math.sqrt(imageData.length);
|
||||
const c = document.createElement('canvas');
|
||||
const width = Math.sqrt(imageData.length);
|
||||
c.width = c.height = width * scale;
|
||||
|
||||
let cc = c.getContext('2d');
|
||||
const cc = c.getContext('2d');
|
||||
|
||||
if (! cc) throw new Error("Can't get 2D context");
|
||||
|
||||
@@ -83,8 +83,8 @@ function createCanvas(
|
||||
cc.fillStyle = color;
|
||||
|
||||
for (let i = 0; i < imageData.length; i++) {
|
||||
let row = Math.floor(i / width);
|
||||
let col = i % width;
|
||||
const row = Math.floor(i / width);
|
||||
const col = i % width;
|
||||
// if data is 2, choose spot color, if 1 choose foreground
|
||||
cc.fillStyle = imageData[i] === 1 ? color : spotcolor;
|
||||
|
||||
@@ -108,18 +108,18 @@ export interface Options {
|
||||
|
||||
export function createIcon(opts: Options) {
|
||||
opts = opts || {};
|
||||
let size = opts.size || 8;
|
||||
let scale = opts.scale || 4;
|
||||
let seed =
|
||||
const size = opts.size || 8;
|
||||
const scale = opts.scale || 4;
|
||||
const seed =
|
||||
opts.seed || Math.floor(Math.random() * Math.pow(10, 16)).toString(16);
|
||||
|
||||
seedrand(seed);
|
||||
|
||||
let color = opts.color || createColor();
|
||||
let bgcolor = opts.bgcolor || createColor();
|
||||
let spotcolor = opts.spotcolor || createColor();
|
||||
let imageData = createImageData(size);
|
||||
let canvas = createCanvas(imageData, color, scale, bgcolor, spotcolor);
|
||||
const color = opts.color || createColor();
|
||||
const bgcolor = opts.bgcolor || createColor();
|
||||
const spotcolor = opts.spotcolor || createColor();
|
||||
const imageData = createImageData(size);
|
||||
const canvas = createCanvas(imageData, color, scale, bgcolor, spotcolor);
|
||||
|
||||
return canvas;
|
||||
}
|
||||
|
||||
+2
-2
@@ -76,8 +76,8 @@ export async function getConfig(): Promise<Config> {
|
||||
// as the provider.
|
||||
const metamask = new ethers.providers.Web3Provider(window.ethereum);
|
||||
const network = await metamask.ready;
|
||||
const provider = alchemyApiKey ?
|
||||
new ethers.providers.AlchemyProvider(network.name, alchemyApiKey)
|
||||
const provider = alchemyApiKey
|
||||
? new ethers.providers.AlchemyProvider(network.name, alchemyApiKey)
|
||||
: metamask;
|
||||
|
||||
config = new Config(network, provider, metamask.getSigner());
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
let app = new App({
|
||||
const app = new App({
|
||||
target: document.body,
|
||||
});
|
||||
|
||||
|
||||
+8
-8
@@ -30,22 +30,22 @@ export interface Session {
|
||||
}
|
||||
|
||||
export const loadState = (initial: State) => {
|
||||
const store = writable<State>(initial)
|
||||
const store = writable<State>(initial);
|
||||
|
||||
const session = window.localStorage.getItem("session");
|
||||
if (session) store.set({ connection: Connection.Connected, session: JSON.parse(session) })
|
||||
if (session) store.set({ connection: Connection.Connected, session: JSON.parse(session) });
|
||||
|
||||
return {
|
||||
subscribe: store.subscribe,
|
||||
connect: async (config: Config) => {
|
||||
let state = get(store);
|
||||
const state = get(store);
|
||||
|
||||
assertEq(state.connection, Connection.Disconnected);
|
||||
store.set({ connection: Connection.Connecting });
|
||||
|
||||
// TODO: This hangs on Brave, if you have to unlock your wallet..
|
||||
try {
|
||||
let accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
||||
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ export const loadState = (initial: State) => {
|
||||
},
|
||||
|
||||
refreshBalance: async (config: Config) => {
|
||||
let state = get(store);
|
||||
const state = get(store);
|
||||
assert(state.connection === Connection.Connected);
|
||||
const addr = state.session.address;
|
||||
|
||||
@@ -155,13 +155,13 @@ export const loadState = (initial: State) => {
|
||||
if (address === undefined) disconnectWallet();
|
||||
else {
|
||||
s.session.address = address;
|
||||
window.localStorage.setItem("session", JSON.stringify({ address, tokenBalance: s.session.tokenBalance, tx: s.session.tx }))
|
||||
window.localStorage.setItem("session", JSON.stringify({ address, tokenBalance: s.session.tokenBalance, tx: s.session.tx }));
|
||||
}
|
||||
return s;
|
||||
default:
|
||||
return s;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -191,7 +191,7 @@ export async function approveSpender(spender: string, amount: BigNumber, config:
|
||||
const allowance = await token.allowance(addr, spender);
|
||||
|
||||
if (allowance < amount) {
|
||||
let tx = await token.connect(signer).approve(spender, amount);
|
||||
const tx = await token.connect(signer).approve(spender, amount);
|
||||
await tx.wait();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -39,8 +39,8 @@ export function capitalize(s: string) {
|
||||
// Takes a domain name, eg. 'cloudhead.radicle.eth' and
|
||||
// returns the label, eg. 'cloudhead', otherwise `null`.
|
||||
export function parseEnsLabel(name: string, config: Config): string {
|
||||
let domain = config.registrar.domain.replace(".", "\\.");
|
||||
let label = name.replace(new RegExp(`\\.${domain}$`), "");
|
||||
const domain = config.registrar.domain.replace(".", "\\.");
|
||||
const label = name.replace(new RegExp(`\\.${domain}$`), "");
|
||||
|
||||
return label;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export function isAddress(input: string): boolean {
|
||||
|
||||
// Get search parameters from location.
|
||||
export function getSearchParam(key: string, location: RouteLocation): string | null {
|
||||
let params = new URLSearchParams(location.search);
|
||||
const params = new URLSearchParams(location.search);
|
||||
return params.get(key);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ export async function querySubgraph(
|
||||
const json = await response.json();
|
||||
|
||||
if (json.errors) {
|
||||
for (let e of json.errors) {
|
||||
for (const e of json.errors) {
|
||||
console.error("querySubgraph:", e.message);
|
||||
}
|
||||
return null;
|
||||
@@ -142,13 +142,13 @@ export function formatProjectHash(hash: Uint8Array, format: number): string {
|
||||
|
||||
// Identify an address by checking whether it's a contract or an externally-owned address.
|
||||
export async function identifyAddress(address: string, config: Config): Promise<AddressType> {
|
||||
let safe = await getSafe(address, config);
|
||||
const safe = await getSafe(address, config);
|
||||
if (safe) {
|
||||
return AddressType.Safe;
|
||||
}
|
||||
|
||||
let code = await config.provider.getCode(address);
|
||||
let bytes = ethers.utils.arrayify(code);
|
||||
const code = await config.provider.getCode(address);
|
||||
const bytes = ethers.utils.arrayify(code);
|
||||
|
||||
if (bytes.length > 0) {
|
||||
if (ethers.utils.keccak256(bytes) === config.orgs.contractHash) {
|
||||
|
||||
Reference in New Issue
Block a user