Skip to content

Commit

Permalink
Merge commit 'ca31adb52d0318c41eea0bf0a845fb966e7c8044' into 2681----…
Browse files Browse the repository at this point in the history
…update-build-actions-before-they-are-deprecated
  • Loading branch information
MarkNerdi committed Jul 3, 2024
2 parents 1bcc134 + ca31adb commit b643311
Show file tree
Hide file tree
Showing 30 changed files with 358 additions and 233 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@types/node": "18.15.11",
"@typescript-eslint/eslint-plugin": "7.11.0",
"@typescript-eslint/parser": "7.11.0",
"eslint": "9.3.0",
"eslint": "9.6.0",
"eslint-plugin-security": "3.0.0",
"eslint-plugin-svelte": "2.39.0",
"globals": "^15.3.0",
"globals": "^15.7.0",
"husky": "7.0.4",
"lint-staged": "15.2.5",
"patch-package": "8.0.0",
Expand Down
39 changes: 23 additions & 16 deletions packages/desktop/components/popup/popups/SignTypedDataPopup.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<script lang="ts">
import { localize } from '@core/i18n'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { IConnectedDapp } from '@auxiliary/wallet-connect/interface'
import { CallbackParameters } from '@auxiliary/wallet-connect/types'
import { WCRequestInfo } from '@auxiliary/wallet-connect/types'
import { Alert, JsonTree, Table, Text } from '@bloomwalletio/ui'
import { IAccountState } from '@core/account'
import { IEvmNetwork } from '@core/network'
import { AccountLabel, DappInfo } from '@ui'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { LedgerAppName } from '@core/ledger'
import PopupTemplate from '../PopupTemplate.svelte'
import { SignTypedDataVersion } from '@metamask/eth-sig-util'
import { signEip712Message } from '@core/wallet/actions/signEip712Message'
import { DappVerification } from '@auxiliary/wallet-connect/enums'
import { handleError } from '@core/error/handlers'
import { MILLISECONDS_PER_SECOND } from '@core/utils'
import { time } from '@core/app/stores'
import { RequestExpirationAlert } from '@views/dashboard/drawers/dapp-config/components'
export let data: string
export let version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4
export let account: IAccountState
export let evmNetwork: IEvmNetwork
export let dapp: IConnectedDapp
export let verifiedState: DappVerification
export let callback: (params: CallbackParameters) => void
export let requestInfo: WCRequestInfo
const { dapp, responseCallback, verifiedState, evmNetwork, expiryTimestamp } = requestInfo
$: hasExpired =
expiryTimestamp === undefined ? false : expiryTimestamp * MILLISECONDS_PER_SECOND - $time.getTime() <= 0
let isBusy = false
Expand All @@ -37,7 +38,7 @@
const result = await signEip712Message(data, version, evmNetwork.coinType, account)
closePopup({ forceClose: true })
callback({ result })
responseCallback({ result })
openPopup({
id: PopupId.SuccessfulDappInteraction,
props: {
Expand Down Expand Up @@ -66,16 +67,22 @@
continueButton={{
text: localize('popups.signMessage.action'),
onClick: onConfirmClick,
disabled: hasExpired,
}}
busy={isBusy}
>
<DappInfo
slot="banner"
metadata={dapp.metadata}
{verifiedState}
showLink={false}
classes="bg-surface-1 dark:bg-surface-1-dark pb-4"
/>
<svelte:fragment slot="banner">
{#if dapp}
<DappInfo
slot="banner"
metadata={dapp.metadata}
{verifiedState}
showLink={false}
classes="bg-surface-1 dark:bg-surface-1-dark pb-4"
/>
<RequestExpirationAlert {expiryTimestamp} />
{/if}
</svelte:fragment>

<div class="space-y-5">
<div>
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/lib/electron/managers/transak.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ITransakManager, ITransakWindowData } from '@core/app'
import path from 'path'
import { TRANSAK_WIDGET_URL } from '@auxiliary/transak/constants'
import { buildUrl } from '@core/utils/url'
import { MarketCurrency } from '@core/market/enums/market-currency.enum'
import { FiatCurrency } from '@core/market/enums/fiat-currency.enum'
import fs from 'fs'
import { IError } from '@core/error'
import { QueryParameters } from '@core/utils'
Expand Down Expand Up @@ -226,7 +226,7 @@ export default class TransakManager implements ITransakManager {
throw new Error('Undefined Transak API key')
}

if (!Object.values(MarketCurrency).includes(currency as MarketCurrency)) {
if (!Object.values(FiatCurrency).includes(currency as FiatCurrency)) {
throw new Error('Invalid Transak currency')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
TransakWindowPlaceholder,
} from '../components'
import { isDashboardSideBarExpanded } from '@core/ui'
import { MarketCoinId, MarketCurrency } from '@core/market/enums'
import { FiatCurrency, MarketCoinId } from '@core/market/enums'
import { MarketCurrency } from '@core/market/types'
import { marketCoinPrices } from '@core/market/stores'
import { DrawerState } from '@desktop/auxiliary/drawer/types'
import { drawerState } from '@desktop/auxiliary/drawer/stores'
Expand Down Expand Up @@ -67,14 +68,14 @@
function getDefaultFiatAmount(currency: MarketCurrency): number {
const DEFAULT_FIAT_AMOUNT = 1000
switch (currency) {
case MarketCurrency.Usd:
case MarketCurrency.Eur:
case MarketCurrency.Gbp:
case FiatCurrency.USD:
case FiatCurrency.EUR:
case FiatCurrency.GBP:
return DEFAULT_FIAT_AMOUNT
default: {
const conversionRate =
$marketCoinPrices[MarketCoinId.Iota]?.[currency] /
$marketCoinPrices[MarketCoinId.Iota]?.[MarketCurrency.Usd]
$marketCoinPrices[MarketCoinId.Iota]?.[FiatCurrency.USD]
const fiatAmount = DEFAULT_FIAT_AMOUNT * conversionRate
const roundedAmount = customRound(fiatAmount)
return roundedAmount
Expand All @@ -97,7 +98,7 @@
currency: $activeProfile?.settings.marketCurrency,
address: $selectedAccount.depositAddress,
service: 'BUY',
amount: getDefaultFiatAmount($activeProfile?.settings.marketCurrency ?? MarketCurrency.Usd),
amount: getDefaultFiatAmount($activeProfile?.settings.marketCurrency ?? FiatCurrency.USD),
})
isTransakOpen = true
await updateTransakBounds()
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/views/settings/views/profile/Currency.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import { IOption, SelectInput } from '@bloomwalletio/ui'
import { localize } from '@core/i18n'
import { MarketCurrency } from '@core/market'
import { CryptoCurrency, FiatCurrency, MarketCurrency } from '@core/market'
import { activeProfile, updateActiveProfileSettings } from '@core/profile/stores'
import SettingsSection from '../SettingsSection.svelte'
const options: IOption[] = Object.values(MarketCurrency)
const options: IOption[] = [...Object.values(FiatCurrency), ...Object.values(CryptoCurrency)]
.map((currency) => ({ value: currency, label: currency.toUpperCase() }))
.sort()
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test": "jest"
},
"devDependencies": {
"@swc/core": "1.5.24",
"@swc/core": "1.6.6",
"@swc/jest": "0.2.36",
"@types/jest": "29.5.12",
"@types/sanitize-html": "2.11.0",
Expand All @@ -46,9 +46,9 @@
"lokijs": "1.5.12",
"postcss": "8.4.38",
"postcss-cli": "11.0.0",
"svelte-loader": "3.2.0",
"svelte-loader": "3.2.3",
"tailwindcss": "3.4.3",
"tslib": "2.6.2",
"tslib": "2.6.3",
"valid-url": "1.0.9",
"zxcvbn": "4.4.2"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IPersistedAccountData } from '@core/account'
import { APP_STAGE } from '@core/app'
import { MarketCurrency } from '@core/market'
import { FiatCurrency } from '@core/market'
import {
DEFAULT_EVM_NETWORK_CONFIGURATIONS_FOR_STARDUST_NETWORK,
DEFAULT_EXPLORER_URLS,
Expand Down Expand Up @@ -111,7 +111,7 @@ function buildEvmNetworksFromThirdPartyPersistedNetwork(

function buildSettingsFromThirdPartyPersistedSettings(settings: IThirdPartyPersistedSettings): IProfileSettings {
return {
marketCurrency: settings.marketCurrency ?? MarketCurrency.Usd,
marketCurrency: settings.marketCurrency ?? FiatCurrency.USD,
lockScreenTimeoutInMinutes: settings.lockScreenTimeoutInMinutes ?? DEFAULT_LOCK_SCREEN_TIMEOUT_IN_MINUTES,
strongholdPasswordTimeoutInMinutes:
settings.strongholdPasswordTimeoutInMinutes ?? DEFAULT_STRONGHOLD_PASSWORD_TIMEOUT_IN_MINUTES,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { IAccountState, getAddressFromAccountForNetwork } from '@core/account'
import { get } from 'svelte/store'
import { ISupportedNamespace } from '../types'
import { getWalletClient, walletClient } from '../stores'
import { EvmNetworkId } from '@core/network/types'
import { buildCaip10Address } from '../utils'
import { connectedDapps } from '../stores'

export async function addAccountToAllDappSessions(account: IAccountState): Promise<void> {
const dapps = get(connectedDapps)
for (const dapp of dapps) {
if (dapp.sessionTopic && dapp.namespaces) {
await addAccountForDappSession(dapp.sessionTopic, dapp.namespaces, account)
}
}
}

export async function addAccountForDappSession(
sessionTopic: string,
namespaces: Record<string, ISupportedNamespace>,
account: IAccountState
): Promise<void> {
const walletConnectClient = get(walletClient)
if (!walletConnectClient) {
return
}

const protocols = Object.keys(namespaces ?? {})
for (const protocol of protocols) {
if (!namespaces[protocol]) {
continue
}

const chainsForSession = (namespaces[protocol].chains ?? []) as EvmNetworkId[]
const addressOfAccountForEachChain = chainsForSession
.map((chainId) => {
const address = getAddressFromAccountForNetwork(account, chainId)
return address ? buildCaip10Address(address, chainId) : undefined
})
.filter(Boolean) as string[]

namespaces[protocol].accounts = [...addressOfAccountForEachChain, ...namespaces[protocol].accounts]
}

await getWalletClient()?.updateSession({ topic: sessionTopic, namespaces })
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './addAccountToAllDappSessions'
export * from './approveSession'
export * from './approveSessionAuthenticate'
export * from './buildSupportedNamespaceFromSelections'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { setSelectedAccount } from './setSelectedAccount'
import { getActiveProfile } from '@core/profile/stores'
import { ProfileType } from '@core/profile'
import { generateAndStoreEvmAddressForAccounts, pollEvmBalancesForAccount } from '@core/layer-2/actions'
import { getEvmNetworks } from '@core/network/stores'
import { IError } from '@core/error/interfaces'
import { DEFAULT_COIN_TYPE, SupportedNetworkId } from '@core/network/constants'
import { addAccountToAllDappSessions, updateAccountForConnectedDapps } from '@auxiliary/wallet-connect/actions'

export async function tryCreateAdditionalAccount(alias: string, color: string): Promise<void> {
try {
Expand All @@ -21,11 +22,12 @@ export async function tryCreateAdditionalAccount(alias: string, color: string):

const activeProfile = getActiveProfile()
if (activeProfile.type === ProfileType.Software) {
const coinType = getEvmNetworks()[0]?.coinType
if (coinType !== undefined) {
void generateAndStoreEvmAddressForAccounts(activeProfile.type, coinType, account)
const coinType = DEFAULT_COIN_TYPE[SupportedNetworkId.Ethereum]
generateAndStoreEvmAddressForAccounts(activeProfile.type, coinType, account).then(async () => {
void pollEvmBalancesForAccount(activeProfile.id, account)
}
await addAccountToAllDappSessions(account)
await updateAccountForConnectedDapps(account)
})
}

return Promise.resolve()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarketCurrency } from '@core/market/enums/market-currency.enum'
import { MarketCurrency } from '@core/market/types'

export interface ITransakWindowData {
currency: MarketCurrency
Expand Down
10 changes: 10 additions & 0 deletions packages/shared/src/lib/core/i18n/utils/formatCurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ export function formatCurrency(
convertedValue = Number(value.toFixed(2))
}

const isCurrencyNotSupported = currency?.length > 3
if (isCurrencyNotSupported) {
const formattedValue = convertedValue.toLocaleString(appLanguage, {
minimumFractionDigits: 2,
maximumFractionDigits: 20,
useGrouping: grouped,
})
return `${formattedValue} ${currency.toUpperCase()}`
}

const formatter = Intl.NumberFormat(appLanguage, {
style: 'currency',
currency: currency ?? 'USD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export function getDecimalSeparator(currency: string | undefined = undefined): s
currency = get(activeProfile)?.settings?.marketCurrency
}

const isCurrencySupportedByIntl = currency?.length <= 3
return (
Intl.NumberFormat(appLanguage, {
style: 'currency',
currency: currency ?? 'USD',
currency: isCurrencySupportedByIntl ? currency : 'USD',
})
.formatToParts(1.1)
.find((part) => part.type === 'decimal')?.value ?? '.'
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/lib/core/i18n/utils/getGroupSeparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export function getGroupSeparator(currency: string | undefined = undefined): str
currency = get(activeProfile)?.settings?.marketCurrency
}

const isCurrencySupportedByIntl = currency?.length <= 3
return (
Intl.NumberFormat(appLanguage, {
style: 'currency',
currency: currency ?? 'USD',
currency: isCurrencySupportedByIntl ? currency : 'USD',
})
.formatToParts(1111111)
.find((part) => part.type === 'group')?.value ?? ','
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get } from 'svelte/store'
import { CoinGeckoApi } from '../apis'
import { MarketCoinId, MarketCurrency } from '../enums'
import { CryptoCurrency, FiatCurrency, MarketCoinId } from '../enums'
import { CoinGeckoCoin } from '../interfaces'
import { coinGeckoTokensMetadata, updateMarketCoinPrices } from '../stores'

Expand All @@ -12,7 +12,7 @@ export async function getAndUpdateMarketPrices(): Promise<void> {

const marketPricesResponse = await CoinGeckoApi.getSimplePrices(
[MarketCoinId.Iota, MarketCoinId.Shimmer, MarketCoinId.Ethereum, ...storedTokenIds],
Object.values(MarketCurrency)
[...Object.values(FiatCurrency), ...Object.values(CryptoCurrency)]
)
updateMarketCoinPrices(marketPricesResponse)
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/lib/core/market/apis/coingecko.api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DEFAULT_APPLICATION_JSON_REQUEST_OPTIONS, QueryParameters, buildUrl } from '@core/utils'
import { MARKET_API_BASE_URL } from '../constants'
import { CoinGeckoApiEndpoint, CoinGeckoNetworkId, MarketCoinId, MarketCurrency } from '../enums'
import { MarketCoinPrices } from '../types'
import { CoinGeckoApiEndpoint, CoinGeckoNetworkId, MarketCoinId } from '../enums'
import { MarketCoinPrices, MarketCurrency } from '../types'
import { CoinGeckoCoin } from '../interfaces'
import { localize } from '@core/i18n'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { MarketCurrency } from '../enums'
import { FiatCurrency } from '../enums'

export const DEFAULT_MARKET_CURRENCY = MarketCurrency.Usd
export const DEFAULT_MARKET_CURRENCY = FiatCurrency.USD
16 changes: 16 additions & 0 deletions packages/shared/src/lib/core/market/enums/crypto-currency.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Coingecko supported crypto currencies prices
export enum CryptoCurrency {
BTC = 'btc',
ETH = 'eth',
LTC = 'ltc',
BCH = 'bch',
BNB = 'bnb',
EOS = 'eos',
XRP = 'xrp',
XLM = 'xlm',
LINK = 'link',
DOT = 'dot',
YFI = 'yfi',
BITS = 'bits',
SATS = 'sats',
}
Loading

0 comments on commit b643311

Please sign in to comment.