Skip to content

Commit

Permalink
fix: fee update, blank mnemonic bug, updating new transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
kieled committed Oct 29, 2024
1 parent 90a4e2b commit bd9c71d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 26 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.8.1",
"version": "0.2.8.2",
"private": true,
"scripts": {
"dev": "bun build.ts --watch",
Expand Down
7 changes: 3 additions & 4 deletions src/shared/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export const EVENTS = {
},
};

const NINTONDO_API_URL =
process.env.API_URL ?? "https://electrs.nintondo.io/api";
const NINTONDO_API_URL = process.env.API_URL ?? "https://api.nintondo.io/api";

const CONTENT_URL =
process.env.CONTENT_URL ?? "https://content.nintondo.io/api/pub";
Expand Down Expand Up @@ -85,8 +84,8 @@ const TESTNET_HISTORY_URL =
process.env.TESTNET_HISTORY_URL ?? "https://testnet.nintondo.io/history/pub";

export const DEFAULT_FEES = {
fast: 5000,
slow: 2000,
fast: 500,
slow: 20,
};

export const DEFAULT_SERVICE_FEE = 1_000_000;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/index.global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ input[type="number"] {
}

.bottom-btn {
@apply flex text-xs gap-2 items-center uppercase tracking-widest justify-center h-11 font-light text-gray-100 font-mono mx-auto py-3 border-t border-neutral-700 fixed standard:relative bottom-0 right-0 left-0 transition-colors w-full text-center disabled:cursor-wait;
@apply flex text-xs gap-2 items-center uppercase tracking-widest justify-center h-11 font-light text-gray-100 font-mono mx-auto py-3 border-t border-neutral-700 fixed standard:relative bottom-0 right-0 left-0 transition-colors w-full text-center disabled:cursor-wait bg-bg;
}

.primary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const RestoreMnemonic = () => {
};

const onNextStep = () => {
if (mnemonicPhrase.findIndex((f) => f === undefined) !== -1)
if (mnemonicPhrase.some((f) => !f))
toast.error(t("new_wallet.restore_mnemonic.incomplete_phrase_error"));
else setStep(2);
};
Expand Down
7 changes: 7 additions & 0 deletions src/ui/pages/main/send/confirm-send/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import toast from "react-hot-toast";
import { useUpdateAddressBook } from "@/ui/hooks/app";
import { t } from "i18next";
import { useUpdateCurrentAccountBalance } from "@/ui/hooks/wallet";
import { useTransactionManagerContext } from "@/ui/utils/tx-ctx";
import { useGetCurrentAccount } from "@/ui/states/walletState";

const ConfirmSend = () => {
const location = useLocation();
Expand All @@ -15,6 +17,8 @@ const ConfirmSend = () => {
const navigate = useNavigate();
const updateAddressBook = useUpdateAddressBook();
const updateBalance = useUpdateCurrentAccountBalance();
const { updateTransactions } = useTransactionManagerContext();
const currentAccount = useGetCurrentAccount();

const confirmSend = async () => {
setLoading(true);
Expand All @@ -26,6 +30,9 @@ const ConfirmSend = () => {

setTimeout(() => {
updateBalance();
if (currentAccount?.address) {
updateTransactions(currentAccount.address);
}
}, 100);

navigate(`/pages/finalle-send/${data.txid}`);
Expand Down
47 changes: 29 additions & 18 deletions src/ui/pages/main/send/create-send/fee-input/component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cn from "classnames";
import { FC, useState } from "react";
import { FC, useEffect, useMemo, useState } from "react";
import s from "./styles.module.scss";
import { t } from "i18next";
import { useAppState } from "@/ui/states/appState";
Expand Down Expand Up @@ -28,23 +28,34 @@ const FeeInput: FC<Props> = ({ onChange, value }) => {
}
};

const cards = [
{
title: t("send.create_send.fee_input.slow"),
description: `${feeRates?.slow ?? "~"} sat/Vb`,
value: feeRates?.slow ?? DEFAULT_FEES.slow,
},
{
title: t("send.create_send.fee_input.fast"),
description: `${feeRates?.fast ?? "~"} sat/Vb`,
value: feeRates?.fast ?? DEFAULT_FEES.fast,
},
{
title: t("send.create_send.fee_input.custom"),
description: "",
value: 3,
},
];
const cards = useMemo(
() => [
{
title: t("send.create_send.fee_input.slow"),
description: `${feeRates?.slow ?? DEFAULT_FEES.slow} sat/Vb`,
value: feeRates?.slow ?? DEFAULT_FEES.slow,
},
{
title: t("send.create_send.fee_input.fast"),
description: `${feeRates?.fast ?? DEFAULT_FEES.fast} sat/Vb`,
value: feeRates?.fast ?? DEFAULT_FEES.fast,
},
{
title: t("send.create_send.fee_input.custom"),
description: "",
value: 3,
},
],
[feeRates]
);

useEffect(() => {
setSelected((prev) => {
if (prev === 3) return prev;
if (cards.some((i) => i.value === prev)) return prev;
return feeRates?.slow ?? DEFAULT_FEES.slow;
});
}, [feeRates, cards]);

return (
<div className={s.container}>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useUpdateFunction = <T>(
receivedItems.map((f) => f[compareKey])
);
const intersection = currentItemsKeys.intersection(receivedItemsKeys);
const difference = currentItemsKeys.difference(receivedItemsKeys);
const difference = receivedItemsKeys.difference(currentItemsKeys);

return [
...receivedItems.filter((f) => difference.has(f[compareKey])),
Expand Down
7 changes: 7 additions & 0 deletions src/ui/utils/tx-ctx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const useTransactionManager = (): TransactionManagerContextType | undefined => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentAccount?.address]);

useEffect(() => {
updateFeeRates();
}, [updateFeeRates]);

if (!currentAccount) return undefined;

return {
Expand All @@ -109,6 +113,7 @@ const useTransactionManager = (): TransactionManagerContextType | undefined => {
currentPrice,
loadMoreTransactions,
feeRates,
updateTransactions,
};
};

Expand All @@ -121,6 +126,7 @@ interface TransactionManagerContextType {
fast: number;
slow: number;
};
updateTransactions: (address: string, reset?: boolean) => Promise<void>;
}

const TransactionManagerContext = createContext<
Expand Down Expand Up @@ -152,6 +158,7 @@ export const useTransactionManagerContext =
},
lastBlock: 0,
loadMoreTransactions: async () => {},
updateTransactions: async () => {},
};
}
return context;
Expand Down

0 comments on commit bd9c71d

Please sign in to comment.