Skip to content

Commit

Permalink
Merge pull request #67 from kaiachain/feat/ethers-ext-unit-conversion-v6
Browse files Browse the repository at this point in the history
feat: update unit conversion helpers for v6
  • Loading branch information
Sotatek-TanHoang authored Dec 24, 2024
2 parents e088ae0 + b6eee68 commit bfa4445
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 83 deletions.
26 changes: 17 additions & 9 deletions ethers-ext/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,25 @@ module.exports = {
"@typescript-eslint/ban-ts-comment": "off",

// imports
"import/order": ["warn", {
"alphabetize": { "order": "asc", "caseInsensitive": true },
"pathGroups": [
{ "pattern": "@kaiachain/**", "group": "parent", "position": "after" },
],
"newlines-between": "always",
"pathGroupsExcludedImportTypes": ["@kaiachain/**"],
}],
"import/order": [
"warn",
{
alphabetize: { order: "asc", caseInsensitive: true },
pathGroups: [
{ pattern: "@kaiachain/**", group: "parent", position: "after" },
],
"newlines-between": "always",
pathGroupsExcludedImportTypes: ["@kaiachain/**"],
},
],
"import/no-unresolved": [
"error", // eslint-plugin-import cannot resolve subpaths https://github.com/firebase/firebase-admin-node/discussions/1359
{ ignore: ["^@kaiachain/js-ext-core/util$"] }
{
ignore: [
"^@kaiachain/js-ext-core/util$",
"^@kaiachain/js-ext-core/ethers-v6$",
],
},
],

// formatting
Expand Down
4 changes: 2 additions & 2 deletions ethers-ext/example/v6/accountKey/sign_tx_AccountKeyPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const { ethers } = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0xe15cd70a41dfb05e7214004d7d054801b2a2f06b";
const senderPriv =
Expand All @@ -23,7 +23,7 @@ async function main() {
type: TxType.ValueTransfer,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
};

const populatedTx = await newWallet.populateTransaction(tx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const { ethers } = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0x5bd2fb3c21564c023a4a735935a2b7a238c4ccea";
const senderPriv =
Expand All @@ -27,7 +27,7 @@ async function main() {
type: TxType.ValueTransfer,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
gasLimit: 100000,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
Wallet,
TxType,
AccountKeyType,
parseKlay,
parseKaia,
} = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0x82c6a8d94993d49cfd0c1d30f0f8caa65782cc7e";
Expand All @@ -34,7 +34,7 @@ async function main() {
type: TxType.ValueTransfer,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
gasLimit: 100000,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react';
import { Account } from '../types';
import { doSignTx } from '../util';
import { TxType, parseKlay } from '@kaiachain/js-ext-core';
import { useState } from "react";
import { Account } from "../types";
import { doSignTx } from "../util";
import { TxType } from "@kaiachain/js-ext-core";
import { parseKaia } from "@kaiachain/ethers-ext/v6";

type Props = {
account: Account;
Expand All @@ -16,7 +17,7 @@ function KlaytnFeeDelVT({ account }: Props) {
const tx = {
type: TxType.FeeDelegatedValueTransfer,
to: e.target.to.value,
value: parseKlay(e.target.amount.value).toString(),
value: parseKaia(e.target.amount.value),
};

try {
Expand All @@ -30,14 +31,29 @@ function KlaytnFeeDelVT({ account }: Props) {
return (
<div className="menu-component">
<form onSubmit={handleSubmit}>
<p>To: <input type="text" name="to" defaultValue={account.address}></input></p>
<p>Value: <input type="text" name="amount" defaultValue="0.01"></input></p>
<p><input type="submit"></input></p>
<p>
To:{" "}
<input type="text" name="to" defaultValue={account.address}></input>
</p>
<p>
Value: <input type="text" name="amount" defaultValue="0.01"></input>
</p>
<p>
<input type="submit"></input>
</p>
</form>
{ txhash? <a target="_blank" href={txhash} rel="noreferrer">{txhash}</a> : null }
{ error? <text><b style={{ color: "red" }}>{error}</b></text> : null }
</div>
);
};
{txhash ? (
<a target="_blank" href={txhash} rel="noreferrer">
{txhash}
</a>
) : null}
{error ? (
<text>
<b style={{ color: "red" }}>{error}</b>
</text>
) : null}
</div>
);
}

export default KlaytnFeeDelVT;
43 changes: 29 additions & 14 deletions ethers-ext/example/v6/browser-react/src/components/KlaytnVT.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from 'react';
import { Account } from '../types';
import { doSendTx } from '../util';
import { TxType, parseKlay } from '@kaiachain/js-ext-core';

import { useState } from "react";
import { Account } from "../types";
import { doSendTx } from "../util";
import { TxType } from "@kaiachain/js-ext-core";
import { parseKaia } from "@kaiachain/ethers-ext/v6";
type Props = {
account: Account;
};
Expand All @@ -16,7 +16,7 @@ function KlaytnVT({ account }: Props) {
const tx = {
type: TxType.ValueTransfer,
to: e.target.to.value,
value: parseKlay(e.target.amount.value).toString(),
value: parseKaia(e.target.amount.value),
};

try {
Expand All @@ -30,14 +30,29 @@ function KlaytnVT({ account }: Props) {
return (
<div className="menu-component">
<form onSubmit={handleSubmit}>
<p>To: <input type="text" name="to" defaultValue={account.address}></input></p>
<p>Value: <input type="text" name="amount" defaultValue="0.01"></input></p>
<p><input type="submit"></input></p>
<p>
To:{" "}
<input type="text" name="to" defaultValue={account.address}></input>
</p>
<p>
Value: <input type="text" name="amount" defaultValue="0.01"></input>
</p>
<p>
<input type="submit"></input>
</p>
</form>
{ txhash? <a target="_blank" href={txhash} rel="noreferrer">{txhash}</a> : null }
{ error? <text><b style={{ color: "red" }}>{error}</b></text> : null }
</div>
);
};
{txhash ? (
<a target="_blank" href={txhash} rel="noreferrer">
{txhash}
</a>
) : null}
{error ? (
<text>
<b style={{ color: "red" }}>{error}</b>
</text>
) : null}
</div>
);
}

export default KlaytnVT;
42 changes: 29 additions & 13 deletions ethers-ext/example/v6/browser-react/src/components/LegacyVT.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { Account } from '../types';
import { doSendTx } from '../util';
import { parseKlay } from '@kaiachain/ethers-ext/v6';
import { useState } from "react";
import { Account } from "../types";
import { doSendTx } from "../util";
import { parseKaia } from "@kaiachain/ethers-ext/v6";

type Props = {
account: Account;
Expand All @@ -14,7 +14,7 @@ function LegacyVT({ account }: Props) {
async function handleSubmit(e: any) {
e.preventDefault();
const toAddr = e.target.to.value;
const valuePeb = parseKlay(e.target.amount.value).toString();
const valuePeb = parseKaia(e.target.amount.value);
const tx = {
to: toAddr,
value: valuePeb,
Expand All @@ -31,14 +31,30 @@ function LegacyVT({ account }: Props) {
return (
<div className="menu-component">
<form onSubmit={handleSubmit}>
<p>To: <input type="text" name="to" defaultValue={account.address}></input></p>
<p>Amount (ETH/KLAY): <input type="text" name="amount" defaultValue="0.01"></input></p>
<p><input type="submit"></input></p>
<p>
To:{" "}
<input type="text" name="to" defaultValue={account.address}></input>
</p>
<p>
Amount (ETH/KLAY):{" "}
<input type="text" name="amount" defaultValue="0.01"></input>
</p>
<p>
<input type="submit"></input>
</p>
</form>
{ txhash? <a target="_blank" href={txhash} rel="noreferrer">{txhash}</a> : null }
{ error? <text><b style={{ color: "red" }}>{error}</b></text> : null }
</div>
);
};
{txhash ? (
<a target="_blank" href={txhash} rel="noreferrer">
{txhash}
</a>
) : null}
{error ? (
<text>
<b style={{ color: "red" }}>{error}</b>
</text>
) : null}
</div>
);
}

export default LegacyVT;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9";
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
Expand All @@ -20,7 +20,7 @@ async function main() {
type: TxType.ValueTransfer,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
};

const sentTx = await wallet.sendTransaction(tx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9";
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
Expand All @@ -20,7 +20,7 @@ async function main() {
type: TxType.ValueTransferMemo,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
data: "0x1234567890",
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv =
Expand All @@ -23,7 +23,7 @@ async function main() {
const tx = {
type: TxType.FeeDelegatedValueTransfer,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
from: senderAddr,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv =
Expand All @@ -24,7 +24,7 @@ async function main() {
type: TxType.FeeDelegatedValueTransferMemo,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
data: "0x1234567890",
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv =
Expand All @@ -23,7 +23,7 @@ async function main() {
const tx = {
type: TxType.FeeDelegatedValueTransferWithRatio,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
from: senderAddr,
feeRatio: 30,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv =
Expand All @@ -24,7 +24,7 @@ async function main() {
type: TxType.FeeDelegatedValueTransferMemoWithRatio,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01").toString(),
value: parseKaia("0.01"),
data: "0x1234567890",
feeRatio: 30,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const ethers = require("ethers6");

const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext/v6");
const { Wallet, TxType, parseKaia } = require("@kaiachain/ethers-ext/v6");

const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv =
Expand Down
Loading

0 comments on commit bfa4445

Please sign in to comment.