Skip to content

Commit

Permalink
Add support for mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
kewbish committed Dec 28, 2022
1 parent ebba8a7 commit cdee69c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
20 changes: 13 additions & 7 deletions src/pages/Background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
CHECK_METAMASK,
APPROVE_FULL,
} from "../shared/events";
import TOKEN_MAP from "../shared/tokens";
import TOKEN_MAP, { PROD_TOKEN_MAP } from "../shared/tokens";
import { Wallet } from "../shared/types";
import createStream, { updateStream } from "./lib/createStream";
import deleteStreamByTabId from "./lib/deleteStreamByTabId";
Expand All @@ -47,6 +47,7 @@ import generateSignature from "./lib/generateSignature";
import verifySignature from "../shared/verifySignature";
import cleanUpStreams from "./lib/cleanUpStreams";
import fetchCobwebAllowance from "./lib/fetchCobwebAllowance";
import { isDev } from "./lib/isDev";

chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
Expand Down Expand Up @@ -86,10 +87,13 @@ if (!addressTry) {

let infuraProvider: InfuraProvider | null = null;
try {
infuraProvider = new ethers.providers.InfuraProvider("goerli", {
projectId: INFURA_PROJECT_ID,
projectSecret: INFURA_PROJECT_SECRET,
});
infuraProvider = new ethers.providers.InfuraProvider(
isDev() ? "goerli" : "homestead",
{
projectId: INFURA_PROJECT_ID,
projectSecret: INFURA_PROJECT_SECRET,
}
);
} catch (e) {
toast("Error - failed to initialize provider");
throw new Error("Error - failed to initialize provider");
Expand All @@ -98,7 +102,7 @@ try {
let sf: Framework | null = null;
try {
sf = await Framework.create({
chainId: 5,
chainId: isDev() ? 5 : 1,
provider: infuraProvider,
});
} catch (e) {
Expand All @@ -109,7 +113,9 @@ try {
let sfToken: SuperToken | null = null;
try {
if (sf) {
sfToken = await sf.loadSuperToken(TOKEN_MAP.ETH.xAddress);
sfToken = await sf.loadSuperToken(
isDev() ? TOKEN_MAP.ETH.xAddress : PROD_TOKEN_MAP.ETH.xAddress
);
}
} catch (e) {
errorToast(e as Error);
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Background/lib/isDev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "process";

export const isDev = () =>
!process.env.NODE_ENV || process.env.NODE_ENV === "development";
8 changes: 8 additions & 0 deletions src/pages/shared/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ const TOKEN_MAP = {
},
};

export const PROD_TOKEN_MAP = {
ETH: {
decimals: 18,
name: "ETHx",
xAddress: "0xC22BeA0Be9872d8B7B3933CEc70Ece4D53A900da",
},
};

export default TOKEN_MAP;
18 changes: 10 additions & 8 deletions worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Env {
MASTER_WALLET_PKEY: string;
ENVIRONMENT: string;
WEBHOOK_URL: string;
SF_TOKEN_ADDRESS: string;
}

const HEADERS = {
Expand Down Expand Up @@ -43,10 +44,13 @@ const worker = {
`:${env.ADMIN_KEY}`
)
) {
const provider = new ethers.providers.InfuraProvider("goerli", {
projectSecret: env.INFURA_API_KEY,
projectId: env.INFURA_ID,
});
const provider = new ethers.providers.InfuraProvider(
env.ENVIRONMENT === "dev" ? "goerli" : "homestead",
{
projectSecret: env.INFURA_API_KEY,
projectId: env.INFURA_ID,
}
);
if (env.ENVIRONMENT === "dev") {
logger(
"Connected to Infura on chain " +
Expand Down Expand Up @@ -76,12 +80,10 @@ const worker = {
}
}
const sf = await Framework.create({
chainId: 5,
chainId: env.ENVIRONMENT === "dev" ? 5 : 1,
provider,
});
const sfToken = await sf.loadSuperToken(
"0x5943F705aBb6834Cad767e6E4bB258Bc48D9C947"
);
const sfToken = await sf.loadSuperToken(env.SF_TOKEN_ADDRESS);
const wallet = new ethers.Wallet(env.MASTER_WALLET_PKEY);
const signer = wallet.connect(provider);
const transferOperation = sfToken.transfer({
Expand Down
2 changes: 2 additions & 0 deletions worker/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ kv_namespaces = [
[vars]
INFURA_ID = "68536930f1864c1b8e9aac67c3095ec8"
ENVIRONMENT = "production"
SF_TOKEN_ADDRESS = "0xC22BeA0Be9872d8B7B3933CEc70Ece4D53A900da"

[env.dev]
ENVIRONMENT = "dev"
SF_TOKEN_ADDRESS = "0x5943F705aBb6834Cad767e6E4bB258Bc48D9C947"

0 comments on commit cdee69c

Please sign in to comment.