Skip to content

Commit

Permalink
Added memo to home page (#731)
Browse files Browse the repository at this point in the history
Signed-off-by: Himalayan Dev <[email protected]>
  • Loading branch information
himalayan-dev authored Oct 10, 2024
1 parent 64fc271 commit dad5114
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/hedera-wallet-snap/packages/site/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/hedera-wallet-snap-site",
"version": "0.6.0",
"version": "0.6.1",
"private": true,
"license": "Apache-2.0",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions packages/hedera-wallet-snap/packages/snap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [0.6.1](https://github.com/hashgraph/hedera-metamask-snaps/compare/v0.6.1...v0.6.1) (2024-10-10)

### :page_with_curl: Documentation

- Refer to the [Hedera Wallet Snap Wiki](https://docs.tuum.tech/hedera-wallet-snap/) for more info on how the snap works and how to integrate it into your own application.

### :rocket: Features

- [Added memo support to snap home page](https://github.com/hashgraph/hedera-metamask-snaps/issues/730)

### :bug: Bug Fixes

- [Fixed an issue whereby snap wasn't able to retrieve lazy-created account](https://github.com/hashgraph/hedera-metamask-snaps/issues/732)

## [0.6.0](https://github.com/hashgraph/hedera-metamask-snaps/compare/v0.6.0...v0.6.0) (2024-09-09)

### :page_with_curl: Documentation
Expand Down
2 changes: 1 addition & 1 deletion packages/hedera-wallet-snap/packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/hedera-wallet-snap",
"version": "0.6.0",
"version": "0.6.1",
"description": "Hedera Wallet 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.",
"keywords": [
"MetaMask",
Expand Down
4 changes: 2 additions & 2 deletions packages/hedera-wallet-snap/packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "0.6.0",
"version": "0.6.1",
"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": "git+https://github.com/hashgraph/hedera-metamask-snaps.git"
},
"source": {
"shasum": "4Cq3R8uZ7z77wWYfS0sOQKhOl/TOd9Obh+konXYj7Yo=",
"shasum": "3upIALuaGlohk4pbtltQLT4Do8+gMcff90QDRYvvkug=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
43 changes: 28 additions & 15 deletions packages/hedera-wallet-snap/packages/snap/src/custom-ui/onHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ export const OnHomePageUI: OnHomePageHandler = async () => {
// Get connected metamask account
const connectedAddress = await SnapAccounts.getCurrentMetamaskAccount();

try {
// Set current account
await SnapAccounts.setCurrentAccount(
origin,
state,
null,
network,
mirrorNodeUrl,
false,
);
const snapAddress = await SnapAccounts.setCurrentAccount(
origin,
state,
null,
network,
mirrorNodeUrl,
false,
true,
);

const walletSnapParams: WalletSnapParams = {
origin,
state,
};
const walletSnapParams: WalletSnapParams = {
origin,
state,
};

try {
const accountInfo: AccountInfo = await GetAccountInfoFacade.getAccountInfo(
walletSnapParams,
{} as GetAccountInfoRequestParams,
Expand Down Expand Up @@ -102,6 +102,10 @@ export const OnHomePageUI: OnHomePageHandler = async () => {
name: 'amount',
placeholder: 'Amount',
}),
input({
name: 'memo',
placeholder: 'Memo(Needed for exchange transfers)',
}),
button({
value: 'Send Hbar',
buttonType: 'submit',
Expand Down Expand Up @@ -138,11 +142,20 @@ export const OnHomePageUI: OnHomePageHandler = async () => {
text(`**Mirror Node URL**: ${mirrorNodeUrl}`),
divider(),
text(`**Account Id**: Could not fetch account id.`),
text(`**Account EVM Address**: Could not fetch EVM address.`),
text(`**Account EVM Address**:`),
copyable(snapAddress),
text(`**Associated Metamask Address**:`),
copyable(connectedAddress),
divider(),
button({
value: 'Export Snap Account Private Key',
name: 'btn-export-snap-account-private-key',
}),
divider(),
text(`**FAQs**:`),
text(
`**Why is my MetaMask address different from my Hedera EVM address?**: Since MetaMask does not allow Snaps to access the private keys of MetaMask accounts, Hedera Wallet Snap creates a new account with its own private key. However, this new account is still associated with the MetaMask account so you can easily get back to your account on any device as long as you're connected to the same MetaMask account.`,
),
text(
`**Why is my account not activated?**: On Hedera, until a transaction is sent to the network, the account is not activated. Please visit [Pulse](https://pulse.tuum.tech) to activate your account for free.`,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ export const onUserInputUI: OnUserInputHandler = async ({ event }) => {
const { network, mirrorNodeUrl } = HederaUtils.getNetworkInfoFromUser(null);

// Set current account
await SnapAccounts.setCurrentAccount(
const snapAddress = await SnapAccounts.setCurrentAccount(
origin,
state,
null,
network,
mirrorNodeUrl,
false,
true,
);

const walletSnapParams: WalletSnapParams = {
Expand All @@ -72,6 +73,9 @@ export const onUserInputUI: OnUserInputHandler = async ({ event }) => {
} as SimpleTransfer,
],
} as TransferCryptoRequestParams;
if (event.value.memo) {
params.memo = event.value.memo as string;
}
result = await TransferCryptoFacade.transferCrypto(
walletSnapParams,
params,
Expand Down Expand Up @@ -101,9 +105,7 @@ export const onUserInputUI: OnUserInputHandler = async ({ event }) => {
'Warning: Never disclose this key. Anyone with your private keys can steal any assets held in your account.',
),
copyable(
state.accountState[state.currentAccount.hederaEvmAddress][
state.currentAccount.network
].keyStore.privateKey,
state.accountState[snapAddress][network].keyStore.privateKey,
),
]),
},
Expand Down
27 changes: 24 additions & 3 deletions packages/hedera-wallet-snap/packages/snap/src/snap/SnapAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class SnapAccounts {
* @param network - Hedera network.
* @param mirrorNodeUrl - Hedera mirror node URL.
* @param isExternalAccount - Whether this is a metamask or a non-metamask account.
* @param returnEarly - Whether to return early.
* @returns Nothing.
*/
public static async setCurrentAccount(
Expand All @@ -105,7 +106,8 @@ export class SnapAccounts {
network: string,
mirrorNodeUrl: string,
isExternalAccount: boolean,
): Promise<void> {
returnEarly = false,
): Promise<string> {
let metamaskEvmAddress = '';
let externalEvmAddress = '';
let connectedAddress = '';
Expand Down Expand Up @@ -189,7 +191,7 @@ export class SnapAccounts {
await SnapAccounts.initAccountState(state, network, connectedAddress);
}

await SnapAccounts.importMetaMaskAccount(
return await SnapAccounts.importMetaMaskAccount(
origin,
state,
network,
Expand All @@ -198,6 +200,7 @@ export class SnapAccounts {
metamaskEvmAddress,
externalEvmAddress,
keyStore,
returnEarly,
);
}

Expand Down Expand Up @@ -546,6 +549,8 @@ export class SnapAccounts {
* @param metamaskEvmAddress - Metamask EVM address.
* @param externalEvmAddress - External EVM address.
* @param keyStore - Keystore for private, public keys and EVM address.
* @param returnEarly - Whether to return early.
* @returns Result.
*/
public static async importMetaMaskAccount(
_origin: string,
Expand All @@ -556,7 +561,8 @@ export class SnapAccounts {
metamaskEvmAddress: string,
externalEvmAddress: string,
keyStore: KeyStore,
): Promise<void> {
returnEarly = false,
): Promise<string> {
const { curve, privateKey, publicKey, address } = keyStore;

console.log('Retrieving account info from Hedera Mirror node');
Expand All @@ -567,6 +573,19 @@ export class SnapAccounts {
if (_.isEmpty(accountInfo)) {
const errMessage = `Could not get account info from Hedera Mirror Node on '${network}'. Address: ${address}. Please try again.`;
console.error(errMessage);
if (returnEarly) {
// eslint-disable-next-line require-atomic-updates
state.accountState[connectedAddress][network].keyStore = {
curve,
privateKey,
publicKey,
address,
hederaAccountId: '',
};

await SnapState.updateState(state);
return address;
}
throw rpcErrors.resourceNotFound({
message: errMessage,
data: address,
Expand Down Expand Up @@ -600,5 +619,7 @@ export class SnapAccounts {
};

await SnapState.updateState(state);

return address;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2576,8 +2576,8 @@ export class HederaUtils {
result.memo = mirrorNodeData.memo;
result.evmAddress = mirrorNodeData.evm_address;
result.key = {
type: mirrorNodeData?.key?._type,
key: mirrorNodeData?.key?.key,
type: mirrorNodeData?.key?._type ?? '',
key: mirrorNodeData?.key?.key ?? '',
};
result.autoRenewPeriod = String(mirrorNodeData.auto_renew_period);
result.ethereumNonce = String(mirrorNodeData.ethereum_nonce);
Expand Down

0 comments on commit dad5114

Please sign in to comment.