Skip to content

Commit

Permalink
0.2.6 | Custom HD path (#100)
Browse files Browse the repository at this point in the history
* fix send for many utxos

* fix , refactoring, redesign

* styles

* fix bug with loading trasactions, better styles, clear transactions on create new wallet

* update version
  • Loading branch information
kieled authored Aug 18, 2024
1 parent 29f57ab commit bda613f
Show file tree
Hide file tree
Showing 47 changed files with 510 additions and 581 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nintondo-extension",
"version": "0.2.5.5",
"version": "0.2.6",
"private": true,
"scripts": {
"dev": "bun build.ts --watch",
Expand Down
1 change: 1 addition & 0 deletions src/background/controllers/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Payload<P extends keyof INintondoProvider> = {
approvalRes?: any;
};

// @ts-ignore
class ProviderController implements IProviderController {
connect = async () => {
if (
Expand Down
14 changes: 8 additions & 6 deletions src/shared/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ export const ADDRESS_TYPES: {
name: string;
hdPath: string;
}[] = [
{
value: AddressType.P2PKH,
label: "P2PKH",
name: "Legacy (P2PKH)",
hdPath: "m/44'/0'/0'/0",
},
{
value: AddressType.P2WPKH,
label: "P2WPKH",
name: "Native Segwit (P2WPKH)",
hdPath: "m/84'/0'/0'/0",
},
{
value: AddressType.P2PKH,
label: "P2PKH",
name: "Legacy (P2PKH)",
hdPath: "m/44'/0'/0'/0",
},
{
value: AddressType.P2TR,
label: "P2TR",
Expand Down Expand Up @@ -95,3 +95,5 @@ export const DEFAULT_FEES = {
};

export const DEFAULT_SERVICE_FEE = 1_000_000;

export const DEFAULT_HD_PATH = "m/44'/0'/0'/0";
14 changes: 8 additions & 6 deletions src/shared/locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
"new_wallet": {
"new_mnemonic_label": "New mnemonic",
"restore_mnemonic_label": "Restore mnemonic",
"restore_ordinals_label": "Restore ordinals mnemonic",
"restore_from_private_key_label": "Restore from private key",
"restore_from_label": "Restore from",
"step_1": "Step 1",
Expand All @@ -136,7 +135,8 @@
"private_key": "Private key",
"recover": "Recover",
"invalid_private_key_error": "Invalid private key"
}
},
"hd_path": "Hd path"
},
"receive": {
"click_to_copy": "Click to copy",
Expand Down Expand Up @@ -211,20 +211,22 @@
},
"transaction_info": {
"txid": "TxId",
"confirmations_label": "Confirmations:",
"confirmations_label": "Confirmations",
"fee_label": "Fee",
"value_label": "Value:",
"value_label": "Value",
"open_in_explorer": "Open in explorer",
"copied": "Copied",
"inputs": "Inputs",
"outputs": "Outputs",
"details": "Details"
"details": "Details",
"your_address": "You"
},
"hooks": {
"transaction": {
"insufficient_balance_0": "Insufficient balance. Non-Inscription balance",
"insufficient_balance_1": "BEL) is lower than",
"insufficient_balance_2": "BEL"
"insufficient_balance_2": "BEL",
"too_many_utxos": "Too many UTXOs. You must consolidate them in order to send"
},
"wallet": {
"last_wallet_error": "You cannot delete your last wallet"
Expand Down
78 changes: 18 additions & 60 deletions src/shared/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,38 @@ import { payments } from "belcoinjs-lib";
import Big from "big.js";
import { AddressType } from "bellhdw/src/hd/types";

export enum TxDirection {
out = 0,
in = 1,
}

export const getTxDirection = (
transaction: ITransaction,
targetAddress: string
): TxDirection => {
const includesIn = transaction.vin
.map((i) => i.prevout?.scriptpubkey_address)
.includes(targetAddress);

if (includesIn) {
return TxDirection.out;
}
return TxDirection.in;
};

export const getTransactionValue = (
transaction: ITransaction,
targetAddress: string,
fixed: number = 2
) => {
const direction = getTxDirection(transaction, targetAddress);
let value: number;
switch (direction) {
case TxDirection.in:
value =
transaction.vout.reduce(
(acc, cur) =>
cur.scriptpubkey_address === targetAddress ? acc + cur.value : acc,
0
) /
10 ** 8;
break;
case TxDirection.out:
value =
(transaction.vin.reduce(
(acc, cur) =>
cur.prevout?.scriptpubkey_address === targetAddress
? acc - cur.prevout?.value
: acc,
0
) +
transaction.vout.reduce(
(acc, cur) =>
cur.scriptpubkey_address === targetAddress
? cur.value + acc
: acc,
0
)) /
10 ** 8;
break;
}
const outputsSum = transaction.vout
.filter((i) => i.scriptpubkey_address === targetAddress)
.reduce((acc, cur) => acc + cur.value, 0);
const inputsSum = transaction.vin
.filter((i) => i.prevout?.scriptpubkey_address === targetAddress)
.reduce((acc, cur) => acc + cur.prevout!.value, 0);

// return value;
const value = Math.abs(outputsSum - inputsSum) / 10 ** 8;

if (typeof fixed !== "undefined") {
if (value < 100) {
return Math.abs(value).toFixed(fixed + 1);
}
return Math.abs(value).toFixed(fixed);
if (value < 1) return parseFloat(value.toFixed(5)).toString();
if (value < 100) {
return value.toFixed(fixed + 1);
}

return Math.abs(value);
return value.toFixed(fixed);
};

export const isIncomeTx = (
transaction: ITransaction,
targetAddress: string
) => {
const direction = getTxDirection(transaction, targetAddress);
return direction === TxDirection.in;
const outputsSum = transaction.vout
.filter((i) => i.scriptpubkey_address === targetAddress)
.reduce((acc, cur) => acc + cur.value, 0);
const inputsSum = transaction.vin
.filter((i) => i.prevout?.scriptpubkey_address === targetAddress)
.reduce((acc, cur) => acc + cur.prevout!.value, 0);
return outputsSum - inputsSum > 0;
};

export const getScriptForAddress = (
Expand Down
4 changes: 3 additions & 1 deletion src/ui/components/inscription-card/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const InscriptionCard: FC<Props> = ({ inscriptionId }) => {
<div
className="cursor-pointer flex flex-col justify-center align-center relative"
onClick={() => {
navigate("/pages/inscription-details", { state: inscriptionId });
navigate("/pages/inscription-details", {
state: { inscription_id: inscriptionId },
});
}}
>
<div className="rounded-xl w-full bg-slate-950 bg-opacity-50">
Expand Down
Loading

0 comments on commit bda613f

Please sign in to comment.