Skip to content

Commit 03e54bc

Browse files
ShawnAngelCastilloBljagiela
authored
feat: add advanced mode to receive drawer (#1404)
* feat: add advanced mode to receive drawer * feat: add functionality to add new unused address * refactor: simplify translation, util function for total assets * chore: bump lace-ui-toolkit version * fix: fix testId on TextLinks --------- Co-authored-by: Angel Castillo <angel.castillo@iohk.io> Co-authored-by: Lukasz Jagiela <Lukasz.Jagiela@iohk.io>
1 parent 2225ebd commit 03e54bc

File tree

64 files changed

+989
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+989
-187
lines changed

apps/browser-extension-wallet/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@cardano-sdk/wallet": "0.44.1",
5151
"@cardano-sdk/web-extension": "0.34.0",
5252
"@emurgo/cip14-js": "~3.0.1",
53-
"@input-output-hk/lace-ui-toolkit": "1.15.1",
53+
"@input-output-hk/lace-ui-toolkit": "1.19.0",
5454
"@lace/cardano": "0.1.0",
5555
"@lace/common": "0.1.0",
5656
"@lace/core": "0.1.0",

apps/browser-extension-wallet/src/features/receive-info/components/ReceiveInfo.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { HandleInfo } from '@cardano-sdk/wallet';
99
import { getAssetImageUrl } from '@src/utils/get-asset-image-url';
1010
import { useAnalyticsContext } from '@providers';
1111
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';
12+
import { Flex } from '@input-output-hk/lace-ui-toolkit';
1213

1314
export interface ReceiveInfoProps {
1415
name: string;
@@ -42,13 +43,12 @@ export const ReceiveInfo = ({ name, address, handles, goBack }: ReceiveInfoProps
4243
navigation={<DrawerNavigation onCloseIconClick={handleOnClose} />}
4344
popupView
4445
>
45-
<div className={styles.container} data-testid="receive-address-qr">
46+
<Flex className={styles.container} testId="receive-address-qr" flexDirection="column" gap="$16">
4647
<AddressCard
4748
name={name}
4849
isPopupView
4950
address={address?.toString()}
5051
getQRCodeOptions={useCallback(() => getQRCodeOptions(theme, ADDRESS_CARD_QR_CODE_SIZE_POPUP), [theme])}
51-
copiedMessage={t('core.infoWallet.addressCopied')}
5252
onCopyClick={handleCopyAddress}
5353
/>
5454
{handles?.map(({ nftMetadata, image }) => (
@@ -60,7 +60,7 @@ export const ReceiveInfo = ({ name, address, handles, goBack }: ReceiveInfoProps
6060
onCopyClick={handleCopyAdaHandle}
6161
/>
6262
))}
63-
</div>
63+
</Flex>
6464
</Drawer>
6565
);
6666
};

apps/browser-extension-wallet/src/hooks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ export * from './useWalletAvatar';
2626
export * from './useActionExecution';
2727
export * from './useCustomSubmitApi';
2828
export * from './useSharedWalletData';
29-
export * from './useNextUnusedAddress';

apps/browser-extension-wallet/src/hooks/useNextUnusedAddress.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

apps/browser-extension-wallet/src/hooks/useWalletState.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ const combineObservable = ({ wallet }: Wallet.CardanoWallet): Observable<Observa
139139
transactionsHistoryOutgoingInFlight,
140140
transactionsHistoryOutgoingSigned,
141141
utxoAvailable,
142-
143142
utxoTotal,
144143
utxoUnspendable
145144
]): ObservableWalletState => ({

apps/browser-extension-wallet/src/styles/themes/light.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ This follows naming from figma
7979
--lace-gradient => linear-gradient(94.22deg, #ff92e1 -18.3%, #fdc300 118.89%)
8080
--lace-pink => #ff92de
8181
--lace-yellow => #fdc300
82+
--lace-pink-shadow => #ff92de66;
8283
8384
--data-pink => #ff5470
8485
--data-pink-10 => rgba(255, 84, 112, 0.1)

apps/browser-extension-wallet/src/types/local-storage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ export interface ILocalStorage {
6666
showMultiAddressModal?: boolean;
6767
userAvatar?: Record<`${EnvironmentTypes}${string}`, string>;
6868
isCustomSubmitApiEnabled?: Record<EnvironmentTypes, CustomSubmitApiConfig>;
69+
isReceiveInAdvancedMode?: boolean;
6970
}

apps/browser-extension-wallet/src/utils/assets-transformers.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import CardanoLogo from '../assets/icons/browser-view/cardano-logo.svg';
99
import { AssetSortBy, IAssetDetails } from '@views/browser/features/assets/types';
1010
import { compactNumberWithUnit, formatLocaleNumber, isNumeric } from '@src/utils/format-number';
1111
import isNumber from 'lodash/isNumber';
12-
import { CurrencyInfo } from '@src/types';
12+
import { CardanoTxOut, CurrencyInfo } from '@src/types';
1313
import { TokenPrice } from '@lib/scripts/types';
1414
import { PriceResult } from '@hooks';
1515
import { getTokenDisplayMetadata } from '@utils/get-token-list';
1616
import { getRandomIcon } from '@lace/common';
17+
import { isNFT } from './is-nft';
1718

1819
export const variationParser = (variation: number): string =>
1920
`${variation > 0 ? '+' : ''}${formatLocaleNumber(variation.toString())}`;
@@ -117,3 +118,20 @@ export const assetTransformer = (params: {
117118

118119
export const getTokenAmountInFiat = (amount: string, priceInADA: number, fiat: number): string =>
119120
new BigNumber(amount).multipliedBy(priceInADA).multipliedBy(fiat).toString(); // first get the price of the amount in ADA and then converted to fiat
121+
122+
export const getTotalAssetsByAddress = (
123+
outputs: CardanoTxOut[],
124+
assets: Wallet.Assets,
125+
targetAddress: string
126+
): { assets: number; nfts: number } => {
127+
const countedAssets = outputs
128+
.filter((output) => output.address === targetAddress && !!output.value.assets)
129+
.flatMap((output) => [...output.value.assets.keys()])
130+
.reduce((allAssets, key) => allAssets.add(key), new Set<string>());
131+
132+
const nftsInAssets = [...countedAssets]
133+
.filter((key: Wallet.Cardano.AssetId) => assets.has(key) && isNFT(assets.get(key)))
134+
.reduce((nfts, key) => nfts.add(key), new Set<string>());
135+
136+
return { assets: countedAssets.size, nfts: nftsInAssets.size };
137+
};

apps/browser-extension-wallet/src/utils/format-number.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,14 @@ export const compactNumberWithUnit = (value: number | string, decimals = DEFAULT
147147
const valueToFormat = bigNumberValue.dividedBy(unitThreshold);
148148
return `${formatLocaleNumber(valueToFormat.toString(), decimals)}${unit}`;
149149
};
150+
151+
export const formatBalance = (value: number): string => {
152+
if (value >= 1_000_000_000) {
153+
return `${(value / 1_000_000_000).toFixed(1).replace(/\.0$/, '')}B`;
154+
} else if (value >= 1_000_000) {
155+
return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
156+
} else if (value >= 1000) {
157+
return `${(value / 1000).toFixed(1).replace(/\.0$/, '')}K`;
158+
}
159+
return value.toString();
160+
};

apps/browser-extension-wallet/src/utils/get-transaction-total-output.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ import BigNumber from 'bignumber.js';
66
*/
77
export const getTransactionTotalOutput = (outputs: CardanoTxOut[]): BigNumber =>
88
outputs.reduce((total, output) => total.plus(output.value.coins.toString()), new BigNumber(0));
9+
10+
export const getTransactionTotalOutputByAddress = (outputs: CardanoTxOut[], targetAddress: string): BigNumber =>
11+
outputs.reduce((total, output) => {
12+
if (output.address === targetAddress) {
13+
return total.plus(output.value.coins.toString());
14+
}
15+
return total;
16+
}, new BigNumber(0));

0 commit comments

Comments
 (0)