Skip to content

Commit

Permalink
Release v0.2.5 (#116)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivy Astrix <[email protected]>
Signed-off-by: Kipkap <[email protected]>
Signed-off-by: Kiran Pachhai <[email protected]>
Co-authored-by: poi-son-ivy <[email protected]>
Co-authored-by: Kiran Pachhai <[email protected]>
  • Loading branch information
3 people authored Feb 26, 2024
1 parent 822af2d commit c711bf6
Show file tree
Hide file tree
Showing 56 changed files with 4,762 additions and 3,300 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/run-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint Snap Code

on: [push, pull_request]

jobs:
eslint:
name: Run ESLint For Snap
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
name: Check out source code

- uses: actions/setup-node@v2
name: Set up Node.js
with:
node-version: '18'
cache: 'yarn'
cache-dependency-path: packages/hedera-wallet-snap/packages/snap

- name: Install Dependencies in Subdirectory
run: yarn install
working-directory: ./packages/hedera-wallet-snap/packages/snap

- name: Run ESLint in Subdirectory
run: yarn lint
working-directory: ./packages/hedera-wallet-snap/packages/snap
27 changes: 27 additions & 0 deletions .github/workflows/run-jest-unit-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run Hedera Pulse Snap Unit Tests

on: [push]

jobs:
eslint:
name: Run Hedera Pulse Snap Unit Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
name: Check out source code

- uses: actions/setup-node@v2
name: Set up Node.js
with:
node-version: '18'
cache: 'yarn'
cache-dependency-path: packages/hedera-wallet-snap/packages/snap

- name: Install Dependencies in Subdirectory
run: yarn install
working-directory: ./packages/hedera-wallet-snap/packages/snap

- name: Run Snap Unit Tests
run: yarn test
working-directory: ./packages/hedera-wallet-snap/packages/snap
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/hedera-metamask-snaps",
"version": "0.2.4",
"version": "0.2.5",
"description": "A collection of Hedera related Metamask snaps that expose and utilize Hedera functionality inside Metamask",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
2 changes: 1 addition & 1 deletion packages/hedera-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"eslint-plugin-jest": "^27.4.0",
"eslint-plugin-jsdoc": "^46.8.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "5.0.0",
"prettier": "^3.0.3",
"prettier-plugin-packagejson": "^2.4.5",
"typescript": "^5.2.2"
Expand Down
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.2.4",
"version": "0.2.5",
"private": true,
"license": "Apache-2.0",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const GetAccountInfo: FC<Props> = ({
const getAccountInfoParams = {
accountId: accountId || undefined,
serviceFee,
fetchUsingMirrorNode: true,
} as GetAccountInfoRequestParams;

const response: any = await getAccountInfo(
network,
mirrorNodeUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ const TransferCrypto: FC<Props> = ({

const transferCryptoParams = {
transfers,
memo,
undefined,
serviceFee,
} as TransferCryptoRequestParams;
if (!_.isEmpty(memo)) {
transferCryptoParams.memo = memo;
}

const response: any = await transferCrypto(
network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
MetamaskActions,
} from '../../contexts/MetamaskContext';
import useModal from '../../hooks/useModal';
import { Account, StakeHbarRequestParams } from '../../types/snap';
import { shouldDisplayReconnectButton, stakeHbar } from '../../utils';
import { Account } from '../../types/snap';
import { shouldDisplayReconnectButton, unstakeHbar } from '../../utils';
import { Card, SendHelloButton } from '../base';
import ExternalAccount, {
GetExternalAccountRef,
Expand All @@ -49,14 +49,9 @@ const UnstakeHbar: FC<Props> = ({ network, mirrorNodeUrl, setAccountInfo }) => {
const externalAccountParams =
externalAccountRef.current?.handleGetAccountParams();

const stakeHbarParams = {
nodeId: null,
accountId: null,
} as StakeHbarRequestParams;
const response: any = await stakeHbar(
const response: any = await unstakeHbar(
network,
mirrorNodeUrl,
stakeHbarParams,
externalAccountParams,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*-
*
* Hedera Wallet Snap
*
* Copyright (C) 2024 Tuum Tech
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { FC, useContext, useRef, useState } from 'react';
import {
MetaMaskContext,
MetamaskActions,
} from '../../../contexts/MetamaskContext';
import useModal from '../../../hooks/useModal';
import { Account, CreateTokenRequestParams } from '../../../types/snap';
import { createToken, shouldDisplayReconnectButton } from '../../../utils';
import { Card, SendHelloButton } from '../../base';
import ExternalAccount, {
GetExternalAccountRef,
} from '../../sections/ExternalAccount';

type Props = {
network: string;
mirrorNodeUrl: string;
setAccountInfo: React.Dispatch<React.SetStateAction<Account>>;
};

const CreateToken: FC<Props> = ({ network, mirrorNodeUrl, setAccountInfo }) => {
const [state, dispatch] = useContext(MetaMaskContext);
const [loading, setLoading] = useState(false);
const { showModal } = useModal();
const [assetType, setAssetType] = useState<'TOKEN' | 'NFT'>('TOKEN');
const [tokenName, setTokenName] = useState('');
const [tokenSymbol, setTokenSymbol] = useState('');
const [tokenDecimals, setTokenDecimals] = useState(1);
const [initialSupply, setInitialSupply] = useState(100);
const [supplyPublicKey, setSupplyPublicKey] = useState('');

const externalAccountRef = useRef<GetExternalAccountRef>(null);

const handleCreateTokenClick = async () => {
setLoading(true);
try {
const externalAccountParams =
externalAccountRef.current?.handleGetAccountParams();

const createTokenParams = {
assetType,
name: tokenName,
symbol: tokenSymbol,
decimals: assetType === 'NFT' ? 0 : tokenDecimals,
supplyType: 'INFINITE',
initialSupply: assetType === 'NFT' ? 0 : initialSupply,
} as CreateTokenRequestParams;
if (assetType === 'NFT') {
createTokenParams.supplyPublicKey = supplyPublicKey;
}
const response: any = await createToken(
network,
mirrorNodeUrl,
createTokenParams,
externalAccountParams,
);

const { receipt, currentAccount } = response;

setAccountInfo(currentAccount);
console.log('receipt: ', receipt);

showModal({
title: 'Transaction Receipt',
content: JSON.stringify({ receipt }, null, 4),
});
} catch (e) {
console.error(e);
dispatch({ type: MetamaskActions.SetError, payload: e });
}
setLoading(false);
};

return (
<Card
content={{
title: 'createToken',
description: 'Create a token on Hedera using Hedera Token Service.',
form: (
<>
<ExternalAccount ref={externalAccountRef} />
<label>
Asset Type
<select
style={{ width: '100%' }}
value={assetType}
onChange={(e) =>
setAssetType(e.target.value as 'TOKEN' | 'NFT')
}
>
<option value="TOKEN">TOKEN</option>
<option value="NFT">NFT</option>
</select>
</label>
<br />

<label>
Enter the name for your token/NFT
<input
type="text"
style={{ width: '100%' }}
value={tokenName}
placeholder="Token Name"
onChange={(e) => setTokenName(e.target.value)}
/>
</label>
<br />

<label>
Enter the symbol for your token/NFT
<input
type="text"
style={{ width: '100%' }}
value={tokenSymbol}
placeholder="Token Symbol"
onChange={(e) => setTokenSymbol(e.target.value)}
/>
</label>
<br />

{assetType === 'TOKEN' && (
<>
<label>
Enter the decimals for your token
<input
type="number"
style={{ width: '100%' }}
value={tokenDecimals}
placeholder="Enter the number of decimals"
onChange={(e) =>
setTokenDecimals(parseFloat(e.target.value))
}
/>
</label>
<br />
<label>
Enter the initial supply for your token
<input
type="number"
style={{ width: '100%' }}
value={initialSupply}
placeholder="Enter the amount of initial supply"
onChange={(e) =>
setInitialSupply(parseFloat(e.target.value))
}
/>
</label>
<br />
</>
)}

{assetType === 'NFT' && (
<>
<label>
Enter the supply public key for your NFT
<input
type="text"
style={{ width: '100%' }}
value={supplyPublicKey}
placeholder="Enter the supply key"
onChange={(e) => setSupplyPublicKey(e.target.value)}
/>
</label>
<br />
</>
)}
</>
),
button: (
<SendHelloButton
buttonText="Create Token"
onClick={handleCreateTokenClick}
disabled={!state.installedSnap}
loading={loading}
/>
),
}}
disabled={!state.installedSnap}
fullWidth={
state.isFlask &&
Boolean(state.installedSnap) &&
!shouldDisplayReconnectButton(state.installedSnap)
}
/>
);
};

export { CreateToken };
7 changes: 7 additions & 0 deletions packages/hedera-wallet-snap/packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Tokens from '../components/cards/Tokens';
import { TransferCrypto } from '../components/cards/TransferCrypto';
import { UnstakeHbar } from '../components/cards/UnstakeHbar';
import { AssociateTokens } from '../components/cards/hts/AssociateTokens';
import { CreateToken } from '../components/cards/hts/CreateToken';
import { networkOptions } from '../config/constants';
import {
CardContainer,
Expand Down Expand Up @@ -211,6 +212,12 @@ const Index = () => {
setAccountInfo={setAccountInfo}
/>

<CreateToken
network={currentNetwork.value}
mirrorNodeUrl={mirrorNodeUrl}
setAccountInfo={setAccountInfo}
/>

<DeleteAccount
network={currentNetwork.value}
mirrorNodeUrl={mirrorNodeUrl}
Expand Down
Loading

0 comments on commit c711bf6

Please sign in to comment.