Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Changed the package names
Browse files Browse the repository at this point in the history
  • Loading branch information
kpachhai committed Oct 25, 2023
1 parent ad060b2 commit e88fe30
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 108 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# @metamask/template-snap-monorepo

This repository demonstrates how to develop a snap with TypeScript. For detailed instructions, see [the MetaMask documentation](https://docs.metamask.io/guide/snaps.html#serving-a-snap-to-your-local-environment).

MetaMask Snaps is a system that allows anyone to safely expand the capabilities of MetaMask. A _snap_ is a program that we run in an isolated environment that can customize the wallet experience.

## Snaps is pre-release software

To interact with (your) Snaps, you will need to install [MetaMask Flask](https://metamask.io/flask/), a canary distribution for developers that provides access to upcoming features.
# @tuum-tech/hedera-wallet-snap-monorepo

## Getting Started

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@tuum-tech/hedera-pulse-monorepo",
"name": "@tuum-tech/hedera-wallet-snap-monorepo",
"version": "0.1.0",
"private": true,
"description": "",
"homepage": "https://github.com/tuum-tech/hedera-pulse#readme",
"homepage": "https://github.com/tuum-tech/hedera-wallet-snap#readme",
"bugs": {
"url": "https://github.com/tuum-tech/hedera-pulse/issues"
"url": "https://github.com/tuum-tech/hedera-wallet-snap/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tuum-tech/hedera-pulse.git"
"url": "git+https://github.com/tuum-tech/hedera-wallet-snap.git"
},
"license": "(MIT-0 OR Apache-2.0)",
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/site/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@tuum-tech/hedera-pulse-site",
"name": "@tuum-tech/hedera-wallet-snap-site",
"version": "0.1.0",
"private": true,
"license": "(MIT-0 OR Apache-2.0)",
Expand Down
13 changes: 2 additions & 11 deletions packages/snap/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# TypeScript Example Snap
# Hedera Wallet Snap

This snap demonstrates how to develop a snap with TypeScript. It is a simple
snap that displays a confirmation dialog when the `hello` JSON-RPC method is
called.

## Testing

The snap comes with some basic tests, to demonstrate how to write tests for
snaps. To test the snap, run `yarn test` in this directory. This will use
[`@metamask/snaps-jest`](https://github.com/MetaMask/snaps/tree/main/packages/snaps-jest)
to run the tests in `src/index.test.ts`.
Hedera Wallet unlocks wallet functionality via Metamask that any other apps can interact with, thereby turning Metamask into a native Hedera wallet without relying on Hedera JSON-RPC Relay.
8 changes: 4 additions & 4 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@tuum-tech/hedera-pulse",
"name": "@tuum-tech/hedera-wallet-snap",
"version": "0.1.0",
"description": "Hedera Pulse Snap unlocks wallet functionality via Metamask that any other apps can interact with, thereby turning Metamask into a native Hedera wallet without relying on Hedera JSON-RPC Relay.",
"description": "Hedera Wallet unlocks wallet functionality via Metamask that any other apps can interact with, thereby turning Metamask into a native Hedera wallet without relying on Hedera JSON-RPC Relay.",
"keywords": [
"MetaMask",
"Snaps",
"Hedera Hashgraph",
"HBAR"
],
"homepage": "https://github.com/tuum-tech/hedera-pulse",
"homepage": "https://github.com/tuum-tech/hedera-wallet-snap",
"repository": {
"type": "git",
"url": "https://github.com/tuum-tech/hedera-pulse.git"
"url": "https://github.com/tuum-tech/hedera-wallet-snap.git"
},
"license": "(MIT-0 OR Apache-2.0)",
"author": {
Expand Down
10 changes: 5 additions & 5 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"version": "0.1.0",
"description": "Hedera Pulse Snap unlocks wallet functionality via Metamask that any other apps can interact with, thereby turning Metamask into a native Hedera wallet without relying on Hedera JSON-RPC Relay.",
"proposedName": "Hedera Pulse",
"description": "Hedera Wallet unlocks wallet functionality via Metamask that any other apps can interact with, thereby turning Metamask into a native Hedera wallet without relying on Hedera JSON-RPC Relay.",
"proposedName": "Hedera Wallet",
"repository": {
"type": "git",
"url": "https://github.com/tuum-tech/hedera-pulse.git"
"url": "https://github.com/tuum-tech/hedera-wallet-snap.git"
},
"source": {
"shasum": "mlUPY6AfdzeXLaGkSP9uoaO1a+w8SdSqqpVbPgCjU98=",
"shasum": "lIPUuxtJBK1FGTeeiLgxiTbw+95PgnIxXZKNEkSs16I=",
"location": {
"npm": {
"filePath": "dist/snap.js",
"iconPath": "images/icon.svg",
"packageName": "@tuum-tech/hedera-pulse",
"packageName": "@tuum-tech/hedera-wallet-snap",
"registry": "https://registry.npmjs.org/"
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getAccountInfo } from './rpc/account/getAccountInfo';
import { transferCrypto } from './rpc/account/transferCrypto';
import { setCurrentAccount } from './snap/account';
import { getSnapStateUnchecked } from './snap/state';
import { PulseSnapParams } from './types/state';
import { WalletSnapParams } from './types/state';
import { init } from './utils/init';
import {
getMirrorNodeFlagIfExists,
Expand Down Expand Up @@ -69,7 +69,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
`Current account: ${JSON.stringify(state.currentAccount, null, 4)}`,
);

const pulseSnapParams: PulseSnapParams = {
const walletSnapParams: WalletSnapParams = {
origin,
state,
mirrorNodeUrl,
Expand Down Expand Up @@ -98,22 +98,22 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
return {
currentAccount: state.currentAccount,
accountInfo: await getAccountInfo(
pulseSnapParams,
walletSnapParams,
request.params.accountId,
),
};
}
case 'getAccountBalance': {
return {
currentAccount: state.currentAccount,
accountBalance: await getAccountBalance(pulseSnapParams),
accountBalance: await getAccountBalance(walletSnapParams),
};
}
case 'transferCrypto': {
isValidTransferCryptoParams(request.params);
return {
currentAccount: state.currentAccount,
receipt: await transferCrypto(pulseSnapParams, request.params),
receipt: await transferCrypto(walletSnapParams, request.params),
};
}
default:
Expand Down
8 changes: 4 additions & 4 deletions packages/snap/src/rpc/account/getAccountBalance.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { createHederaClient } from '../../snap/account';
import { updateSnapState } from '../../snap/state';
import { PulseSnapParams } from '../../types/state';
import { WalletSnapParams } from '../../types/state';

/**
* A query that returns the account balance for the specified account.
* Requesting an account balance is currently free of charge. Queries do
* not change the state of the account or require network consensus. The
* information is returned from a single node processing the query.
*
* @param pulseSnapParams - Pulse snap params.
* @param walletSnapParams - Wallet snap params.
* @returns Account Balance.
*/
export async function getAccountBalance(
pulseSnapParams: PulseSnapParams,
walletSnapParams: WalletSnapParams,
): Promise<number> {
const { state } = pulseSnapParams;
const { state } = walletSnapParams;

const { hederaAccountId, hederaEvmAddress, network } = state.currentAccount;

Expand Down
8 changes: 4 additions & 4 deletions packages/snap/src/rpc/account/getAccountInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createHederaClient } from '../../snap/account';
import { generateCommonPanel, snapDialog } from '../../snap/dialog';
import { updateSnapState } from '../../snap/state';
import { AccountInfo } from '../../types/account';
import { PulseSnapParams, SnapDialogParams } from '../../types/state';
import { WalletSnapParams, SnapDialogParams } from '../../types/state';
import {
calculateHederaQueryFees,
deductServiceFee,
Expand All @@ -27,15 +27,15 @@ import {
* available so these fields contain current data. Historical ethereum nonce information is also
* currently not available and may not be the exact value at a provided timestamp.
*
* @param pulseSnapParams - Pulse snap params.
* @param walletSnapParams - Wallet snap params.
* @param accountId - Hedera Account Id.
* @returns Account Info.
*/
export async function getAccountInfo(
pulseSnapParams: PulseSnapParams,
walletSnapParams: WalletSnapParams,
accountId?: string,
): Promise<AccountInfo> {
const { origin, state, mirrorNodeUrl } = pulseSnapParams;
const { origin, state, mirrorNodeUrl } = walletSnapParams;

const { hederaAccountId, hederaEvmAddress, network } = state.currentAccount;

Expand Down
10 changes: 5 additions & 5 deletions packages/snap/src/rpc/account/transferCrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import {
import { createHederaClient } from '../../snap/account';
import { snapDialog } from '../../snap/dialog';
import { TransferCryptoRequestParams } from '../../types/params';
import { PulseSnapParams, SnapDialogParams } from '../../types/state';
import { WalletSnapParams, SnapDialogParams } from '../../types/state';

/**
* Transfer crypto(hbar or other tokens).
*
* @param pulseSnapParams - Pulse snap params.
* @param walletSnapParams - Wallet snap params.
* @param transferCryptoParams - Parameters for transferring crypto.
* @returns Account Info.
*/
export async function transferCrypto(
pulseSnapParams: PulseSnapParams,
walletSnapParams: WalletSnapParams,
transferCryptoParams: TransferCryptoRequestParams,
): Promise<TxReceipt> {
const { origin, state } = pulseSnapParams;
const { origin, state } = walletSnapParams;

const {
transfers = [] as SimpleTransfer[],
Expand All @@ -37,7 +37,7 @@ export async function transferCrypto(
if (!acc[transfer.asset]) {
acc[transfer.asset] = 0;
}
acc[transfer.asset] += transfer.amount * 0.001; // Add 0.1% of the amount
acc[transfer.asset] += transfer.amount * 0.0001; // Add 0.01% of the amount; This can be changed in the future
return acc;
}, {});

Expand Down
20 changes: 10 additions & 10 deletions packages/snap/src/snap/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
NetworkParams,
} from '../types/account';
import { hederaNetworks } from '../types/constants';
import { KeyStore, PulseSnapState, SnapDialogParams } from '../types/state';
import { KeyStore, SnapDialogParams, WalletSnapState } from '../types/state';
import { generateWallet } from '../utils/keyPair';
import { generateCommonPanel, snapDialog } from './dialog';
import { validHederaNetwork } from './network';
Expand Down Expand Up @@ -46,15 +46,15 @@ function ensure0xPrefix(address: string): string {
* Function that returns account info of the currently selected MetaMask account.
*
* @param origin - Source.
* @param state - PulseSnapState.
* @param state - WalletSnapState.
* @param params - Parameters that were passed by the user.
* @param mirrorNodeUrl - Hedera mirror node URL.
* @param isExternalAccount - Whether this is a metamask or a non-metamask account.
* @returns MetaMask Hedera client.
*/
export async function setCurrentAccount(
origin: string,
state: PulseSnapState,
state: WalletSnapState,
params: unknown,
mirrorNodeUrl: string,
isExternalAccount: boolean,
Expand Down Expand Up @@ -131,7 +131,7 @@ export async function setCurrentAccount(
} else {
// Handle metamask connected account
connectedAddress = await getCurrentMetamaskAccount();
// Generate a new wallet according to the Hedera Pulse's entrophy combined with the currently connected EVM address
// Generate a new wallet according to the Hedera Wallet's entrophy combined with the currently connected EVM address
const res = await generateWallet(connectedAddress);
if (!res) {
console.log('Failed to generate snap wallet for DID operations');
Expand All @@ -158,7 +158,7 @@ export async function setCurrentAccount(
!Object.keys(state.accountState[connectedAddress]).includes(network))
) {
console.log(
`The address ${connectedAddress} has NOT yet been configured for the '${network}' network in the Hedera Pulse Snap. Configuring now...`,
`The address ${connectedAddress} has NOT yet been configured for the '${network}' network in the Hedera Wallet. Configuring now...`,
);
await initAccountState(state, network, connectedAddress);
}
Expand All @@ -181,14 +181,14 @@ export async function setCurrentAccount(
* Connect EVM Account.
*
* @param origin - Source.
* @param state - Pulse state.
* @param state - Wallet state.
* @param network - Hedera network.
* @param curve - Public Key curve('ECDSA_SECP256K1' | 'ED25519').
* @param evmAddress - EVM Account address.
*/
async function connectEVMAccount(
origin: string,
state: PulseSnapState,
state: WalletSnapState,
network: string,
curve: 'ECDSA_SECP256K1' | 'ED25519',
evmAddress: string,
Expand Down Expand Up @@ -256,15 +256,15 @@ async function connectEVMAccount(
* Connect Hedera Account.
*
* @param origin - Source.
* @param state - Pulse state.
* @param state - Wallet state.
* @param network - Hedera network.
* @param mirrorNodeUrl - Hedera mirror node URL.
* @param curve - Public Key curve('ECDSA_SECP256K1' | 'ED25519').
* @param accountId - Hedera Account id.
*/
async function connectHederaAccount(
origin: string,
state: PulseSnapState,
state: WalletSnapState,
network: string,
mirrorNodeUrl: string,
curve: 'ECDSA_SECP256K1' | 'ED25519',
Expand Down Expand Up @@ -401,7 +401,7 @@ async function connectHederaAccount(
*/
export async function importMetaMaskAccount(
origin: string,
state: PulseSnapState,
state: WalletSnapState,
network: string,
mirrorNode: string,
connectedAddress: string,
Expand Down
10 changes: 5 additions & 5 deletions packages/snap/src/snap/dapp.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { PulseSnapState } from '../types/state';
import { WalletSnapState } from '../types/state';
import { updateSnapState } from './state';

/**
* Function that lets you add a friendly dApp.
*
* @param state - PulseSnapState.
* @param state - WalletSnapState.
* @param dapp - Dapp.
*/
export async function addFriendlyDapp(state: PulseSnapState, dapp: string) {
export async function addFriendlyDapp(state: WalletSnapState, dapp: string) {
state.snapConfig.dApp.friendlyDapps.push(dapp);
await updateSnapState(state);
}

/**
* Function that removes a friendly dApp.
*
* @param state - PulseSnapState.
* @param state - WalletSnapState.
* @param dapp - Dapp.
*/
export async function removeFriendlyDapp(state: PulseSnapState, dapp: string) {
export async function removeFriendlyDapp(state: WalletSnapState, dapp: string) {
// FIXME: TEST IF YOU CAN REFERENCE FRIENDLY DAPS
// let friendlyDapps = state.snapConfig.dApp.friendlyDapps;
// friendlyDapps = friendlyDapps.filter((app) => app !== dapp);
Expand Down
6 changes: 3 additions & 3 deletions packages/snap/src/snap/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { divider, heading, panel, Panel, text } from '@metamask/snaps-ui';

import { PulseSnapState, SnapDialogParams } from '../types/state';
import { SnapDialogParams, WalletSnapState } from '../types/state';
import { updateSnapState } from './state';

/**
* Function that toggles the disablePopups flag in the config.
*
* @param state - PulseSnapState.
* @param state - WalletSnapState.
*/
export async function updatePopups(state: PulseSnapState) {
export async function updatePopups(state: WalletSnapState) {
state.snapConfig.dApp.disablePopups = !state.snapConfig.dApp.disablePopups;
await updateSnapState(state);
}
Expand Down
Loading

0 comments on commit e88fe30

Please sign in to comment.