Skip to content

Commit

Permalink
Merge branch 'develop' into l10n_develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nicole-obrien authored Jun 11, 2024
2 parents 32f3b47 + a624244 commit 6fab811
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 19 deletions.
21 changes: 16 additions & 5 deletions packages/desktop/components/AccountSwitcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
export let breadcrumb: boolean = false
export let compact: boolean = false
export let hasCreateAccount: boolean = false
export let placement: 'bottom-start' | 'bottom-end' = 'bottom-start'
Expand All @@ -30,7 +29,19 @@
onClick: () => onAccountClick(account.index),
}
})
const totalBalance = Object.values($allAccountFiatBalances)
.reduce((acc, balance) => Number(acc) + Number(balance), 0)
.toString()
items = items.concat({
title: localize('general.totalBalance'),
subtitle: formatCurrency(totalBalance),
selected: false,
hidden: accounts.length < 2,
})
}
$: setItems($visibleActiveAccounts, $selectedAccount?.index)
function onCreateAccountClick(): void {
Expand All @@ -41,7 +52,7 @@

<Menu
{items}
{compact}
compact={false}
{...hasCreateAccount && { button: { text: localize('general.newAccount'), onClick: onCreateAccountClick } }}
{placement}
maxHeight={320}
Expand All @@ -51,12 +62,12 @@
{#if breadcrumb}
<Indicator color={$selectedAccount?.color} size="sm" />
{/if}
<div class="flex flex-row justify-center items-center {compact ? 'space-x-1' : 'space-x-2'}">
<Text type={compact ? 'base' : 'body1'}>
<div class="flex flex-row justify-center items-center {breadcrumb ? 'space-x-1' : 'space-x-2'}">
<Text type={breadcrumb ? 'base' : 'body1'}>
{$selectedAccount?.name}
</Text>
{#if !breadcrumb}
<Icon name={IconName.ChevronSelectorVertical} size={compact ? 'xs' : 'sm'} textColor="secondary" />
<Icon name={IconName.ChevronSelectorVertical} size="sm" textColor="secondary" />
{/if}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
/>
<div class="flex flex-row space-x-1 items-center">
<div class="shrink-0">
<AccountSwitcher breadcrumb compact />
<AccountSwitcher breadcrumb hasCreateAccount />
</div>
<Icon name={IconName.ChevronRight} size="sm" />
<Breadcrumb
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Bloom Labs Ltd <[email protected]>",
"license": "PolyForm Strict License 1.0.0",
"dependencies": {
"@bloomwalletio/ui": "0.21.1",
"@bloomwalletio/ui": "0.21.3",
"@ethereumjs/common": "4.3.0",
"@ethereumjs/rlp": "5.0.2",
"@ethereumjs/tx": "5.3.0",
Expand All @@ -16,7 +16,7 @@
"@metamask/eth-sig-util": "7.0.1",
"@spruceid/siwe-parser": "2.0.2",
"@sveltejs/svelte-virtual-list": "3.0.1",
"@walletconnect/jsonrpc-types": "1.0.3",
"@walletconnect/jsonrpc-types": "1.0.4",
"@walletconnect/types": "2.11.3",
"@walletconnect/web3wallet": "1.11.2",
"http-status-codes": "2.3.0",
Expand Down
22 changes: 19 additions & 3 deletions packages/shared/src/lib/core/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,28 @@ export class Converter {
* @returns The bytes.
*/
public static bigIntLikeToBigInt(number: BigIntLike | undefined): bigint {
if (number === undefined || number === null || Number.isNaN(number)) {
return BigInt(0)
}

if (ArrayBuffer.isView(number)) {
return bytesToBigInt(number)
} else {
number = number === '0x' ? '0x0' : number
return BigInt(String(number ?? '0'))
}

if (typeof number === 'string') {
if (number === '0x') {
return BigInt('0x0')
}
if (/\d+\.?\d*e[+-]?\d+/i.test(number)) {
number = Number(number)
}
}

if (typeof number === 'number' && !Number.isInteger(number)) {
number = Math.floor(number)
}

return BigInt(number)
}

/**
Expand Down
23 changes: 23 additions & 0 deletions packages/shared/src/lib/core/utils/tests/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,30 @@ describe('File: convert.ts', () => {
expect(Converter.bigIntLikeToBigInt('0')).toEqual(BigInt(0))
expect(Converter.bigIntLikeToBigInt(100)).toEqual(BigInt(100))
expect(Converter.bigIntLikeToBigInt('123330')).toEqual(BigInt(123330))
})
it('should handle floats by truncating', () => {
expect(Converter.bigIntLikeToBigInt(123.456)).toEqual(BigInt(123))
})
it('should handle scientific notation', () => {
expect(Converter.bigIntLikeToBigInt('1e6')).toEqual(BigInt(1000000))
expect(Converter.bigIntLikeToBigInt('1.23e3')).toEqual(BigInt(1230))
expect(Converter.bigIntLikeToBigInt('-1e6')).toEqual(BigInt(-1000000))
expect(Converter.bigIntLikeToBigInt('1.23e-3')).toEqual(BigInt(0))
})
it('should handle string representations of numbers', () => {
expect(Converter.bigIntLikeToBigInt('123456789012345678901234567890')).toEqual(
BigInt('123456789012345678901234567890')
)
expect(Converter.bigIntLikeToBigInt('-123456789012345678901234567890')).toEqual(
BigInt('-123456789012345678901234567890')
)
})
it('should handle edge cases', () => {
expect(Converter.bigIntLikeToBigInt('')).toEqual(BigInt(0))
expect(Converter.bigIntLikeToBigInt(undefined)).toEqual(BigInt(0))
expect(Converter.bigIntLikeToBigInt(null)).toEqual(BigInt(0))
expect(Converter.bigIntLikeToBigInt(NaN)).toEqual(BigInt(0))
expect(Converter.bigIntLikeToBigInt(false)).toEqual(BigInt(0))
})
})
})
3 changes: 2 additions & 1 deletion packages/shared/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,8 @@
"average": "Average",
"fast": "Fast",
"spender": "Spender",
"status": "Status"
"status": "Status",
"totalBalance": "Total balance"
},
"filters":{
"title": "Filters",
Expand Down
47 changes: 40 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@bloomwalletio/[email protected].1":
version "0.21.1"
resolved "https://npm.pkg.github.com/download/@bloomwalletio/ui/0.21.1/ce60ed69ad083f7ebc27164cc2fa69c8bf1a041f#ce60ed69ad083f7ebc27164cc2fa69c8bf1a041f"
integrity sha512-1//FX06CFUvv2SXUHQGZwQ9Y8FbO/Irj8cYO3cVXNbQHiM93UCtxgb/jYmryaOSHBrhH7OtrzDt+/0Hg88BA1w==
"@bloomwalletio/[email protected].3":
version "0.21.3"
resolved "https://npm.pkg.github.com/download/@bloomwalletio/ui/0.21.3/2bf5587205e01b89f67cd6b990495d3a1175b5de#2bf5587205e01b89f67cd6b990495d3a1175b5de"
integrity sha512-McwM3nbGmGkkq8zJAWBfriMvSDXXurTrqL26vHrTbNP1LNJJSujRo4o2Oep0sjf1xeQRoHy7HZSPVml/EKwF/g==
dependencies:
"@floating-ui/dom" "1.4.3"
"@popperjs/core" "2.11.8"
Expand Down Expand Up @@ -2840,6 +2840,14 @@
keyvaluestorage-interface "^1.0.0"
tslib "1.14.1"

"@walletconnect/[email protected]":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@walletconnect/jsonrpc-types/-/jsonrpc-types-1.0.4.tgz#ce1a667d79eadf2a2d9d002c152ceb68739c230c"
integrity sha512-P6679fG/M+wuWg9TY8mh6xFSdYnFyFjwFelxyISxMDrlbXokorEVXYOxiqEbrU3x1BmBoCAJJ+vtEaEoMlpCBQ==
dependencies:
events "^3.3.0"
keyvaluestorage-interface "^1.0.0"

"@walletconnect/[email protected]", "@walletconnect/jsonrpc-utils@^1.0.6", "@walletconnect/jsonrpc-utils@^1.0.8":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@walletconnect/jsonrpc-utils/-/jsonrpc-utils-1.0.8.tgz#82d0cc6a5d6ff0ecc277cb35f71402c91ad48d72"
Expand Down Expand Up @@ -9903,7 +9911,16 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -9980,7 +9997,14 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -11347,7 +11371,16 @@ word-wrap@^1.2.5:
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down

0 comments on commit 6fab811

Please sign in to comment.