Skip to content

Commit

Permalink
lint and config
Browse files Browse the repository at this point in the history
  • Loading branch information
coderofstuff committed Dec 31, 2023
1 parent 9170cc9 commit 7332503
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 67 deletions.
28 changes: 6 additions & 22 deletions app/wallet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import styles from './page.module.css';
import { getAddress, fetchAddressDetails, initTransport } from '@/lib/ledger';
import { useState, useEffect } from 'react';
import { Box, Stack, Tabs, Breadcrumbs, Anchor, Button, Center } from '@mantine/core';
import { Stack, Tabs, Breadcrumbs, Anchor, Button, Center } from '@mantine/core';
import Header from '../../components/header';
import AddressesTab from './addresses-tab';
import OverviewTab from './overview-tab';
Expand All @@ -22,24 +22,6 @@ import SettingsStore from '@/lib/settings-store';
let loadingAddressBatch = false;
let addressInitialized = false;

function loadAddresses(bip32, addressType = 0, from = 0, to = from + 10) {
const addresses = [];

for (let addressIndex = from; addressIndex < to; addressIndex++) {
const derivationPath = `44'/111111'/0'/${addressType}/${addressIndex}`;
const address = bip32.getAddress(addressType, addressIndex);

addresses.push({
derivationPath,
address,
addressIndex,
addressType,
});
}

return addresses;
}

const addressFilter = (lastReceiveIndex) => {
return (addressData, index) => {
return (
Expand Down Expand Up @@ -174,7 +156,7 @@ function getDemoXPub() {
};
}

export default function Dashboard(props) {
export default function Dashboard() {
const [addresses, setAddresses] = useState([]);
const [rawAddresses, setRawAddresses] = useState([]);
const [selectedAddress, setSelectedAddress] = useState(null);
Expand Down Expand Up @@ -267,14 +249,14 @@ export default function Dashboard(props) {

useEffect(() => {
if (isTransportInitialized) {
return;
return () => {};
}

if (deviceType === 'demo') {
setTransportInitialized(true);
const xpub = getDemoXPub();
setBIP32Base(new KaspaBIP32(xpub.compressedPublicKey, xpub.chainCode));
return;
return () => {};
}

let unloaded = false;
Expand All @@ -288,6 +270,8 @@ export default function Dashboard(props) {
setBIP32Base(new KaspaBIP32(xpub.compressedPublicKey, xpub.chainCode)),
);
}

return null;
})
.catch((e) => {
notifications.show({
Expand Down
36 changes: 16 additions & 20 deletions components/send-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { kasToSompi, sompiToKas } from '@/lib/kaspa-util';

export default function SendForm(props) {
const [confirming, setConfirming] = useState(false);
const [fee, setFee] = useState('-');
const [amountDescription, setAmountDescription] = useState();
const [fee, setFee] = useState<string | number>('-');
const [amountDescription, setAmountDescription] = useState<string>();

const [canSendAmount, setCanSendAmount] = useState(false);

Expand All @@ -37,7 +37,7 @@ export default function SendForm(props) {

const form = useForm({
initialValues: {
amount: '',
amount: undefined,
sendTo: '',
includeFeeInAmount: false,
sentAmount: '',
Expand All @@ -55,20 +55,18 @@ export default function SendForm(props) {
// Reset setup
setConfirming(false);
setFee('-');
const baseValues = { amount: '', sendTo: '', includeFeeInAmount: false };
let baseValues = { amount: '', sendTo: '', includeFeeInAmount: false };

if (resetAllValues) {
baseValues.sentTo = '';
baseValues.sentTxId = '';
baseValues.sentAmount = '';
form.setValues({ sentTo: '', sentTxId: '', sentAmount: '', ...baseValues });
} else {
form.setValues(baseValues);
}

form.setValues(baseValues);
};

const cleanupOnSuccess = (transactionId) => {
const targetAmount = form.values.includeFeeInAmount
? Number((form.values.amount - fee).toFixed(8))
? (Number(form.values.amount) - Number(fee)).toFixed(8)
: form.values.amount;

form.setValues({
Expand Down Expand Up @@ -117,7 +115,7 @@ export default function SendForm(props) {
} else if (deviceType == 'usb') {
try {
const { tx } = createTransaction(
kasToSompi(form.values.amount),
kasToSompi(Number(form.values.amount)),
form.values.sendTo,
props.addressContext.utxos,
props.addressContext.derivationPath,
Expand Down Expand Up @@ -147,7 +145,7 @@ export default function SendForm(props) {
setAmountDescription('');

if (amount && sendTo) {
let calculatedFee = '-';
let calculatedFee: string | number = '-';
if (deviceType === 'demo') {
calculatedFee =
fee === '-' ? sompiToKas(Math.round(Math.random() * 10000)) : Number(fee);
Expand All @@ -157,7 +155,7 @@ export default function SendForm(props) {
setAmountDescription(`Amount after fee: ${afterFeeDisplay}`);
}
} else if (deviceType === 'usb') {
const [hasEnough, selectedUtxos, feeCalcResult, utxoTotalAmount] = selectUtxos(
const [hasEnough, _selectedUtxos, feeCalcResult, utxoTotalAmount] = selectUtxos(
kasToSompi(amount),
props.addressContext.utxos,
includeFeeInAmount,
Expand Down Expand Up @@ -216,7 +214,7 @@ export default function SendForm(props) {
label='Send to Address'
placeholder='Address'
{...form.getInputProps('sendTo')}
disabled={form.getInputProps('sendTo').disabled || confirming}
disabled={confirming}
required
/>

Expand All @@ -243,7 +241,7 @@ export default function SendForm(props) {
<Checkbox
{...form.getInputProps('includeFeeInAmount', { type: 'checkbox' })}
label='Include fee in amount'
disabled={confirming || form.getInputProps('includeFeeInAmount').disabled}
disabled={confirming}
/>

<Group justify='space-between'>
Expand All @@ -267,7 +265,7 @@ export default function SendForm(props) {
size={viewportWidth > 700 ? 'auto' : 'md'}
>
<Stack align='center'>
<Text size='lg' align='center' c='brand'>
<Text size='lg' c='brand'>
Sent!
</Text>

Expand All @@ -277,23 +275,21 @@ export default function SendForm(props) {
href={`https://explorer.kaspa.org/txs/${form.values.sentTxId}`}
target='_blank'
c='brand'
align='center'
w={'calc(var(--modal-size) - 6rem)'}
style={{ overflowWrap: 'break-word' }}
>
{form.values.sentTxId}
</Anchor>

<Text component='h2' align='center' fw={600}>
<Text component='h2' fw={600}>
{form.values.sentAmount} KAS
</Text>

<Text align='center'>sent to</Text>
<Text>sent to</Text>

<Text
w={'calc(var(--modal-size) - 6rem)'}
style={{ overflowWrap: 'break-word' }}
align='center'
>
<AddressText address={form.values.sentTo} />
</Text>
Expand Down
2 changes: 1 addition & 1 deletion lib/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let transportState = {
type: null,
};

export async function fetchTransaction(transactionId) {
export async function fetchTransaction(transactionId: string) {
const { data: txData } = await axios.get(`https://api.kaspa.org/transactions/${transactionId}`);

return txData;
Expand Down
72 changes: 48 additions & 24 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
},
"target": "es2015",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
"compilerOptions": {
"paths": {
"@/*": [
"./*"
]
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"target": "esnext",
"lib": [
"es6",
"es7",
"esnext",
"dom"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"noEmit": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}

0 comments on commit 7332503

Please sign in to comment.