Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chores: Refactor and Improve Codebase Readability and Documentation #215

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ProviderController extends BaseController {
const networkType = wallet.getNetworkType()
const psbtNetwork = toPsbtNetwork(networkType)
const psbt = bitcoin.Psbt.fromHex(psbtHex, { network: psbtNetwork })
const autoFinalized = (options && options.autoFinalized == false) ? false : true;
const autoFinalized = !(options && options.autoFinalized == false);
const toSignInputs = await wallet.formatOptionsToSignInputs(psbtHex, options);
await wallet.signPsbt(psbt, toSignInputs, autoFinalized);
return psbt.toHex();
Expand All @@ -243,7 +243,7 @@ class ProviderController extends BaseController {
const result: string[] = [];
for (let i = 0; i < psbtHexs.length; i++) {
const psbt = bitcoin.Psbt.fromHex(psbtHexs[i], { network: psbtNetwork });
const autoFinalized = (options && options[i] && options[i].autoFinalized == false) ? false : true;
const autoFinalized = !(options && options[i] && !options[i].autoFinalized);
const toSignInputs = await wallet.formatOptionsToSignInputs(psbtHexs[i], options[i]);
await wallet.signPsbt(psbt, toSignInputs, autoFinalized);
result.push(psbt.toHex())
Expand Down
6 changes: 1 addition & 5 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ export class WalletController extends BaseController {
};

isReady = () => {
if (contactBookService.store) {
return true;
} else {
return false;
}
return !!contactBookService.store;
};

unlock = async (password: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/background/service/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ class KeyringService extends EventEmitter {
* Import Keychain using Private key
*
* @emits KeyringController#unlock
* @param privateKey - The privateKey to generate address
* @param privateKey - The privateKey to generate address
* @param addressType - The type of address
* @returns A Promise that resolves to the state.
*/
importPrivateKey = async (privateKey: string, addressType: AddressType) => {
Expand Down
8 changes: 1 addition & 7 deletions src/content-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const channelName = nanoid();
/**
* Injects a script tag into the current document
*
* @param {string} content - Code to be executed in the current document
*/
function injectScript() {
try {
Expand Down Expand Up @@ -106,12 +105,7 @@ function blockedDomainCheck() {
}

function iframeCheck() {
const isInIframe = self != top;
if (isInIframe) {
return true;
} else {
return false;
}
return self != top;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/AtomicalsNFTPreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Atomical } from '@/shared/types';
import { colors } from '@/ui/theme/colors';
import { fontSizes } from '@/ui/theme/font';

import { formatDate } from '../../utils';
import { formatDate } from '@/ui/utils';
import { Column } from '../Column';
import Iframe from '../Iframe';
import { Row } from '../Row';
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function AtomicalsNFTPreview({ data, onClick, preset }: Atomicals
</div>
<Column px="md" py="sm" gap="zero" bg="bg4" full>
<Text text={numberStr} color="gold" size={$numberPresets[preset] as any} />
{isUnconfirmed == false && <Text text={time} preset="sub" size={$timePresets[preset] as any} />}
{!isUnconfirmed && <Text text={time} preset="sub" size={$timePresets[preset] as any} />}
</Column>
</Column>
);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/BRC20CardStack/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
height: 198px;
width: 156px;
background-color: #17141d;
border-radius: 0px;
border-radius: 0;
box-shadow: -1rem 0 3rem #000;
/* margin-left: -50px; */
transition: 0.4s ease-out;
position: relative;
left: 0px;
padding: 0px;
left: 0;
padding: 0;
}

.card:not(:first-child) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/InscriptionPreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useOrdinalsWebsite } from '@/ui/state/settings/hooks';
import { colors } from '@/ui/theme/colors';
import { fontSizes } from '@/ui/theme/font';

import { formatDate } from '../../utils';
import { formatDate } from '@/ui/utils';
import { Column } from '../Column';
import Iframe from '../Iframe';
import { Row } from '../Row';
Expand Down Expand Up @@ -142,7 +142,7 @@ export default function InscriptionPreview({ data, onClick, preset, asLogo }: In
) : null}
<Column px="md" py="sm" gap="zero" bg="bg4" full>
<Text text={numberStr} color="gold" size={$numberPresets[preset] as any} />
{isUnconfirmed == false && data.timestamp && (
{!isUnconfirmed && data.timestamp && (
<Text text={time} preset="sub" size={$timePresets[preset] as any} />
)}
</Column>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ export const SendingOutAssets = ({ decodedPsbt, onClose }: { decodedPsbt: Decode
return inscriptionMap[id];
})
.filter((v) => {
if (v.from === currentAccount.address && v.to !== currentAccount.address) {
return true;
} else {
return false;
}
return v.from === currentAccount.address && v.to !== currentAccount.address;
});

const arc20BalanceChanged: { [key: string]: number } = {};
Expand Down
1 change: 0 additions & 1 deletion src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const wallet: Record<string, any> = new Proxy(
}
}
);
break;
default:
return function (...params: any) {
return portMessageChannel.request({
Expand Down
6 changes: 2 additions & 4 deletions src/ui/pages/Approval/components/MultiSignPsbt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,8 @@ export default function MultiSignPsbt({
}, [decodedPsbt]);

const isValidData = useMemo(() => {
if (psbtHex === '') {
return false;
}
return true;
return psbtHex !== '';

}, [psbtHex]);

const isValid = useMemo(() => {
Expand Down
14 changes: 4 additions & 10 deletions src/ui/pages/Approval/components/SignPsbt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ function SignTxDetails({
}, [txInfo.decodedPsbt]);

const isCurrentToPayFee = useMemo(() => {
if (type === TxType.SIGN_TX) {
return false;
} else {
return true;
}
return type !== TxType.SIGN_TX;
}, [type]);

const spendSatoshis = useMemo(() => {
Expand Down Expand Up @@ -753,10 +749,8 @@ export default function SignPsbt({
}, [txInfo, brc20PriceMap, runesPriceMap]);

const isValidData = useMemo(() => {
if (txInfo.psbtHex === '') {
return false;
}
return true;
return txInfo.psbtHex !== '';

}, [txInfo.psbtHex]);

const isValid = useMemo(() => {
Expand Down Expand Up @@ -904,7 +898,7 @@ export default function SignPsbt({
<Card>
<Column full justifyCenter>
{txInfo.decodedPsbt.inputInfos.map((v, index) => {
const isToSign = txInfo.toSignInputs.find((v) => v.index === index) ? true : false;
const isToSign = !!txInfo.toSignInputs.find((v) => v.index === index);
const inscriptions = v.inscriptions;
const atomicals_nft = v.atomicals.filter((v) => v.type === 'NFT');
const atomicals_ft = v.atomicals.filter((v) => v.type === 'FT');
Expand Down
6 changes: 1 addition & 5 deletions src/ui/pages/Main/BoostScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ export default function BoostScreen() {

if (!currentAccount) {
navigate('WelcomeScreen');
return;
} else if (approval) {
navigate('ApprovalScreen');
} else {
navigate('MainScreen');
return;
navigate(approval ? 'ApprovalScreen' : 'MainScreen');
}
};

Expand Down
6 changes: 2 additions & 4 deletions src/ui/pages/Settings/EditAccountNameScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ export default function EditAccountNameScreen() {
};

const validName = useMemo(() => {
if (alianName.length == 0) {
return false;
}
return true;
return alianName.length != 0;

}, [alianName]);
return (
<Layout>
Expand Down
6 changes: 2 additions & 4 deletions src/ui/pages/Settings/EditWalletNameScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ export default function EditWalletNameScreen() {
};

const isValidName = useMemo(() => {
if (alianName.length == 0) {
return false;
}
return true;
return alianName.length != 0;

}, [alianName]);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/Wallet/KeystoneSignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Step2(props: Props) {

const onSucceed = async ({ type, cbor }) => {
if (props.type === 'psbt') {
const res = await wallet.parseSignPsbtUr(type, cbor, props.isFinalize === false ? false : true);
const res = await wallet.parseSignPsbtUr(type, cbor, !!props.isFinalize);
if (props.onSuccess) {
props.onSuccess(res);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/ui/pages/Wallet/ReceiveScreen/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
flex-direction: row;
justify-content: center;
align-items: center;
padding: 0.625rem 0px;
padding: 0.625rem 0;
gap: 0.625rem;

width: 25rem;
Expand All @@ -23,7 +23,7 @@
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0px;
padding: 0;

width: 0.98rem;
height: 1.37rem;
Expand Down Expand Up @@ -56,7 +56,7 @@
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0px;
padding: 0;
gap: 0.625rem;
width: 31.25rem;
height: 1.18rem;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/styles/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

iframe {
overflow-clip-margin: content-box !important;
border-width: 0px;
border-width: 0;
border-style: inset;
border-color: initial;
border-image: initial;
Expand Down Expand Up @@ -50,7 +50,7 @@ iframe {
}

div {
border: 0px solid;
border: 0 solid;
}

// For scrollbar
Expand Down
3 changes: 1 addition & 2 deletions src/ui/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ export async function sleep(timeSec: number) {
}

export function isValidAddress(address: string) {
if (!address) return false;
return true;
return !!address;
}

export const copyToClipboard = (textToCopy: string | number) => {
Expand Down