Skip to content

Commit

Permalink
Merge pull request #96 from enkryptcom/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
kvhnuke authored Jul 31, 2022
2 parents e8a4df7 + 615f744 commit 58aeee5
Show file tree
Hide file tree
Showing 28 changed files with 279 additions and 211 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.0.0",
"version": "1.0.1",
"private": true,
"scripts": {
"zip": "cd dist; zip -r release.zip *;",
Expand Down
10 changes: 10 additions & 0 deletions packages/extension/src/libs/keyring/public-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class PublicKeyRing {
walletType: WalletType.ledger,
isHardware: true,
};
allKeys["5E56EZk6jmpq1q3Har3Ms99D9TLN9ra2inFh7Q1Hj6GpUx6D"] = {
address: "5CFnoCsP3pDK2thhSqYPwKELJFLQ1hBodqzSUypexyh7eHkB",
basePath: "//",
name: "fake account #4",
pathIndex: 0,
publicKey: "0x0",
signerType: SignerType.sr25519,
walletType: WalletType.mnemonic,
isHardware: false,
};
}
return allKeys;
}
Expand Down
30 changes: 29 additions & 1 deletion packages/extension/src/libs/utils/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { SignerType } from "@enkryptcom/types";
import { EnkryptAccount, NetworkNames, SignerType } from "@enkryptcom/types";
import PublicKeyRing from "../keyring/public-keyring";
import { getNetworkByName } from "./networks";

const getOtherSigners = (signers: SignerType[]): SignerType[] => {
const otherSigners: SignerType[] = [];
Expand All @@ -8,4 +10,30 @@ const getOtherSigners = (signers: SignerType[]): SignerType[] => {
return otherSigners;
};

export const getAccountsByNetworkName = async (
networkName: NetworkNames
): Promise<EnkryptAccount[]> => {
const network = getNetworkByName(networkName);

if (!network) return [];

const keyring = new PublicKeyRing();

const accounts = await keyring.getAccounts(network.signer);

return accounts.filter((account) => {
if (account.isHardware && account.HWOptions !== undefined) {
// Polkadot and Kusama ledger apps only work for those networks
if (
account.HWOptions.networkName === NetworkNames.Kusama ||
account.HWOptions.networkName === NetworkNames.Polkadot
) {
return account.HWOptions.networkName === networkName;
}
}

return true;
});
};

export { getOtherSigners };
4 changes: 2 additions & 2 deletions packages/extension/src/manifest/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "https://www.enkrypt.com",
"homepage_url": "https://www.enkrypt.com",
"version": "",
"name": "Enkrypt",
"name": "Enkrypt: Ethereum and Polkadot Web3 Wallet",
"short_name": "Enkrypt",
"permissions": [
"storage",
Expand Down Expand Up @@ -39,7 +39,7 @@
"icons": {
"16": "assets/img/icons/icon16.png",
"32": "assets/img/icons/icon32.png",
"48": "assets/img/icons/icon48.png",
"64": "assets/img/icons/icon64.png",
"192": "assets/img/icons/icon192.png"
}
}
2 changes: 1 addition & 1 deletion packages/extension/src/manifest/manifest-chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"default_icon": {
"16": "assets/img/icons/icon16.png",
"32": "assets/img/icons/icon32.png",
"48": "assets/img/icons/icon48.png",
"64": "assets/img/icons/icon64.png",
"192": "assets/img/icons/icon192.png"
},
"default_title": "Enkrypt",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/manifest/manifest-firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"default_icon": {
"16": "assets/img/icons/icon16.png",
"32": "assets/img/icons/icon32.png",
"48": "assets/img/icons/icon48.png",
"64": "assets/img/icons/icon64.png",
"192": "assets/img/icons/icon192.png"
},
"default_title": "Enkrypt",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/manifest/manifest-opera.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"background": {
"scripts": ["scripts/background.js"],
"persistent": true
Expand All @@ -8,7 +9,7 @@
"default_icon": {
"16": "assets/img/icons/icon16.png",
"32": "assets/img/icons/icon32.png",
"48": "assets/img/icons/icon48.png",
"64": "assets/img/icons/icon64.png",
"192": "assets/img/icons/icon192.png"
},
"default_title": "Enkrypt",
Expand Down
15 changes: 15 additions & 0 deletions packages/extension/src/providers/polkadot/libs/api-promises.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SubstrateAPI from "@/providers/polkadot/libs/api";

const apiPromiseList: Record<string, SubstrateAPI> = {};

const addNewApi = (node: string, api: SubstrateAPI) => {
apiPromiseList[node] = api;
};
const closeAllConnections = () => {
Object.values(apiPromiseList).forEach((api) => api.api.disconnect());
};
const getApi = (node: string): SubstrateAPI => {
return apiPromiseList[node];
};

export { addNewApi, closeAllConnections, getApi };
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const assets: BaseToken[] = [
name: "Karura",
symbol: "KAR",
decimals: 12,
icon: require("./icons/KAR.svg"),
icon: require("../../icons/karura.svg"),
coingeckoID: "acala",
existentialDeposit: toBN("100000000000"),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import Sparkline from "@/libs/sparkline";
import { SubstrateNativeToken } from "./substrate-native-token";
import { Activity } from "@/types/activity";
import { getApi, addNewApi } from "../libs/api-promises";

export interface SubstrateNetworkOptions {
name: NetworkNames;
Expand All @@ -32,7 +33,6 @@ export interface SubstrateNetworkOptions {
node: string;
coingeckoID?: string;
genesisHash: string;
transferMethods?: Record<string, (args: any) => any>;
activityHandler: (
network: BaseNetwork,
address: string
Expand All @@ -43,33 +43,20 @@ export class SubstrateNetwork extends BaseNetwork {
public prefix: number;
public assets: BaseToken[] = [];
public genesisHash: string;

private activityHandler: (
network: BaseNetwork,
address: string
) => Promise<Activity[]>;
public transferMethods: Record<string, (args: any) => any> = {
"balances.transferKeepAlive": (args: any) => {
const to = args.dest["Id"];
const token = new SubstrateNativeToken({
name: this.name_long,
symbol: this.name,
coingeckoID: this.coingeckoID,
decimals: this.decimals,
icon: this.icon,
});
const amount =
Number(args.value.replaceAll(",", "")) / 10 ** this.decimals;
return { to, token, amount };
},
};

constructor(options: SubstrateNetworkOptions) {
const api = async () => {
if (getApi(options.node)) return getApi(options.node);
const api = new SubstrateAPI(options.node, {
decimals: options.decimals,
name: options.name,
});
await api.init();
addNewApi(options.node, api);
return api;
};

Expand All @@ -87,12 +74,6 @@ export class SubstrateNetwork extends BaseNetwork {
this.prefix = options.prefix;
this.genesisHash = options.genesisHash;

if (options.transferMethods) {
this.transferMethods = {
...options.transferMethods,
...this.transferMethods,
};
}
this.activityHandler = options.activityHandler;
}

Expand Down Expand Up @@ -122,53 +103,49 @@ export class SubstrateNetwork extends BaseNetwork {
);
const marketData = new MarketData();
const market = await marketData.getMarketData(
supported
.filter(({ coingeckoID }) => coingeckoID !== undefined)
.map(({ coingeckoID }) => coingeckoID as string)
supported.map(({ coingeckoID }) => coingeckoID ?? "")
);

const balances = (await Promise.all(
balancePromises
)) as unknown as number[];

const tokens: AssetsType[] = supported
.map((st, idx) => {
const userBalance = fromBase(balances[idx].toString(), st.decimals);
const usdBalance = new BigNumber(userBalance).times(
market[idx]?.current_price || 0
);
return {
balance: balances[idx].toString(),
balancef: formatFloatingPointValue(userBalance).value,
balanceUSD: usdBalance.toNumber(),
balanceUSDf: formatFiatValue(usdBalance.toString()).value,
decimals: st.decimals,
icon: st.icon,
name: st.name,
symbol: st.symbol,
priceChangePercentage:
market[idx]?.price_change_percentage_7d_in_currency || 0,
sparkline: market[idx]
? new Sparkline(market[idx]?.sparkline_in_7d.price, 25).dataUri
: "",
value: market[idx]?.current_price.toString() || "0",
valuef: formatFloatingPointValue(
market[idx]?.current_price.toString() || "0"
).value,
baseToken: st,
};
})
.filter((asset) => asset.balance !== "0");

const sorted = [...tokens].filter((val, idx) => idx !== 0);
sorted.sort((a, b) => {
const tokens: AssetsType[] = supported.map((st, idx) => {
const userBalance = fromBase(balances[idx].toString(), st.decimals);
const usdBalance = new BigNumber(userBalance).times(
market[idx]?.current_price || 0
);
return {
balance: balances[idx].toString(),
balancef: formatFloatingPointValue(userBalance).value,
balanceUSD: usdBalance.toNumber(),
balanceUSDf: formatFiatValue(usdBalance.toString()).value,
decimals: st.decimals,
icon: st.icon,
name: st.name,
symbol: st.symbol,
priceChangePercentage:
market[idx]?.price_change_percentage_7d_in_currency || 0,
sparkline: market[idx]
? new Sparkline(market[idx]?.sparkline_in_7d.price, 25).dataUri
: "",
value: market[idx]?.current_price.toString() || "0",
valuef: formatFloatingPointValue(
market[idx]?.current_price.toString() || "0"
).value,
baseToken: st,
};
});
const nonNativNonZeroList = tokens.filter(
(asset, idx) => idx !== 0 && asset.balance !== "0"
);
nonNativNonZeroList.sort((a, b) => {
if (a.balanceUSD < b.balanceUSD) return 1;
else if (a.balanceUSD > b.balanceUSD) return -1;
else return 0;
});
sorted.unshift(tokens[0]);

return sorted;
nonNativNonZeroList.unshift(tokens[0]);
return nonNativNonZeroList;
}
public getAllActivity(address: string): Promise<Activity[]> {
return this.activityHandler(this, address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,28 @@ const pasteFromClipboard = () => {
defineExpose({ addressInput, pasteFromClipboard });
const address = computed({
get: () =>
isFocus.value
? props.value
: isAddress.value
? replaceWithEllipsis(props.value, 6, 6)
: replaceWithEllipsis(props.value, 6, 6),
set: (value) => emit("update:inputAddress", value),
get: () => {
try {
if (isFocus.value && isAddress.value) {
return props.network.displayAddress(props.value);
} else if (isAddress.value) {
return replaceWithEllipsis(
props.network.displayAddress(props.value),
6,
6
);
}
return props.value;
} catch {
return props.value;
}
},
set: (value) => {
if (value) {
emit("update:inputAddress", value);
}
},
});
const isAddress = computed(() => {
Expand Down Expand Up @@ -148,6 +163,10 @@ const changeFocus = (val: FocusEvent) => {
outline: none;
padding: 0;
}
input:disabled {
background-color: #ffffff;
}
}
&__arrow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<h3>Recent</h3>
<div class="send-contacts-list__list">
<send-address-item
v-for="(account, index) in accountInfo.activeAccounts"
v-for="(account, index) in accounts"
:key="index"
:account="account"
:network="network"
Expand All @@ -45,7 +45,7 @@

<div class="send-contacts-list__list">
<send-address-item
v-for="(account, index) in accountInfo.activeAccounts"
v-for="(account, index) in accounts"
:key="index"
:account="account"
:network="network"
Expand Down Expand Up @@ -83,10 +83,9 @@
import SendAddressItem from "./send-address-item.vue";
import CustomScrollbar from "@action/components/custom-scrollbar/index.vue";
import BaseButton from "@action/components/base-button/index.vue";
import { AccountsHeaderData } from "@action/types/account";
import scrollSettings from "@/libs/utils/scroll-settings";
import { onUpdated, ref } from "vue";
import { KeyRecord } from "@enkryptcom/types";
import { EnkryptAccount, KeyRecord } from "@enkryptcom/types";
import PasteIcon from "@action/icons/actions/paste.vue";
import ArrowBack from "@action/icons/common/arrow-back.vue";
import { BaseNetwork } from "@/types/base-network";
Expand All @@ -97,18 +96,18 @@ const emit = defineEmits<{
interface IProps {
showAccounts: boolean;
accountInfo: AccountsHeaderData;
accounts: EnkryptAccount[];
address: string;
network: BaseNetwork;
}
const props = defineProps<IProps>();
const searchAccounts = ref<KeyRecord[]>(props.accountInfo.activeAccounts);
const searchAccounts = ref<KeyRecord[]>(props.accounts);
const isMyAddress = ref(false);
onUpdated(() => {
searchAccounts.value = props.accountInfo.activeAccounts;
searchAccounts.value = props.accounts;
});
const close = () => {
Expand Down
Loading

2 comments on commit 58aeee5

@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.