Skip to content

Commit

Permalink
Merge pull request #301 from enkryptcom/develop
Browse files Browse the repository at this point in the history
Release: v1.20.0
  • Loading branch information
kvhnuke authored Jun 2, 2023
2 parents 9e4f72c + 7c20bcd commit edd64de
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 42 deletions.
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@enkryptcom/extension",
"version": "1.19.0",
"version": "1.20.0",
"private": true,
"scripts": {
"zip": "cd dist; zip -r release.zip *;",
Expand Down
5 changes: 3 additions & 2 deletions packages/extension/src/libs/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ const POPULAR_NAMES = [
NetworkNames.Ethereum,
NetworkNames.Matic,
NetworkNames.Polkadot,
NetworkNames.Moonbeam,
NetworkNames.Acala,
NetworkNames.Binance,
NetworkNames.Rootstock,
NetworkNames.Optimism,
];
export {
getAllNetworks,
Expand Down
37 changes: 23 additions & 14 deletions packages/extension/src/providers/ethereum/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import {
ProviderType,
ProviderInterface,
SendMessageHandler,
ProviderInfo,
EIP6963ProviderInfo,
EIP6963Events,
} from "@/types/provider";
import { EXTENSION_VERSION } from "@/configs/constants";
import { SettingsType } from "@/libs/settings-state/types";
import { EnkryptWindow } from "@/types/globals";

const ENKRYPT_UUID_V4 = "d59f4ac4-a9da-4b9d-a08c-9a28396ec016";

export class Provider extends EventEmitter implements ProviderInterface {
chainId: string | null;
networkVersion: string;
Expand All @@ -31,7 +30,6 @@ export class Provider extends EventEmitter implements ProviderInterface {
type: ProviderType;
version: string = EXTENSION_VERSION;
autoRefreshOnNetworkChange = false;
info: ProviderInfo;
sendMessageHandler: SendMessageHandler;
constructor(options: ProviderOptions) {
super();
Expand All @@ -44,13 +42,6 @@ export class Provider extends EventEmitter implements ProviderInterface {
this.name = options.name;
this.type = options.type;
this.version = EXTENSION_VERSION;
this.info = {
uuid: ENKRYPT_UUID_V4,
description:
"A multichain crypto wallet hold, buy, send, receive, and swap tokens. Manage your NFTs. Access web3 apps across multiple blockchains.",
icon: `data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODEiIGhlaWdodD0iODEiIHZpZXdCb3g9IjAgMCA4MSA4MSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNy4wMDU3IDE3LjAwNjJDMTguOTMwMyAxNS4wODE2IDIxLjU0MDUgMTQuMDAwNCAyNC4yNjIyIDE0LjAwMDRMNjcuMzI5NiAxNFYyMS44NzQxQzY3LjMyOTYgMjMuODMwNSA2Ni41NTIzIDI1LjcwNjcgNjUuMTY5IDI3LjA5QzYzLjc4NTcgMjguNDczMyA2MS45MDk1IDI5LjI1MDQgNTkuOTUzMiAyOS4yNTA0SDM5LjcwNDVDMzYuOTgyOCAyOS4yNTA0IDM0LjM3MjYgMzAuMzMxNiAzMi40NDggMzIuMjU2MUMzMC41MjM1IDM0LjE4MDcgMjkuNDQyMyAzNi43OTA5IDI5LjQ0MjMgMzkuNTEyNlY0Mi4xMjQyQzI5LjQ0MjMgNDQuODQ1OSAzMC41MjM1IDQ3LjQ1NjEgMzIuNDQ4IDQ5LjM4MDZDMzQuMzcyNiA1MS4zMDUxIDM2Ljk4MjggNTIuMzg2MyAzOS43MDQ1IDUyLjM4NjNINTkuOTUzMkM2MS45MDk1IDUyLjM4NjMgNjMuNzg1NyA1My4xNjM1IDY1LjE2OSA1NC41NDY4QzY2LjU1MjMgNTUuOTMwMSA2Ny4zMjk2IDU3LjgwNjMgNjcuMzI5NiA1OS43NjI2VjY3LjMzSDI0LjI2MjJDMjEuNTQwNSA2Ny4zMyAxOC45MzAzIDY2LjI0ODggMTcuMDA1NyA2NC4zMjQzQzE1LjA4MTIgNjIuMzk5NyAxNCA1OS43ODk1IDE0IDU3LjA2NzhWMjQuMjYyNkMxNCAyMS41NDA5IDE1LjA4MTIgMTguOTMwNyAxNy4wMDU3IDE3LjAwNjJaTTQwLjE0NzkgMzMuNTQyM0g2MC45MTU3QzY0LjQ1OCAzMy41NDIzIDY3LjMyOTUgMzYuNDEzOCA2Ny4zMjk1IDM5Ljk1NjFWNDEuNjgxNkM2Ny4zMjk1IDQ1LjIyMzggNjQuNDU4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg==`,
name: "Enkrypt",
};
this.sendMessageHandler = options.sendMessageHandler;
}
async request(request: EthereumRequest): Promise<EthereumResponse> {
Expand Down Expand Up @@ -153,11 +144,29 @@ const injectDocument = (
): void => {
const provider = new Provider(options);
const globalSettings: SettingsType = document.enkrypt.settings;
const proxiedProvider = new Proxy(provider, ProxyHandler);
if (!globalSettings.evm.inject.disabled)
document[options.name] = new Proxy(provider, ProxyHandler); //proxy is needed due to web3js 1.3.0 callbackify issue. Used in superrare
document[options.name] = proxiedProvider; //proxy is needed due to web3js 1.3.0 callbackify issue. Used in superrare
document["enkrypt"]["providers"][options.name] = provider;
document["evmproviders"] = document["evmproviders"] || {};
document["evmproviders"]["enkrypt"] = provider;
const ENKRYPT_UUID_V4 = document.crypto.randomUUID();
// EIP-6963
const eip6963AnnounceProvider = () => {
const info: EIP6963ProviderInfo = {
uuid: ENKRYPT_UUID_V4,
icon: `data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODEiIGhlaWdodD0iODEiIHZpZXdCb3g9IjAgMCA4MSA4MSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNy4wMDU3IDE3LjAwNjJDMTguOTMwMyAxNS4wODE2IDIxLjU0MDUgMTQuMDAwNCAyNC4yNjIyIDE0LjAwMDRMNjcuMzI5NiAxNFYyMS44NzQxQzY3LjMyOTYgMjMuODMwNSA2Ni41NTIzIDI1LjcwNjcgNjUuMTY5IDI3LjA5QzYzLjc4NTcgMjguNDczMyA2MS45MDk1IDI5LjI1MDQgNTkuOTUzMiAyOS4yNTA0SDM5LjcwNDVDMzYuOTgyOCAyOS4yNTA0IDM0LjM3MjYgMzAuMzMxNiAzMi40NDggMzIuMjU2MUMzMC41MjM1IDM0LjE4MDcgMjkuNDQyMyAzNi43OTA5IDI5LjQ0MjMgMzkuNTEyNlY0Mi4xMjQyQzI5LjQ0MjMgNDQuODQ1OSAzMC41MjM1IDQ3LjQ1NjEgMzIuNDQ4IDQ5LjM4MDZDMzQuMzcyNiA1MS4zMDUxIDM2Ljk4MjggNTIuMzg2MyAzOS43MDQ1IDUyLjM4NjNINTkuOTUzMkM2MS45MDk1IDUyLjM4NjMgNjMuNzg1NyA1My4xNjM1IDY1LjE2OSA1NC41NDY4QzY2LjU1MjMgNTUuOTMwMSA2Ny4zMjk2IDU3LjgwNjMgNjcuMzI5NiA1OS43NjI2VjY3LjMzSDI0LjI2MjJDMjEuNTQwNSA2Ny4zMyAxOC45MzAzIDY2LjI0ODggMTcuMDA1NyA2NC4zMjQzQzE1LjA4MTIgNjIuMzk5NyAxNCA1OS43ODk1IDE0IDU3LjA2NzhWMjQuMjYyNkMxNCAyMS41NDA5IDE1LjA4MTIgMTguOTMwNyAxNy4wMDU3IDE3LjAwNjJaTTQwLjE0NzkgMzMuNTQyM0g2MC45MTU3QzY0LjQ1OCAzMy41NDIzIDY3LjMyOTUgMzYuNDEzOCA2Ny4zMjk1IDM5Ljk1NjFWNDEuNjgxNkM2Ny4zMjk1IDQ1LjIyMzggNjQuNDU4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg==`,
name: "Enkrypt",
walletId: "com.enkrypt",
};
document.dispatchEvent(
new document.CustomEvent(EIP6963Events.announce, {
detail: { info, provider: proxiedProvider },
})
);
};
document.addEventListener(EIP6963Events.request, () => {
eip6963AnnounceProvider();
});
eip6963AnnounceProvider();
};
export default injectDocument;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { NetworkNames } from "@enkryptcom/types";

const NetworkEndpoints: Record<string, string> = {
[NetworkNames.Ethereum]: "https://api.etherscan.io/",
[NetworkNames.Ropsten]: "https://api-ropsten.etherscan.io/",
[NetworkNames.Rinkeby]: "https://api-rinkeby.etherscan.io/",
[NetworkNames.Goerli]: "https://api-goerli.etherscan.io/",
[NetworkNames.Kovan]: "https://api-kovan.etherscan.io/",
[NetworkNames.Binance]: "https://api.bscscan.com/",
[NetworkNames.Matic]: "https://api.polygonscan.com/",
[NetworkNames.Moonbeam]: "https://api-moonbeam.moonscan.io/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { NetworkNames } from "@enkryptcom/types";

const NetworkEndpoints = {
[NetworkNames.Ethereum]: "https://nodes.mewapi.io/rpc/eth",
[NetworkNames.Ropsten]: "https://nodes.mewapi.io/rpc/rop",
[NetworkNames.Rinkeby]: "https://nodes.mewapi.io/rpc/rinkeby",
[NetworkNames.Sepolia]: "https://nodes.mewapi.io/rpc/sepolia",
[NetworkNames.Goerli]: "https://nodes.mewapi.io/rpc/goerli",
[NetworkNames.EthereumClassic]: "https://nodes.mewapi.io/rpc/etc",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const getBaseFeeBasedOnType = (
const baseFeeBN = toBN(baseFee);
switch (gasPriceType) {
case GasPriceTypes.ECONOMY:
return baseFeeBN.muln(1.15);
return baseFeeBN;
case GasPriceTypes.REGULAR:
return baseFeeBN.muln(1.25);
case GasPriceTypes.FAST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Transaction {
const feeHistory = await this.web3.getFeeHistory(
6,
"pending",
[90, 75, 50, 25]
[25, 50, 75, 90]
);
const formattedFeeHistory = formatFeeHistory(feeHistory);
const feeMarket = this.getFeeMarketGasInfo(
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/providers/ethereum/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import ftmNode from "./ftm";
import klayNode from "./klay";
import auroraNode from "./aurora";
import puppyNode from "./puppy";
import sepoliaNode from "./sepolia";

export default {
goerli: goerliNode,
sepolia: sepoliaNode,
ethereum: ethNode,
etc: etcNode,
matic: maticNode,
Expand Down
24 changes: 24 additions & 0 deletions packages/extension/src/providers/ethereum/networks/sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NetworkNames } from "@enkryptcom/types";
import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network";
import { RivetActivity } from "../libs/activity-handlers";
import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler";

const goerliOptions: EvmNetworkOptions = {
name: NetworkNames.Sepolia,
name_long: "Sepolia",
homePage: "https://sepolia.dev",
blockExplorerTX: "https://sepolia.ethvm.com/tx/[[txHash]]",
blockExplorerAddr: "https://sepolia.ethvm.com/address/[[address]]",
chainID: "0xaa36a7",
isTestNetwork: true,
currencyName: "SEP",
currencyNameLong: "Sepolia",
node: "wss://nodes.mewapi.io/ws/sepolia",
icon: require("./icons/eth.svg"),
gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)",
activityHandler: wrapActivityHandler(RivetActivity),
};

const goerli = new EvmNetwork(goerliOptions);

export default goerli;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import EthereumInject from "../inject";
import { MessageMethod, EmitEvent } from "../types";
import { OnMessageResponse } from "@enkryptcom/types";
import { EnkryptWindow } from "@/types/globals";
import { randomUUID } from "crypto";

const providerSendMessage = async (
provider: ProviderName,
Expand Down Expand Up @@ -33,6 +34,15 @@ const tempWindow: EnkryptWindow = {
},
},
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
addEventListener: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
CustomEvent: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
dispatchEvent: () => {},
crypto: {
randomUUID: () => randomUUID(),
},
};
describe("Test injected Ethereum", () => {
it("should have default values", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EthereumRequest } from "../types";
import { OnMessageResponse } from "@enkryptcom/types";
import { getError } from "@/libs/error";
import { EnkryptWindow } from "@/types/globals";
import { randomUUID } from "crypto";

const requestHandler = (request: string): OnMessageResponse => {
const req = JSON.parse(request) as EthereumRequest;
Expand Down Expand Up @@ -54,6 +55,15 @@ const tempWindow: EnkryptWindow = {
},
},
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
addEventListener: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
CustomEvent: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
dispatchEvent: () => {},
crypto: {
randomUUID: () => randomUUID(),
},
};
describe("Test Ethereum reponses", () => {
it("should send proper responses", async () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/extension/src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,19 @@ export interface ProviderOptions {
type: ProviderType;
sendMessageHandler: SendMessageHandler;
}
export interface ProviderInfo {

export interface EIP6963ProviderInfo {
uuid: string;
name: string;
icon: `data:image/svg+xml;base64,${string}`;
description: string;
walletId: string;
}

export enum EIP6963Events {
request = "eip6963:requestProvider",
announce = "eip6963:announceProvider",
}

export abstract class ProviderInterface extends EventEmitter {
name: ProviderName;
type: ProviderType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
<div class="add-network__custom-block">
<label-input
type="text"
label="Network name"
label="New RPC URL"
class="add-network__custom-input"
placeholder="Network Name"
:value="nameValue"
:is-error="nameInvalid"
@update:value="nameChanged"
placeholder="RPC Url"
:value="rpcURLValue"
:is-error="rpcInvalid"
@update:value="rpcURLChanged"
/>
</div>

<div class="add-network__custom-block">
<label-input
type="text"
label="New RPC URL"
label="Network name"
class="add-network__custom-input"
placeholder="RPC Url"
:value="rpcURLValue"
:is-error="rpcInvalid"
@update:value="rpcURLChanged"
placeholder="Network Name"
:value="nameValue"
:is-error="nameInvalid"
@update:value="nameChanged"
/>
</div>

Expand Down
1 change: 0 additions & 1 deletion packages/hw-wallets/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const ledgerAppNames = {
[NetworkNames.Binance]: "Ethereum",
[NetworkNames.Rootstock]: "RSK",
[NetworkNames.EthereumClassic]: "Ethereum Classic",
[NetworkNames.Ropsten]: "Ethereum",
[NetworkNames.Goerli]: "Ethereum",
[NetworkNames.Acala]: "Acala",
[NetworkNames.Kusama]: "Kusama",
Expand Down
1 change: 0 additions & 1 deletion packages/hw-wallets/src/ledger/ethereum/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const supportedPaths = {
bip44Paths.ethereumLedger,
bip44Paths.ethereumLedgerLive,
],
[NetworkNames.Ropsten]: [bip44Paths.ethereumTestnetLedger],
[NetworkNames.Goerli]: [bip44Paths.ethereumTestnetLedger],
};
export { supportedPaths };
1 change: 0 additions & 1 deletion packages/hw-wallets/src/trezor/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const supportedPaths = {
[NetworkNames.Ethereum]: [bip44Paths.ethereum],
[NetworkNames.Matic]: [bip44Paths.ethereum],
[NetworkNames.EthereumClassic]: [bip44Paths.ethereumClassic],
[NetworkNames.Ropsten]: [bip44Paths.ethereumTestnet],
[NetworkNames.Goerli]: [bip44Paths.ethereumTestnet],
[NetworkNames.Rootstock]: [bip44Paths.rootstock],
};
Expand Down
4 changes: 1 addition & 3 deletions packages/types/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ export enum NetworkNames {
Binance = "BNB",
EthereumClassic = "ETC",
Goerli = "GOERLI",
Kovan = "KOV",
Sepolia = "SEPOLIA",
Matic = "MATIC",
Moonbeam = "GLMR",
Moonriver = "MOVR",
Rinkeby = "RIN",
Ropsten = "ROP",
Rootstock = "Rootstock",
Acala = "ACA",
Karura = "KAR",
Expand Down

2 comments on commit edd64de

@github-actions
Copy link

Choose a reason for hiding this comment

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

@github-actions
Copy link

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.