Skip to content

Commit

Permalink
feat: add send flow (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 authored Dec 8, 2024
1 parent e59cdec commit 408bfd6
Show file tree
Hide file tree
Showing 90 changed files with 2,791 additions and 802 deletions.
2 changes: 1 addition & 1 deletion packages/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
"last 1 safari version"
]
}
}
}
2 changes: 1 addition & 1 deletion packages/dapp/src/apis/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type TxResult = {
failureText?: string;
};

export async function send( from: string | AccountId, api: ApiPromise, ptx: SubmittableExtrinsic<'promise', ISubmittableResult>, payload: SignerPayloadJSON, signature: HexString,): Promise<TxResult> {
export async function send(from: string | AccountId, api: ApiPromise, ptx: SubmittableExtrinsic<'promise', ISubmittableResult>, payload: SignerPayloadJSON, signature: HexString,): Promise<TxResult> {
return new Promise((resolve) => {
console.info('sending a tx ...');
ptx.addSignature(from, signature, payload);
Expand Down
22 changes: 11 additions & 11 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polkagate/snap",
"version": "0.7.0",
"version": "1.0.0",
"description": "A MetaMask Snap to interact with Polkadot ecosystem, a platform for cross-chain communication and scalability. Use your MetaMask wallet to access Polkadot dApps and tokens. No extra extension needed.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -29,17 +29,17 @@
"@metamask/key-tree": "^9.1.2",
"@metamask/rpc-errors": "^7.0.0",
"@metamask/snaps-sdk": "^6.8.0",
"@polkadot/api": "^12.1.1",
"@polkadot/api": "^15.0.1",
"@polkadot/apps-config": "^0.141.1",
"@polkadot/extension-chains": "^0.47.6",
"@polkadot/keyring": "^12.6.2",
"@polkadot/networks": "^12.6.2",
"@polkadot/types": "^12.1.1",
"@polkadot/types-known": "^12.1.1",
"@polkadot/ui-keyring": "^3.6.6",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@polkagate/apps-config": "^0.140.3",
"@polkadot/extension-chains": "^0.56.2",
"@polkadot/keyring": "^13.2.3",
"@polkadot/networks": "^13.2.3",
"@polkadot/types": "^15.0.1",
"@polkadot/types-known": "^15.0.1",
"@polkadot/ui-keyring": "^3.11.3",
"@polkadot/util": "^13.2.3",
"@polkadot/util-crypto": "^13.2.3",
"@polkagate/apps-config": "^0.140.7",
"buffer": "^6.0.3",
"umi-request": "^1.4.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "0.7.0",
"version": "1.0.0",
"description": "Explore Polkadot decentralized applications and manage your tokens using your MetaMask wallet. Start your journey at apps.polkagate.xyz.",
"proposedName": "PolkaGate",
"repository": {
"type": "git",
"url": "https://github.com/polkagate/snap.git"
},
"source": {
"shasum": "CRmXO1t+mMp/F99/JhIfeOnVlLw169eBsjdOTQdFSIY=",
"shasum": "El6Htlbic1UW7u+7PnF0khkjJ1Xka742wgjOp/qyXTk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
106 changes: 89 additions & 17 deletions packages/snap/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Chain } from '@polkadot/extension-chains/types';
import { sanitizeChainName } from './util/getChainName';
import { HexString } from '@polkadot/util/types';

const westend = {
const testnets:Network[] = [
{
decimals: [12],
displayName: 'Westend',
genesisHash: [
Expand All @@ -22,27 +23,98 @@ const westend = {
standardAccount: '*25519',
symbols: ['WND'],
website: 'https://polkadot.network',
};

const westendAssetHub = {
},
{
decimals: [12],
displayName: 'Westend Asset Hub',
displayName: "Paseo",
genesisHash: [
'0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9',
"0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f",
],
hasLedgerSupport: false,
icon: 'polkadot',
icon: "polkadot",
isIgnored: false,
isTestnet: true,
network: 'westmint',
network: "paseo",
prefix: 42,
slip44: 354,
standardAccount: '*25519',
symbols: ['WND'],
website: 'https://polkadot.network',
};

selectableNetworks.push(westend as Network, westendAssetHub as Network);
slip44: 0,
standardAccount: "*25519",
symbols: ["PAS"],
website: "https://polkadot.network",
}
]

const assetHubs:Network[] = [
{
decimals: [10],
displayName: "Polkadot Asset Hub",
genesisHash: [
"0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f",
],
hasLedgerSupport: true,
icon: "polkadot",
isIgnored: false,
isTestnet: false,
network: "statemint",
prefix: 0,
slip44: 354,
standardAccount: "*25519",
symbols: ["DOT"],
website: "https://polkadot.network",
},
{
decimals: [12],
displayName: "Kusama Asset Hub",
genesisHash: [
"0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a",
],
hasLedgerSupport: true,
icon: "polkadot",
isIgnored: false,
isTestnet: false,
network: "statemine",
prefix: 2,
slip44: 434,
standardAccount: "*25519",
symbols: ["KSM"],
website: "https://kusama.network",
},
{
decimals: [12],
displayName: 'Westend Asset Hub',
genesisHash: [
'0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9',
],
hasLedgerSupport: false,
icon: 'polkadot',
isIgnored: false,
isTestnet: true,
network: 'westmint',
prefix: 42,
slip44: 354,
standardAccount: '*25519',
symbols: ['WND'],
website: 'https://polkadot.network',
},
{
decimals: [10],
displayName: "Paseo Asset Hub",
genesisHash: [
"0xd6eec26135305a8ad257a20d003357284c8aa03d0bdb2b357ab0a22371e11ef2",
],
hasLedgerSupport: false,
icon: "polkadot",
isIgnored: false,
isTestnet: false,
network: "paseo-asset-hub",
prefix: 42, // Adjust if necessary
slip44: 0, // Update as required
standardAccount: "*25519",
symbols: ["PAS"],
website: "https://polkadot.network",
},
];

selectableNetworks.push(...testnets, ...assetHubs);
export const DISABLED_NETWORKS = ['3DP network', 'xx network', 'Polkadex Mainnet', 'Stafi', 'Peaq Network', 'Genshiro Network'];

// keyWord can be genesisHash, chainName, or even display name
Expand All @@ -67,7 +139,7 @@ export const getAllChains = (): Network[] | null => {
return selectableNetworks;
};

type Options = {
export type Options = {
value: string;
text: string;
}
Expand All @@ -78,7 +150,7 @@ export const getChainOptions = (): Options[] => {
if (!chains) {
return [];
}

return chains
.filter(({ genesisHash, displayName }) => genesisHash?.length && !DISABLED_NETWORKS.includes(displayName))
.map(({ displayName, genesisHash }) => (
Expand Down
22 changes: 5 additions & 17 deletions packages/snap/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import { KUSAMA_GENESIS, POLKADOT_GENESIS, WESTEND_GENESIS } from "@polkadot/apps-config";

export const DEFAULT_NETWORK_PREFIX = 42; // 42 is for substrate
export const DEFAULT_COIN_TYPE = 354; // 354 is for Polkadot
export const DEFAULT_CHAIN_NAME = 'polkadot'; // Since Westend shares the same address prefix as Substrate, the address format for both is identical
export const CHAIN_NAMES = ['westend', 'polkadot', 'kusama'];

export const NOT_LISTED_CHAINS = [
'0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b', // Darwinia
'0x6f1a800de3daff7f5e037ddf66ab22ce03ab91874debeddb1086f5f7dbd48925', // Equilibirum
'0x81443836a9a24caaa23f1241897d1235717535711d1d3fe24eae4fdc942c092c', // Cere
'0xdaab8df776eb52ec604a5df5d388bb62a050a0aaec4556a64265b9d42755552d', // Composable
'0xe358eb1d11b31255a286c12e44fe6780b7edb171d657905a97e39f71d9c6c3ee', // Ajuna
'0xe71578b37a7c799b0ab4ee87ffa6f059a6b98f71f06fb8c84a8d88013a548ad6', // Darwinia
'0xf7a99d3cb92853d00d5275c971c132c074636256583fee53b3bbe60d7b8769ba', // Kulupu
'0xe61a41c53f5dcd0beb09df93b34402aada44cb05117b71059cce40a2723a4e97', // parallel
'0x5d3c298622d5634ed019bf61ea4b71655030015bde9beb0d6a24743714462c86', // Pendulum
'0x1bb969d85965e4bb5a651abbedf21a54b6b31a21f66b5401cc3f1e286268d736', // Phala
'0x6fbd74e5e1d0a61d52ccfe9d4adaed16dd3a7caa37c6bc4d0c2fa12e8b2f4063', // Polymesh
'0x7e4e32d0feafd4f9c9414b0be86373f9a1efa904809b683453a9af6856d38ad5', // SORA
]

export const PRICE_VALIDITY_PERIOD = 2 * 60 * 1000;
export const PRICE_VALIDITY_PERIOD = 2 * 60 * 1000;

export const DEFAULT_CHAINS_GENESIS = [POLKADOT_GENESIS, KUSAMA_GENESIS];
Loading

0 comments on commit 408bfd6

Please sign in to comment.