Skip to content

Commit

Permalink
Fix bugs and change texts (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi authored Aug 7, 2024
1 parent e101fbb commit 7e99b08
Show file tree
Hide file tree
Showing 14 changed files with 1,536 additions and 1,426 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.0] - 2024-08-07
### Changed
- Changed the transaction send flow
- The snap no longer waits for the transaction to be confirmed on the Qtum chain. It immediately returns the transaction hash as soon as it is received.
- There is a possibility that if the get transaction method by hash is used with the newly acquired hash, the get transaction method can revert with the following message: "invalid hash."
- `UI` for homepage & creating wallet dialog

### Fixed
- `eth_sendTransaction` timeout issue

## [0.1.0] - 2024-06-24
### Added
- Initial release of the snap.

[Unreleased]: https://github.com/qtumproject/qtum-extension-wallet/compare/0.1.0...HEAD
[Unreleased]: https://github.com/qtumproject/qtum-extension-wallet/compare/0.2.0...HEAD
[0.2.0]: https://github.com/qtumproject/qtum-extension-wallet/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/qtumproject/qtum-extension-wallet/releases/tag/0.1.0



4 changes: 3 additions & 1 deletion packages/connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qtumproject/qtum-wallet-connector",
"version": "0.1.0",
"version": "0.2.0",
"description": "A Provider to be used in ethers.js to interact with Qtum's wallet",
"repository": {
"type": "git",
Expand Down Expand Up @@ -53,6 +53,8 @@
"@ethersproject/abstract-provider": "5.7.0",
"@ethersproject/properties": "^5.7.0",
"@ethersproject/providers": "5.7.2",
"bs58check": "^4.0.0",
"buffer": "^6.0.3",
"compare-versions": "^6.1.0",
"ethers": "5.7.2"
},
Expand Down
32 changes: 32 additions & 0 deletions packages/connector/src/helpers/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import bs58check from 'bs58check';
// eslint-disable-next-line
import { Buffer } from 'buffer';

// eslint-disable-next-line jsdoc/require-jsdoc
export function toBase58Check(ethAddress: string, version: number) {
const hash = Buffer.from(ethAddress.slice(2), 'hex');
const payload = Buffer.allocUnsafe(21);
payload.writeUInt8(version, 0);
hash.copy(payload, 1);
return bs58check.encode(payload);
}

// eslint-disable-next-line jsdoc/require-jsdoc
export function fromBase58Check(qtumAddress: string) {
const payload = bs58check.decode(qtumAddress);
const buffer = Buffer.from(payload);
return `0x${buffer.toString('hex').slice(2)}`;
}

// eslint-disable-next-line jsdoc/require-jsdoc
export function isAddressMatchNetwork(qtumAddress: string, chainId: number) {
const payload = bs58check.decode(qtumAddress);

const version = {
8889: 120,
81: 58,
}[chainId];

// Check if the version matches
return payload[0] === version;
}
1 change: 1 addition & 0 deletions packages/connector/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './snap';
export * from './promise';
export * from './error-helper';
export * from './address';
2 changes: 1 addition & 1 deletion packages/connector/src/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.1.0"
"version": "0.2.0"
}
5 changes: 3 additions & 2 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qtumproject/qtum-wallet",
"version": "0.1.0",
"version": "0.2.0",
"description": "Qtum Wallet is a MetaMask Snap that plays the role of the RPC proxy that accepts requests to the MetaMask and forwards them to the Qtum network with the Qtum ethers adapter.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -29,7 +29,7 @@
"serve": "mm-snap serve",
"start": "nodemon --watch src/ --ext ts --exec 'yarn build && yarn serve'",
"test": "yarn test:wallet --passWithNoTests",
"test:wallet": "node --experimental-vm-modules --trace-warnings ../../node_modules/jest/bin/jest.js --findRelatedTests ./src/tests/wallet.test.ts",
"test:wallet": "jest --findRelatedTests ./src/tests/wallet.test.ts",
"typia:generate": "typia generate --input src/typia-templates --output src/typia-generated --project tsconfig.json",
"preversion": "yarn && yarn build && git add snap.manifest.json"
},
Expand All @@ -44,6 +44,7 @@
"@metamask/transaction-controller": "^27.0.1",
"@qtumproject/qtum-wallet-connector": "workspace:^",
"buffer": "6.0.3",
"eth-block-tracker": "^8.1.0",
"ethers": "5.7.2",
"intl": "1.2.5",
"key-did-provider-ed25519": "3.0.2",
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.1.0",
"version": "0.2.0",
"description": "Qtum Wallet is a MetaMask Snap that plays the role of the RPC proxy that accepts requests to the MetaMask and forwards them to the Qtum network with the Qtum ethers adapter.",
"proposedName": "Qtum Wallet",
"repository": {
"type": "git",
"url": "https://github.com/qtumproject/qtum-extension-wallet.git"
},
"source": {
"shasum": "GCvOxV52DlGWa+wGp9FEkLAV8STusflG65XGtujPtEc=",
"shasum": "SB/fFdS7jmrx1Fp/c98Gx2RQzo0+nbBOXeplPvYc6VU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
26 changes: 20 additions & 6 deletions packages/snap/src/helpers/format.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { toBase58Check } from '@qtumproject/qtum-wallet-connector';
import type { BigNumberish } from 'ethers';
import { ethers } from 'ethers';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import qtum from 'qtumjs-lib';

import { getWallet } from '@/config';
import { getProvider, getWallet } from '@/config';
import { DEFAULT_NETWORKS_RPC_URLS } from '@/consts';

// eslint-disable-next-line
export function formatUnits(
Expand All @@ -20,12 +19,27 @@ export function formatUnits(
// eslint-disable-next-line
export async function getQtumAddress(walletEthAddress?: string) {
let addr = walletEthAddress;
let chainId = Number(DEFAULT_NETWORKS_RPC_URLS[0].chainId);

if (!addr) {
const wallet = await getWallet();
addr = wallet.address;

const provider = await getProvider();

const network = await provider.getNetwork();

chainId = network.chainId;
}

const version = {
8889: 120,
81: 58,
}[chainId];

if (!version) {
throw new Error('Unsupported chainId');
}

const hash = Buffer.from(addr.slice(2), 'hex');
return qtum.address.toBase58Check(hash, 120);
return toBase58Check(addr, version);
}
1 change: 0 additions & 1 deletion packages/snap/src/helpers/parsers/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const readAddressAsContract = async (
try {
contractCode = await provider.getCode(address);
} catch (err) {
// TODO(@dbrans): Dangerous to swallow errors here.
contractCode = null;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/snap/src/helpers/ui/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export const onHomePage: OnHomePageHandler = async () => {
? [
divider(),

text('Your eth address:'),
text('Your Qtum address:'),
copyable({
value: wallet.address,
value: (await getQtumAddress()) || 'Not created yet',
}),

text('Your qtum address:'),
text('Your Qtum address in hexadecimal format:'),
copyable({
value: (await getQtumAddress()) || 'Not created yet',
value: wallet.address,
}),
]
: []),
Expand Down
8 changes: 4 additions & 4 deletions packages/snap/src/helpers/ui/wallet-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export async function showWalletCreatedSnapDialog(
heading('Your Wallet'),
divider(),

text('Your eth address:'),
text('Your Qtum address:'),
copyable({
value: ethAddr,
value: qtumAddr,
}),

text('Your qtum address:'),
text('Your Qtum address in hexadecimal format:'),
copyable({
value: qtumAddr,
value: ethAddr,
}),
]);
}
Loading

0 comments on commit 7e99b08

Please sign in to comment.