Skip to content

Commit

Permalink
add westend assethub support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Dec 8, 2023
1 parent 61acc00 commit 83c956b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"rimraf": "^3.0.2",
"through2": "^4.0.2",
"ts-jest": "^29.1.0",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"@polkadot/apps-config":"latest"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
20 changes: 19 additions & 1 deletion packages/snap/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,25 @@ const westend = {
website: 'https://polkadot.network',
};

selectableNetworks.push(westend as Network);
const westendAssetHub = {
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',
};

selectableNetworks.push(westend as Network, westendAssetHub as Network);

export const getChain = (genesisOrChainName: string): Network => {
const chain = selectableNetworks.find(
Expand Down
52 changes: 33 additions & 19 deletions packages/snap/src/rpc/showConfirmTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import getLogo from '../util/getLogo';
import { Decoded, getDecoded } from './decodeTxMethod';

const FLOATING_POINT_DIGIT = 4;
const EMPTY_LOGO = `<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>`;

export function fixFloatingPoint(
_number: number | string,
Expand Down Expand Up @@ -75,20 +78,27 @@ const transactionContent = (
decoded: Decoded,
) => {
const headingText = `Transaction Approval Request from ${origin}`;
const decodedArgs = decoded.args;
const decodedArgs = decoded?.args;

const { args, callIndex } = api.createType('Call', payload.method);
const { method, section } = api.registry.findMetaCall(callIndex);

const action = `${section}_${method}`;

let chainLogoSvg = EMPTY_LOGO;
const dataURI = getLogo(payload.genesisHash);
const svgString = atob(dataURI.replace(/data:image\/svg\+xml;base64,/, ''));
const maybeSvgString = atob(
dataURI.replace(/data:image\/svg\+xml;base64,/, ''),
);
const indexOfFirstSvgTag = maybeSvgString.indexOf('<svg');
if (indexOfFirstSvgTag !== -1) {
chainLogoSvg = maybeSvgString.substring(indexOfFirstSvgTag);
}

const decimal = api.registry.chainDecimals[0];
const token = api.registry.chainTokens[0];
let amount;

let amount;
const isNoArgsMethod = args?.length === 0 && 'noArgsMethods';

switch (isNoArgsMethod || action) {
Expand All @@ -111,7 +121,7 @@ const transactionContent = (
divider(),
text(`Estimated Fee: **${partialFee.toHuman()}**`),
divider(),
panel([text('_Chain_ Logo:'), image(svgString)]),
panel([text('_Chain_ Logo:'), image(chainLogoSvg)]),
]),
]);
case 'staking_bond':
Expand All @@ -122,9 +132,9 @@ const transactionContent = (
heading(headingText),
divider(),
panel([
text(`Method: ${formatCamelCase(method)}`),
text(`Method: **${formatCamelCase(method)}**`),
divider(),
text(`Amount: ${amountToHuman(amount, decimal)} ${token}`),
text(`Amount: **${amountToHuman(amount, decimal)} ${token}**`),
divider(),
text(`Payee: ${payee}`),
]),
Expand All @@ -134,9 +144,9 @@ const transactionContent = (
heading(headingText),
divider(),
panel([
text(`Method: ${method}`),
text(`Method: **${method}**`),
divider(),
text(`Validators: ${args[0]}`),
text(`Validators: **${args[0]}**`),
]),
]);
case 'nominationPools_unbond':
Expand All @@ -148,19 +158,19 @@ const transactionContent = (
heading(headingText),
divider(),
panel([
text(`Method: ${method}`),
text(`Method: **${method}**`),
divider(),
text(`Amount: ${amountToHuman(amount, decimal)} ${token}`),
text(`Amount: **${amountToHuman(amount, decimal)} ${token}**`),
]),
]);
case 'staking_setPayee':
return panel([
heading(headingText),
divider(),
panel([
text(`Method: ${method}`),
text(`Method: **${method}**`),
divider(),
text(`Payee: ${args[0]}`),
text(`Payee: **${args[0]}**`),
]),
]);
case 'nominationPools_join':
Expand All @@ -171,11 +181,11 @@ const transactionContent = (
heading(headingText),
divider(),
panel([
text(`Method: ${method}`),
text(`Method: **${method}**`),
divider(),
text(`Amount: ${amountToHuman(amount, decimal)} ${token}`),
text(`Amount: **${amountToHuman(amount, decimal)} ${token}**`),
divider(),
text(`Pool Id: ${poolId}`),
text(`Pool Id: **${poolId}**`),
]),
]);
case 'nominationPools_bondExtra':
Expand All @@ -190,24 +200,28 @@ const transactionContent = (
return panel([
heading(headingText),
divider(),
panel([text(`Method: ${method}`), divider(), text(`Extra: ${extra}`)]),
panel([
text(`Method: **${method}**`),
divider(),
text(`Extra: **${extra}**`),
]),
]);
case 'noArgsMethods':
return panel([
heading(headingText),
divider(),
panel([
text(`Section: ${section}`),
text(`Section: **${section}**`),
divider(),
text(`Method: ${method}`),
text(`Method: **${method}**`),
]),
]);
default:
return panel([
heading(headingText),
divider(),
panel([
text(`Method: ${action}`),
text(`Method: **${action}**`),
divider(),
text(`Args:`),
divider(),
Expand Down

0 comments on commit 83c956b

Please sign in to comment.