Skip to content

Commit

Permalink
refactor: assets and asset list
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed May 14, 2024
1 parent 25b62a8 commit b0c3dde
Show file tree
Hide file tree
Showing 127 changed files with 1,323 additions and 1,604 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"@dlc-link/dlc-tools": "1.1.1",
"@fungible-systems/zone-file": "2.0.0",
"@hirosystems/token-metadata-api-client": "1.2.0",
"@leather-wallet/models": "0.4.0",
"@leather-wallet/models": "0.4.4",
"@leather-wallet/tokens": "0.0.14",
"@ledgerhq/hw-transport-webusb": "6.27.19",
"@noble/hashes": "1.3.2",
Expand Down
11 changes: 9 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 0 additions & 72 deletions src/app/common/crypto-assets/stacks-crypto-asset.utils.spec.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/app/common/crypto-assets/stacks-crypto-asset.utils.ts

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/common/hooks/balance/use-total-balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money';
import { i18nFormatCurrency } from '@app/common/money/format-money';
import { useBtcCryptoAssetBalanceNativeSegwit } from '@app/query/bitcoin/balance/btc-balance-native-segwit.hooks';
import { useCryptoCurrencyMarketDataMeanAverage } from '@app/query/common/market-data/market-data.hooks';
import { useStxCryptoAssetBalance } from '@app/query/stacks/balance/stx-balance.hooks';
import { useStxCryptoAssetBalance } from '@app/query/stacks/balance/account-balance.hooks';

interface UseTotalBalanceArgs {
btcAddress: string;
Expand Down
25 changes: 0 additions & 25 deletions src/app/common/hooks/use-transferable-asset-balances.hooks.ts

This file was deleted.

16 changes: 15 additions & 1 deletion src/app/common/stacks-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stacksValue } from '@app/common/stacks-utils';
import { isFtNameLikeStx, stacksValue } from '@app/common/stacks-utils';

const uSTX_AMOUNT = 10000480064; // 10,000.480064

Expand Down Expand Up @@ -31,3 +31,17 @@ describe('stacksValue tests', () => {
expect(value).toEqual('10K STX');
});
});

describe(isFtNameLikeStx.name, () => {
it('detect impersonating token names', () => {
expect(isFtNameLikeStx('STX')).toBeTruthy();
expect(isFtNameLikeStx('stx')).toBeTruthy();
expect(isFtNameLikeStx('stacks')).toBeTruthy();
expect(isFtNameLikeStx('Stäcks')).toBeTruthy();
expect(isFtNameLikeStx('Stácks')).toBeTruthy();
expect(isFtNameLikeStx('Stáçks')).toBeTruthy();
expect(isFtNameLikeStx('stocks')).toBeFalsy();
expect(isFtNameLikeStx('miamicoin')).toBeFalsy();
expect(isFtNameLikeStx('')).toBeFalsy();
});
});
12 changes: 12 additions & 0 deletions src/app/common/stacks-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import BigNumber from 'bignumber.js';
import { c32addressDecode } from 'c32check';

import { NetworkConfiguration, STX_DECIMALS } from '@shared/constants';
import { isValidUrl } from '@shared/utils/validate-url';

import { abbreviateNumber } from '@app/common/utils';

import { initBigNumber } from './math/helpers';
import { microStxToStx } from './money/unit-conversion';
import { convertUnicodeToAscii } from './string-utils';

export const stacksValue = ({
value,
Expand Down Expand Up @@ -64,3 +66,13 @@ export function validateAddressChain(address: string, currentNetwork: NetworkCon
return false;
}
}

export function isFtNameLikeStx(name: string) {
return ['stx', 'stack', 'stacks'].includes(convertUnicodeToAscii(name).toLocaleLowerCase());
}

export function getSafeImageCanonicalUri(imageCanonicalUri: string, name: string) {
return imageCanonicalUri && isValidUrl(imageCanonicalUri) && !isFtNameLikeStx(name)
? imageCanonicalUri
: '';
}
2 changes: 1 addition & 1 deletion src/app/components/account/account-addresses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BulletSeparator } from '@app/ui/components/bullet-separator/bullet-sepa
import { Caption } from '@app/ui/components/typography/caption';
import { truncateMiddle } from '@app/ui/utils/truncate-middle';

import { BitcoinNativeSegwitAccountLoader } from '../loaders/bitcoin-account-loader';
import { StacksAccountLoader } from '../loaders/stacks-account-loader';
import { BitcoinNativeSegwitAccountLoader } from './bitcoin-account-loader';

interface AccountAddressesProps {
index: number;
Expand Down
47 changes: 0 additions & 47 deletions src/app/components/account/bitcoin-account-loader.tsx

This file was deleted.

10 changes: 5 additions & 5 deletions src/app/components/balance/btc-balance.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { formatMoney } from '@app/common/money/format-money';
import { Caption } from '@app/ui/components/typography/caption';

import { BitcoinNativeSegwitAccountLoader } from '../account/bitcoin-account-loader';
import { BtcBalanceLoader } from '../loaders/btc-balance-loader';
import { BitcoinNativeSegwitAccountLoader } from '../loaders/bitcoin-account-loader';
import { BtcCryptoAssetLoader } from '../loaders/btc-crypto-asset-loader';

export function BtcBalance() {
return (
<BitcoinNativeSegwitAccountLoader current>
{signer => (
<BtcBalanceLoader address={signer.address}>
{balance => <Caption>{formatMoney(balance.availableBalance)}</Caption>}
</BtcBalanceLoader>
<BtcCryptoAssetLoader address={signer.address}>
{asset => <Caption>{formatMoney(asset.balance.availableBalance)}</Caption>}
</BtcCryptoAssetLoader>
)}
</BitcoinNativeSegwitAccountLoader>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/balance/stx-balance.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react';

import { stacksValue } from '@app/common/stacks-utils';
import { useStxCryptoAssetBalance } from '@app/query/stacks/balance/stx-balance.hooks';
import { useStxCryptoAssetBalance } from '@app/query/stacks/balance/account-balance.hooks';
import { Caption } from '@app/ui/components/typography/caption';

interface StxBalanceProps {
Expand Down
Loading

0 comments on commit b0c3dde

Please sign in to comment.