{formatRadicleUrn(project.info.urn)}
@@ -68,7 +67,7 @@
{#each results.profiles as profile}
-
-
+
{/each}
diff --git a/src/config.json b/src/config.json
index c602aa06c..c1106882f 100644
--- a/src/config.json
+++ b/src/config.json
@@ -1,60 +1,15 @@
{
- "homestead": {
- "registrar": {
- "domain": "radicle.eth",
- "address": "0x37723287Ae6F34866d82EE623401f92Ec9013154"
- },
- "radToken": {
- "address": "0x31c8EAcBFFdD875c74b94b077895Bd78CF1E64A3"
- },
- "users": {
- "pinned": ["cloudhead.radicle.eth"]
- },
- "reverseRegistrar": {
- "address": "0x084b1c3C81545d370f3634392De611CaaBFf8148"
- },
- "tokens": [],
- "alchemy": { "key": "cQFlLK8EokIGlJhd_soImwEyUoC7Ec8r" }
- },
- "goerli": {
- "registrar": {
- "domain": "radicle-goerli.eth",
- "address": "0xD88303A92577bFDF5A82FddeF342F3A27A972405"
- },
- "radToken": {
- "address": "0x3EE94D192397aAFAe438C9803825eb1Aa4402e09",
- "faucet": "0xc627191d2BB8839eAcbb7191f9500B84d201A066"
- },
- "users": {
- "pinned": []
- },
- "reverseRegistrar": {
- "address": "0xD5610A08E370051a01fdfe4bB3ddf5270af1aA48"
- },
- "tokens": [],
- "alchemy": { "key": "1T6h-0rxu7SRzKEtmukIoxaJOXazLDNs" }
- },
"walletConnect": { "bridge": "https://radicle.bridge.walletconnect.org" },
"reactions": ["👍", "👎", "😄", "🎉", "🙁", "🚀", "👀"],
- "radicle": {
- "seed": {
- "api": { "port": 8777 },
- "link": { "port": 8776 },
- "git": { "port": 443 }
- }
- },
"seeds": {
- "pinned": {
- "willow.radicle.garden": {
+ "pinned": [
+ {
+ "host": "willow.radicle.garden",
"emoji": "🪵"
},
- "pine.radicle.garden": {
- "emoji": "🌲"
- },
- "maple.radicle.garden": {
- "emoji": "🍁"
- }
- }
+ { "host": "pine.radicle.garden", "emoji": "🌲" },
+ { "host": "maple.radicle.garden", "emoji": "🍁" }
+ ]
},
"projects": {
"pinned": [
@@ -119,54 +74,5 @@
"seed": "pine.radicle.garden"
}
]
- },
- "ipfs": { "gateway": "https://ipfs.io/ipfs/" },
- "abi": {
- "registrar": [
- "function rad() view returns (address)",
- "function radNode() view returns (bytes32)",
- "function minCommitmentAge() view returns (uint256)",
- "function registrationFeeRad() view returns (uint256)",
- "function commit(bytes32)",
- "function commitWithPermit(bytes32, address, uint256, uint256, uint8, bytes32, bytes32)",
- "function register(string, address, uint256)",
- "function valid(string) pure returns (bool)",
- "function available(string) view returns (bool)"
- ],
- "token": [
- "function balanceOf(address) view returns (uint256)",
- "function approve(address, uint256) returns (bool)",
- "function allowance(address, address) view returns (uint256)",
- "function DOMAIN_SEPARATOR() view returns (bytes32)",
- "function name() pure returns (string)",
- "function symbol() pure returns (string)",
- "function nonces(address) view returns (uint256)"
- ],
- "resolver": [
- "function multicall(bytes[] calldata data) returns(bytes[] memory results)",
- "function setAddr(bytes32 node, address addr)",
- "function setText(bytes32 node, string calldata key, string calldata value)"
- ],
- "reverseRegistrar": ["function setName(string) returns (bytes32)"],
- "org": ["function owner() view returns (address)"],
- "vesting": [
- "function token() view returns (address)",
- "function totalVestingAmount() view returns (uint256)",
- "function vestingStartTime() view returns (uint256)",
- "function vestingPeriod() view returns (uint256)",
- "function cliffPeriod() view returns (uint256)",
- "function beneficiary() view returns (address)",
- "function interrupted() view returns (bool)",
- "function withdrawn() view returns (uint256)",
- "function withdrawableBalance() view returns (uint256)",
- "function withdrawVested()"
- ],
- "faucet": [
- "function lastWithdrawalByUser(address) view returns (uint256)",
- "function maxWithdrawAmount() view returns (uint256)",
- "function calculateTimeLock(uint256) view returns (uint256)",
- "function withdraw(address, uint256)"
- ],
- "ens": ["function owner(bytes32 node) view returns (address)"]
}
}
diff --git a/src/ens/SetName.svelte b/src/ens/SetName.svelte
index e7fcac16a..279030aa2 100644
--- a/src/ens/SetName.svelte
+++ b/src/ens/SetName.svelte
@@ -2,7 +2,7 @@
import { createEventDispatcher } from "svelte";
import { navigate } from "svelte-routing";
import Modal from "@app/Modal.svelte";
- import type { Config } from "@app/config";
+ import type { Wallet } from "@app/wallet";
import { formatAddress, isAddressEqual } from "@app/utils";
import type { User } from "@app/base/users/User";
import ErrorModal from "@app/ErrorModal.svelte";
@@ -13,7 +13,7 @@
const dispatch = createEventDispatcher();
export let entity: User;
- export let config: Config;
+ export let wallet: Wallet;
enum State {
Idle,
@@ -37,13 +37,13 @@
}
state = State.Checking;
- const domain = `${name}.${config.registrar.domain}`;
- const resolved = await config.provider.resolveName(domain);
+ const domain = `${name}.${wallet.registrar.domain}`;
+ const resolved = await wallet.provider.resolveName(domain);
if (resolved && isAddressEqual(resolved, entity.address)) {
try {
state = State.Signing;
- const tx = await entity.setName(domain, config);
+ const tx = await entity.setName(domain, wallet);
state = State.Pending;
await tx.wait();
state = State.Success;
@@ -78,7 +78,7 @@
The ENS name for {entity.address} was set to
- {name}.{config.registrar.domain}
+ {name}.{wallet.registrar.domain}
.
@@ -90,11 +90,11 @@
{:else if state === State.Mismatch}
- The name {name}.{config.registrar.domain}
+ The name {name}.{wallet.registrar.domain}
does not resolve to
{entity.address}
- . Please update the ENS record for {name}.{config.registrar.domain} to point
- to the correct address and try again.
+ . Please update the ENS record for {name}.{wallet.registrar.domain} to to the
+ correct address and try again.
diff --git a/src/ethereum/contractAbis.json b/src/ethereum/contractAbis.json
new file mode 100644
index 000000000..630ea0d34
--- /dev/null
+++ b/src/ethereum/contractAbis.json
@@ -0,0 +1,48 @@
+{
+ "ens": ["function owner(bytes32 node) view returns (address)"],
+ "faucet": [
+ "function lastWithdrawalByUser(address) view returns (uint256)",
+ "function maxWithdrawAmount() view returns (uint256)",
+ "function calculateTimeLock(uint256) view returns (uint256)",
+ "function withdraw(address, uint256)"
+ ],
+ "org": ["function owner() view returns (address)"],
+ "registrar": [
+ "function rad() view returns (address)",
+ "function radNode() view returns (bytes32)",
+ "function minCommitmentAge() view returns (uint256)",
+ "function registrationFeeRad() view returns (uint256)",
+ "function commit(bytes32)",
+ "function commitWithPermit(bytes32, address, uint256, uint256, uint8, bytes32, bytes32)",
+ "function register(string, address, uint256)",
+ "function valid(string) pure returns (bool)",
+ "function available(string) view returns (bool)"
+ ],
+ "resolver": [
+ "function multicall(bytes[] calldata data) returns(bytes[] memory results)",
+ "function setAddr(bytes32 node, address addr)",
+ "function setText(bytes32 node, string calldata key, string calldata value)"
+ ],
+ "reverseRegistrar": ["function setName(string) returns (bytes32)"],
+ "token": [
+ "function balanceOf(address) view returns (uint256)",
+ "function approve(address, uint256) returns (bool)",
+ "function allowance(address, address) view returns (uint256)",
+ "function DOMAIN_SEPARATOR() view returns (bytes32)",
+ "function name() pure returns (string)",
+ "function symbol() pure returns (string)",
+ "function nonces(address) view returns (uint256)"
+ ],
+ "vesting": [
+ "function token() view returns (address)",
+ "function totalVestingAmount() view returns (uint256)",
+ "function vestingStartTime() view returns (uint256)",
+ "function vestingPeriod() view returns (uint256)",
+ "function cliffPeriod() view returns (uint256)",
+ "function beneficiary() view returns (address)",
+ "function interrupted() view returns (bool)",
+ "function withdrawn() view returns (uint256)",
+ "function withdrawableBalance() view returns (uint256)",
+ "function withdrawVested()"
+ ]
+}
diff --git a/src/ethereum/networks/goerli.json b/src/ethereum/networks/goerli.json
new file mode 100644
index 000000000..205f0ba27
--- /dev/null
+++ b/src/ethereum/networks/goerli.json
@@ -0,0 +1,16 @@
+{
+ "name": "goerli",
+ "chainId": 5,
+ "registrar": {
+ "domain": "radicle-goerli.eth",
+ "address": "0xD88303A92577bFDF5A82FddeF342F3A27A972405"
+ },
+ "radToken": {
+ "address": "0x3EE94D192397aAFAe438C9803825eb1Aa4402e09",
+ "faucet": "0xc627191d2BB8839eAcbb7191f9500B84d201A066"
+ },
+ "reverseRegistrar": {
+ "address": "0xD5610A08E370051a01fdfe4bB3ddf5270af1aA48"
+ },
+ "alchemy": { "key": "1T6h-0rxu7SRzKEtmukIoxaJOXazLDNs" }
+}
diff --git a/src/ethereum/networks/homestead.json b/src/ethereum/networks/homestead.json
new file mode 100644
index 000000000..185aa9057
--- /dev/null
+++ b/src/ethereum/networks/homestead.json
@@ -0,0 +1,15 @@
+{
+ "name": "homestead",
+ "chainId": 1,
+ "registrar": {
+ "domain": "radicle.eth",
+ "address": "0x37723287Ae6F34866d82EE623401f92Ec9013154"
+ },
+ "radToken": {
+ "address": "0x31c8EAcBFFdD875c74b94b077895Bd78CF1E64A3"
+ },
+ "reverseRegistrar": {
+ "address": "0x084b1c3C81545d370f3634392De611CaaBFf8148"
+ },
+ "alchemy": { "key": "cQFlLK8EokIGlJhd_soImwEyUoC7Ec8r" }
+}
diff --git a/src/profile.ts b/src/profile.ts
index f1a9b8987..bc65840e9 100644
--- a/src/profile.ts
+++ b/src/profile.ts
@@ -7,7 +7,7 @@ import {
identifyAddress,
isFulfilled,
} from "@app/utils";
-import type { Config } from "@app/config";
+import type { Wallet } from "@app/wallet";
import { cached } from "@app/cache";
import type { Seed, InvalidSeed } from "@app/base/seeds/Seed";
import { Org } from "@app/base/orgs/Org";
@@ -107,18 +107,18 @@ export class Profile {
private static async lookupProfile(
addressOrName: string,
profileType: ProfileType,
- config: Config,
+ wallet: Wallet,
): Promise {
let type = AddressType.EOA;
let org: Org | null = null;
- const ens = await resolveEnsProfile(addressOrName, profileType, config);
+ const ens = await resolveEnsProfile(addressOrName, profileType, wallet);
if (ens) {
if (ens.address) {
- type = await identifyAddress(ens.address, config);
+ type = await identifyAddress(ens.address, wallet);
if (type === AddressType.Org) {
- org = await Org.get(ens.address, config);
+ org = await Org.get(ens.address, wallet);
}
return {
@@ -132,9 +132,9 @@ export class Profile {
} else if (isAddress(addressOrName)) {
const address = addressOrName.toLowerCase();
- type = await identifyAddress(address, config);
+ type = await identifyAddress(address, wallet);
if (type === AddressType.Org) {
- org = await Org.get(address, config);
+ org = await Org.get(address, wallet);
}
try {
@@ -154,10 +154,10 @@ export class Profile {
static async getMulti(
addressesOrNames: string[],
- config: Config,
+ wallet: Wallet,
): Promise {
const profilePromises = addressesOrNames.map(addressOrName =>
- this.lookupProfile(addressOrName, ProfileType.Minimal, config),
+ this.lookupProfile(addressOrName, ProfileType.Minimal, wallet),
);
const profiles = await Promise.allSettled(profilePromises);
return profiles
@@ -168,20 +168,20 @@ export class Profile {
static async get(
addressOrName: string,
profileType: ProfileType,
- config: Config,
+ wallet: Wallet,
): Promise {
const profile = await this.lookupProfile(
addressOrName,
profileType,
- config,
+ wallet,
);
return new Profile(profile);
}
}
export const getBalance = cached(
- async (address: string, config: Config) => {
- return await config.provider.getBalance(address);
+ async (address: string, wallet: Wallet) => {
+ return await wallet.provider.getBalance(address);
},
address => address,
{ max: 1000 },
diff --git a/src/project.ts b/src/project.ts
index 80f9a3c75..fa036fb1d 100644
--- a/src/project.ts
+++ b/src/project.ts
@@ -5,7 +5,7 @@ import type { Commit, CommitHeader, CommitsHistory } from "@app/commit";
import { isFulfilled, isOid, isRadicleId } from "@app/utils";
import { Profile, ProfileType } from "@app/profile";
import { Seed } from "@app/base/seeds/Seed";
-import type { Config } from "@app/config";
+import type { Wallet } from "@app/wallet";
export type Urn = string;
export type PeerId = string;
@@ -441,15 +441,15 @@ export class Project implements ProjectInfo {
peer: string | null,
profileName: string | null,
seedHost: string | null,
- config: Config,
+ wallet: Wallet,
): Promise {
const profile = profileName
- ? await Profile.get(profileName, ProfileType.Project, config)
+ ? await Profile.get(profileName, ProfileType.Project, wallet)
: null;
const seed = profile
? profile.seed
: seedHost
- ? await Seed.lookup(seedHost, config)
+ ? await Seed.lookup(seedHost)
: null;
if (!profile && !seed) {
diff --git a/src/session.ts b/src/session.ts
index 74b356066..8d6891765 100644
--- a/src/session.ts
+++ b/src/session.ts
@@ -5,7 +5,7 @@ import type {
TransactionReceipt,
TransactionResponse,
} from "@ethersproject/providers";
-import { Config, getConfig } from "@app/config";
+import { Wallet, getWallet } from "@app/wallet";
import { Unreachable, assert, assertEq } from "@app/error";
import type { TypedDataSigner } from "@ethersproject/abstract-signer";
import type { WalletConnectSigner } from "./WalletConnectSigner";
@@ -55,11 +55,11 @@ export interface Session {
}
export interface Store extends Readable {
- connectMetamask(config: Config): Promise;
- connectWalletConnect(config: Config): Promise;
+ connectMetamask(wallet: Wallet): Promise;
+ connectWalletConnect(wallet: Wallet): Promise;
updateBalance(n: BigNumber): void;
connectSeed(seed: { id: string; session: SeedSession }): void;
- refreshBalance(config: Config): Promise;
+ refreshBalance(wallet: Wallet): Promise;
setTxSigning(): void;
setTxPending(tx: TransactionResponse): void;
setTxConfirmed(tx: TransactionReceipt): void;
@@ -73,15 +73,15 @@ export const loadState = (initial: State): Store => {
return {
subscribe: store.subscribe,
- connectMetamask: async (config: Config) => {
- assert(config.metamask.signer);
- // We use config.metamask.signer here, because config.signer is still null on page reload.
- const signer = config.metamask.signer;
+ connectMetamask: async (wallet: Wallet) => {
+ assert(wallet.metamask.signer);
+ // We use wallet.metamask.signer here, because wallet.signer is still null on page reload.
+ const signer = wallet.metamask.signer;
// Re-connect using previous session.
- if (config.metamask.connected) {
- const metamask = config.metamask.session;
- const tokenBalance: BigNumber = await config.token.balanceOf(
+ if (wallet.metamask.connected) {
+ const metamask = wallet.metamask.session;
+ const tokenBalance: BigNumber = await wallet.token.balanceOf(
metamask.address,
);
const session = {
@@ -94,7 +94,7 @@ export const loadState = (initial: State): Store => {
};
store.set({ connection: Connection.Connected, session });
- config.setSigner(signer);
+ wallet.setSigner(signer);
return;
}
@@ -110,14 +110,14 @@ export const loadState = (initial: State): Store => {
await window.ethereum.request({ method: "eth_requestAccounts" });
const address = await signer.getAddress();
- config.setSigner(signer);
+ wallet.setSigner(signer);
try {
// Closes the wallet modal.
// TODO: We should move this into the session store.
- config.walletConnect.state.set({ state: "close" });
+ wallet.walletConnect.state.set({ state: "close" });
- const tokenBalance: BigNumber = await config.token.balanceOf(address);
+ const tokenBalance: BigNumber = await wallet.token.balanceOf(address);
const session = {
address,
signer,
@@ -137,17 +137,17 @@ export const loadState = (initial: State): Store => {
}
},
- connectWalletConnect: async (config: Config) => {
+ connectWalletConnect: async (wallet: Wallet) => {
store.set({ connection: Connection.Connecting });
- // We fetch the walletConnect signer here, because config.signer is still null on page reload.
- const signer = config.getWalletConnectSigner();
+ // We fetch the walletConnect signer here, because wallet.signer is still null on page reload.
+ const signer = wallet.getWalletConnectSigner();
try {
- await config.walletConnect.client.connect();
+ await wallet.walletConnect.client.connect();
console.debug("WalletConnect: connected.");
const address = await signer.getAddress();
- const tokenBalance: BigNumber = await config.token.balanceOf(address);
+ const tokenBalance: BigNumber = await wallet.token.balanceOf(address);
const session = {
address,
signer,
@@ -161,11 +161,11 @@ export const loadState = (initial: State): Store => {
);
// Instead of killing the WalletConnect session, we force the UI to change network
- if (network.chainId !== config.network.chainId) {
- config.changeNetwork(network.chainId);
+ if (network.chainId !== wallet.network.chainId) {
+ wallet.changeNetwork(network.chainId);
}
- config.walletConnect.client.on(
+ wallet.walletConnect.client.on(
"session_update",
async (
error,
@@ -178,12 +178,12 @@ export const loadState = (initial: State): Store => {
}
try {
- // We update config to reflect the new signer address.
- const signer = config.getWalletConnectSigner();
+ // We update wallet to reflect the new signer address.
+ const signer = wallet.getWalletConnectSigner();
changeAccounts(accounts[0], signer);
// Check the current chainId, and request Metamask to change, or reload the window to get the correct chain.
- if (chainId !== config.network.chainId) {
+ if (chainId !== wallet.network.chainId) {
if (session.signerType === SignerType.MetaMask) {
await window.ethereum.request({
method: "wallet_switchEthereumChain",
@@ -242,13 +242,13 @@ export const loadState = (initial: State): Store => {
});
},
- refreshBalance: async (config: Config) => {
+ refreshBalance: async (wallet: Wallet) => {
const state = get(store);
assert(state.connection === Connection.Connected);
const addr = state.session.address;
try {
- const tokenBalance: BigNumber = await config.token.balanceOf(addr);
+ const tokenBalance: BigNumber = await wallet.token.balanceOf(addr);
state.session.tokenBalance = tokenBalance;
store.set(state);
@@ -371,9 +371,9 @@ export async function changeAccounts(
address: string,
signer: Signer,
): Promise {
- const config = await getConfig();
+ const wallet = await getWallet();
state.setChangedAccount(address, signer);
- state.refreshBalance(config);
+ state.refreshBalance(wallet);
}
export function loadSeedSessions(): { [key: string]: SeedSession } {
@@ -411,17 +411,17 @@ state.subscribe(s => {
export async function approveSpender(
spender: string,
amount: BigNumber,
- config: Config,
+ wallet: Wallet,
): Promise {
- assert(config.signer);
+ assert(wallet.signer);
- const signer = config.signer;
+ const signer = wallet.signer;
const addr = await signer.getAddress();
- const allowance = await config.token.allowance(addr, spender);
+ const allowance = await wallet.token.allowance(addr, spender);
if (allowance < amount) {
- const tx = await config.token.connect(signer).approve(spender, amount);
+ const tx = await wallet.token.connect(signer).approve(spender, amount);
await tx.wait();
}
}
@@ -431,9 +431,9 @@ export function disconnectMetamask(): void {
window.location.reload();
}
-export function disconnectWallet(config: Config): void {
- if (config.walletConnect.client.connected) {
- config.walletConnect.client.killSession();
+export function disconnectWallet(wallet: Wallet): void {
+ if (wallet.walletConnect.client.connected) {
+ wallet.walletConnect.client.killSession();
}
disconnectMetamask();
}
@@ -449,7 +449,7 @@ function saveMetamaskSession(session: Session): void {
address: session.address,
tokenBalance: null,
tx: null,
- config: null,
+ wallet: null,
}),
);
}
diff --git a/src/siwe.ts b/src/siwe.ts
index 2c68e4aea..ad78d45d0 100644
--- a/src/siwe.ts
+++ b/src/siwe.ts
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { SiweMessage } from "siwe";
import { Request, type Host } from "@app/api";
-import type { Config } from "@app/config";
+import type { Wallet } from "@app/wallet";
import { connectSeed } from "@app/session";
import type { Seed } from "@app/base/seeds/Seed";
@@ -22,7 +22,7 @@ export function createSiweMessage(
seed: Seed,
address: string,
nonce: string,
- config: Config,
+ wallet: Wallet,
): string {
const nextWeek = new Date();
nextWeek.setDate(nextWeek.getDate() + 7);
@@ -35,7 +35,7 @@ export function createSiweMessage(
nonce,
version: "1",
expirationTime: nextWeek.toISOString(),
- chainId: config.network.chainId,
+ chainId: wallet.network.chainId,
});
return message.prepareMessage();
@@ -50,16 +50,16 @@ export async function createUnauthorizedSession(
/// Signs the user into given seed and returns when successfull a session id
export async function signInWithEthereum(
seed: Seed,
- config: Config,
+ wallet: Wallet,
): Promise<{ id: string } | null> {
- if (!config.signer) {
+ if (!wallet.signer) {
return null;
}
- const address = await config.signer.getAddress();
+ const address = await wallet.signer.getAddress();
const result = await createUnauthorizedSession(seed.api);
- const message = createSiweMessage(seed, address, result.nonce, config);
- const signature = await config.signer.signMessage(message);
+ const message = createSiweMessage(seed, address, result.nonce, wallet);
+ const signature = await wallet.signer.signMessage(message);
const auth: {
id: string;
diff --git a/src/utils.test.ts b/src/utils.test.ts
index d5e1dbb79..7932d6780 100644
--- a/src/utils.test.ts
+++ b/src/utils.test.ts
@@ -1,6 +1,7 @@
+import type { Wallet } from "@app/wallet";
+
import { BigNumber } from "ethers";
import { describe, expect, test } from "vitest";
-import type { Config } from "./config";
import * as utils from "./utils";
describe("Conversions", () => {
@@ -174,7 +175,7 @@ describe("Others", () => {
network: {
name,
},
- } as Config),
+ } as Wallet),
).toEqual(expected);
});
});
@@ -190,7 +191,7 @@ describe("Parse Strings", () => {
address: "0x1234567890123456789012345678901234567890",
domain: "radicle.eth",
},
- } as Config),
+ } as Wallet),
).toEqual(expected);
});
diff --git a/src/utils.ts b/src/utils.ts
index 2cc948fdc..fe1493748 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -3,7 +3,7 @@ import type { RouteLocation } from "@app/index";
import md5 from "md5";
import { BigNumber } from "ethers";
import katex from "katex";
-import type { Config } from "@app/config";
+import type { Wallet } from "@app/wallet";
import { assert } from "@app/error";
import type { EnsProfile } from "@app/base/registrations/registrar";
import { getAddress, getResolver } from "@app/base/registrations/registrar";
@@ -17,6 +17,7 @@ import { parseUnits } from "@ethersproject/units";
import * as cache from "@app/cache";
import type { marked } from "marked";
import emojis from "@app/emojis";
+import config from "@app/config.json";
export enum AddressType {
Contract,
@@ -48,9 +49,9 @@ export type State =
export async function isReverseRecordSet(
address: string,
domain: string,
- config: Config,
+ wallet: Wallet,
): Promise {
- const name = await lookupAddress(address, config);
+ const name = await lookupAddress(address, wallet);
return name === domain;
}
@@ -128,11 +129,11 @@ export function formatCommit(oid: string): string {
return oid.substring(0, 7);
}
-export function formatProfile(input: string, config: Config): string {
+export function formatProfile(input: string, wallet: Wallet): string {
if (isAddress(input)) {
return ethers.utils.getAddress(input);
} else {
- return parseEnsLabel(input, config);
+ return parseEnsLabel(input, wallet);
}
}
@@ -142,8 +143,8 @@ export function capitalize(s: string): string {
}
// Takes a domain name, eg. 'cloudhead.radicle.eth' and returns the label, eg. 'cloudhead'.
-export function parseEnsLabel(name: string, config: Config): string {
- const domain = config.registrar.domain.replace(".", "\\.");
+export function parseEnsLabel(name: string, wallet: Wallet): string {
+ const domain = wallet.registrar.domain.replace(".", "\\.");
const label = name.replace(new RegExp(`\\.${domain}$`), "");
return label;
@@ -264,8 +265,8 @@ export function isUrl(input: string): boolean {
return /^https?:\/\//.test(input);
}
-export function isENSName(input: string, config: Config): boolean {
- const domain = config.registrar.domain.replace(".", "\\.");
+export function isENSName(input: string, wallet: Wallet): boolean {
+ const domain = wallet.registrar.domain.replace(".", "\\.");
const regEx = new RegExp(`^[a-zA-Z0-9]+.(${domain}|eth)$`);
return regEx.test(input);
}
@@ -291,16 +292,16 @@ export function getSearchParam(
}
// Get the explorer link of an address, eg. Etherscan.
-export function explorerLink(addr: string, config: Config): string {
- if (config.network.name === "goerli") {
+export function explorerLink(addr: string, wallet: Wallet): string {
+ if (wallet.network.name === "goerli") {
return `https://goerli.etherscan.io/address/${addr}`;
}
return `https://etherscan.io/address/${addr}`;
}
// Format a name.
-export function formatName(input: string, config: Config): string {
- return parseEnsLabel(input, config);
+export function formatName(input: string, wallet: Wallet): string {
+ return parseEnsLabel(input, wallet);
}
// Parse a Radicle Id (URN).
@@ -321,22 +322,24 @@ export function parseEmoji(input: string): string {
return input;
}
-// Fetch from config the emoji to the corresponding pinned seed, if non found return default emoji
-// @dev: This helper fn lets us get a seed emoji quick without multiLookups or complex type usage.
-// TODO: Should be revisited, when we have a stable implementation for seed avatars.
-export function getSeedEmoji(input: string, config: Config): string {
- if (config.seeds.pinned[input]) {
- return config.seeds.pinned[input].emoji;
+export function getSeedEmoji(seedHost: string): string {
+ const seed = config.seeds.pinned.find(s => s.host === seedHost);
+
+ if (seed) {
+ return seed.emoji;
+ } else if (isLocal(seedHost)) {
+ return "🏠";
+ } else {
+ return "🌱";
}
- return "🌱";
}
// Identify an address by checking whether it's a contract or an externally-owned address.
export async function identifyAddress(
address: string,
- config: Config,
+ wallet: Wallet,
): Promise {
- const code = await getCode(address, config);
+ const code = await getCode(address, wallet);
const bytes = ethers.utils.arrayify(code);
if (bytes.length > 0) {
@@ -349,25 +352,25 @@ export async function identifyAddress(
export async function resolveEnsProfile(
addressOrName: string,
profileType: ProfileType,
- config: Config,
+ wallet: Wallet,
): Promise {
const name = ethers.utils.isAddress(addressOrName)
- ? await lookupAddress(addressOrName, config)
+ ? await lookupAddress(addressOrName, wallet)
: addressOrName;
if (name) {
- const resolver = await getResolver(name, config);
+ const resolver = await getResolver(name, wallet);
if (!resolver) {
return null;
}
if (profileType === ProfileType.Full) {
- const registration = await getRegistration(name, config, resolver);
+ const registration = await getRegistration(name, wallet, resolver);
if (registration) {
return registration.profile;
}
} else {
- const promises: [Promise] = [getAvatar(name, config, resolver)];
+ const promises: [Promise] = [getAvatar(name, wallet, resolver)];
if (addressOrName === name) {
promises.push(getAddress(resolver));
@@ -376,7 +379,7 @@ export async function resolveEnsProfile(
}
if (profileType === ProfileType.Project) {
- promises.push(getSeed(name, config, resolver));
+ promises.push(getSeed(name, wallet, resolver));
} else if (profileType === ProfileType.Minimal) {
promises.push(Promise.resolve(null));
}
@@ -401,12 +404,12 @@ export async function resolveEnsProfile(
// Get token balances for an address.
export async function getTokens(
address: string,
- config: Config,
+ wallet: Wallet,
): Promise> {
const userBalances = await getRpcMethod(
"alchemy_getTokenBalances",
[address, "DEFAULT_TOKENS"],
- config,
+ wallet,
);
const balances = userBalances.tokenBalances
.filter((token: any) => {
@@ -421,7 +424,7 @@ export async function getTokens(
const tokenMetaData = await getRpcMethod(
"alchemy_getTokenMetadata",
[token.contractAddress],
- config,
+ wallet,
);
return { ...tokenMetaData, balance: BigNumber.from(token.tokenBalance) };
});
@@ -430,8 +433,8 @@ export async function getTokens(
}
export const getRpcMethod = cache.cached(
- async (method: string, props: string[], config: Config) => {
- return await config.provider.send(method, props);
+ async (method: string, props: string[], wallet: Wallet) => {
+ return await wallet.provider.send(method, props);
},
(method, props) => JSON.stringify([method, props]),
{ ttl: 2 * 60 * 1000, max: 1000 },
@@ -465,16 +468,16 @@ export function gravatarURL(email: string): string {
}
export const getCode = cache.cached(
- async (address: string, config: Config) => {
- return await config.provider.getCode(address);
+ async (address: string, wallet: Wallet) => {
+ return await wallet.provider.getCode(address);
},
address => address,
{ max: 1000 },
);
export const lookupAddress = cache.cached(
- async (address: string, config: Config) => {
- return await config.provider.lookupAddress(address);
+ async (address: string, wallet: Wallet) => {
+ return await wallet.provider.lookupAddress(address);
},
address => address,
{ max: 1000 },
diff --git a/src/config.ts b/src/wallet.ts
similarity index 76%
rename from src/config.ts
rename to src/wallet.ts
index ac77687cc..60957eb5d 100644
--- a/src/config.ts
+++ b/src/wallet.ts
@@ -1,11 +1,33 @@
-import { get, writable } from "svelte/store";
-import type { Writable } from "svelte/store";
-import { ethers } from "ethers";
import type { TypedDataSigner } from "@ethersproject/abstract-signer";
+import type { Writable } from "svelte/store";
+
import WalletConnect from "@walletconnect/client";
-import config from "@app/config.json";
-import { WalletConnectSigner } from "./WalletConnectSigner";
+import { ethers } from "ethers";
+import { get, writable } from "svelte/store";
+
+import { WalletConnectSigner } from "@app/WalletConnectSigner";
import { capitalize } from "@app/utils";
+import ethereumContractAbis from "@app/ethereum/contractAbis.json";
+import homestead from "@app/ethereum/networks/homestead.json";
+import goerli from "@app/ethereum/networks/goerli.json";
+import config from "@app/config.json";
+
+interface NetworkConfig {
+ name: string;
+ chainId: number;
+ registrar: {
+ domain: string;
+ address: string;
+ };
+ radToken: {
+ address: string;
+ faucet?: string;
+ };
+ reverseRegistrar: {
+ address: string;
+ };
+ alchemy: { key: string };
+}
declare global {
interface Window {
@@ -20,14 +42,11 @@ export type WalletConnectState =
| { state: "close" }
| { state: "open"; uri: string; onClose: any };
-export class Config {
+export class Wallet {
network: { name: string; chainId: number };
registrar: { address: string; domain: string };
- radToken: { address: string; faucet: string };
+ radToken: { address: string; faucet?: string };
reverseRegistrar: { address: string };
- users: { pinned: string[] };
- projects: { pinned: { urn: string; name: string; seed: string }[] };
- seeds: { pinned: Record };
provider: ethers.providers.JsonRpcProvider;
signer: (ethers.Signer & TypedDataSigner) | WalletConnectSigner | null;
walletConnect: {
@@ -46,24 +65,15 @@ export class Config {
connected: false;
signer: (ethers.Signer & TypedDataSigner) | null;
};
- abi: { [contract: string]: string[] };
- seed: {
- api: { port: number };
- git: { port: number };
- link: { port: number };
- };
- tokens: string[];
token: ethers.Contract;
constructor(
- network: { name: string; chainId: number },
+ network: NetworkConfig,
provider: ethers.providers.JsonRpcProvider,
metamaskSigner: (ethers.Signer & TypedDataSigner) | null,
) {
- const cfg = (>config)[network.name];
-
const walletConnectState = writable({ state: "close" });
- const wc = Config.initializeWalletConnect(
+ const wc = Wallet.initializeWalletConnect(
config.walletConnect.bridge,
walletConnectState,
provider,
@@ -89,20 +99,14 @@ export class Config {
signer: wc.signer,
state: walletConnectState,
};
- this.seed = config.radicle.seed;
- this.registrar = cfg.registrar;
- this.radToken = cfg.radToken;
- this.reverseRegistrar = cfg.reverseRegistrar;
- this.users = cfg.users;
+ this.registrar = network.registrar;
+ this.radToken = network.radToken;
+ this.reverseRegistrar = network.reverseRegistrar;
this.provider = provider;
this.signer = null;
- this.projects = config.projects;
- this.seeds = config.seeds;
- this.abi = config.abi;
- this.tokens = cfg.tokens;
this.token = new ethers.Contract(
this.radToken.address,
- this.abi.token,
+ ethereumContractAbis.token,
this.provider,
);
}
@@ -122,7 +126,7 @@ export class Config {
this.setSigner(this.walletConnect.signer);
return this.walletConnect.signer;
}
- const wc = Config.initializeWalletConnect(
+ const wc = Wallet.initializeWalletConnect(
this.walletConnect.bridge,
this.walletConnect.state,
this.provider,
@@ -191,16 +195,15 @@ export function isMetamaskInstalled(): boolean {
}
function getProvider(
- network: { name: string },
- config: Record,
+ networkConfig: NetworkConfig,
metamask: ethers.providers.JsonRpcProvider | null,
): ethers.providers.JsonRpcProvider {
if (metamask) {
return metamask;
} else if (import.meta.env.PROD) {
return new ethers.providers.AlchemyWebSocketProvider(
- network.name,
- config.alchemy.key,
+ networkConfig.name,
+ networkConfig.alchemy.key,
);
} else if (import.meta.env.DEV) {
// The ethers defaultProvider doesn't include a `send` method, which breaks the `utils.getTokens` fn.
@@ -224,34 +227,38 @@ function checkMetaMask(
});
}
-export async function getConfig(): Promise {
+export async function getWallet(): Promise {
const metamask = isMetamaskInstalled()
? new ethers.providers.Web3Provider(window.ethereum)
: null;
const metamaskSigner = metamask?.getSigner() || null;
- console.debug("metamask", metamask);
- console.debug("metamaskSigner", metamaskSigner);
+ let selectedNetwork: NetworkConfig;
- let network = { name: "homestead", chainId: 1 };
if (metamask) {
- // If Metamask is detected, we use the network configured there.
const ready = await checkMetaMask(metamask);
- if (ready) network = ready;
+ if (ready) {
+ if (ready.name === "homestead") {
+ selectedNetwork = homestead;
+ } else if (ready.name === "goerli") {
+ selectedNetwork = goerli;
+ } else {
+ throw new Error(
+ `${capitalize(
+ ready.name,
+ )} is not supported. Connect to Homestead or Goerli instead.`,
+ );
+ }
+ } else {
+ throw new Error("Metamask was not ready after 4 seconds.");
+ }
+ } else {
+ // Fall back to homestead.
+ selectedNetwork = homestead;
}
- const networkConfig = (>config)[network.name];
- if (!networkConfig) {
- throw new Error(
- `${capitalize(
- network.name,
- )} is not supported. Connect to Homestead or Goerli instead.`,
- );
- }
-
- const provider = getProvider(network, networkConfig, metamask);
- const cfg = new Config(network, provider, metamaskSigner);
- console.debug("config", cfg);
+ const provider = getProvider(selectedNetwork, metamask);
+ const cfg = new Wallet(selectedNetwork, provider, metamaskSigner);
return cfg;
}