From 00ec6ea095e221769b308b325cec6faee962bfce Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Thu, 7 Nov 2024 11:27:37 +0800 Subject: [PATCH] feat: providers are now consumed from the service worker instead of the UI script (#1507) * feat: providers are now consumed from the service worker instead of the UI script * fixup! feat: providers are now consumed from the service worker instead of the UI script * fixup! feat: providers are now consumed from the service worker instead of the UI script * fixup! feat: providers are now consumed from the service worker instead of the UI script * fixup! feat: providers are now consumed from the service worker instead of the UI script * fixup! feat: providers are now consumed from the service worker instead of the UI script --------- Co-authored-by: Martynas Kazlauskas --- apps/browser-extension-wallet/package.json | 6 +- .../DappTransactionContainer.tsx | 9 +- .../DappTransactionContainer.test.tsx | 21 +++-- .../src/hooks/index.ts | 1 - .../src/hooks/useChainHistoryProvider.ts | 21 ----- .../src/lib/scripts/background/wallet.ts | 19 ++++- .../slices/blockchain-provider-slice.ts | 66 ++++++-------- .../QRInfoWalletDrawer/QRInfoWalletDrawer.tsx | 8 +- .../restore-wallet/steps/WalletOverview.tsx | 4 +- packages/cardano/package.json | 8 +- packages/cardano/src/wallet/lib/providers.ts | 43 ++++++++++ packages/core/package.json | 4 +- packages/nami/package.json | 3 +- packages/nami/src/api/util.ts | 12 ++- packages/staking/package.json | 8 +- yarn.lock | 85 ++++++++++--------- 16 files changed, 177 insertions(+), 141 deletions(-) delete mode 100644 apps/browser-extension-wallet/src/hooks/useChainHistoryProvider.ts diff --git a/apps/browser-extension-wallet/package.json b/apps/browser-extension-wallet/package.json index 584381b6bb..30bc474232 100644 --- a/apps/browser-extension-wallet/package.json +++ b/apps/browser-extension-wallet/package.json @@ -41,15 +41,15 @@ }, "dependencies": { "@ant-design/icons": "^4.7.0", - "@cardano-sdk/cardano-services-client": "0.21.6", + "@cardano-sdk/cardano-services-client": "0.21.7", "@cardano-sdk/core": "0.41.2", "@cardano-sdk/dapp-connector": "0.12.42", "@cardano-sdk/input-selection": "0.13.25", "@cardano-sdk/tx-construction": "0.21.10", "@cardano-sdk/util": "0.15.5", "@cardano-sdk/util-rxjs": "0.7.38", - "@cardano-sdk/wallet": "0.44.14", - "@cardano-sdk/web-extension": "0.34.13", + "@cardano-sdk/wallet": "0.44.15", + "@cardano-sdk/web-extension": "0.34.14", "@emurgo/cip14-js": "~3.0.1", "@input-output-hk/lace-ui-toolkit": "1.21.0", "@lace/cardano": "0.1.0", diff --git a/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/DappTransactionContainer.tsx b/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/DappTransactionContainer.tsx index a387dc64c9..aaf64d5bcd 100644 --- a/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/DappTransactionContainer.tsx +++ b/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/DappTransactionContainer.tsx @@ -12,7 +12,7 @@ import { useViewsFlowContext } from '@providers/ViewFlowProvider'; import { Wallet } from '@lace/cardano'; import { useAddressBookContext, withAddressBookContext } from '@src/features/address-book/context'; import { useWalletStore } from '@stores'; -import { useFetchCoinPrice, useChainHistoryProvider } from '@hooks'; +import { useFetchCoinPrice } from '@hooks'; import { createTxInspector, TransactionSummaryInspection, @@ -25,7 +25,7 @@ import { import { createWalletAssetProvider } from '@cardano-sdk/wallet'; import { Skeleton } from 'antd'; -import { useCurrencyStore, useAppSettingsContext } from '@providers'; +import { useCurrencyStore } from '@providers'; import { logger, walletRepository } from '@lib/wallet-api-ui'; import { useComputeTxCollateral } from '@hooks/useComputeTxCollateral'; import { utxoAndBackendChainHistoryResolver } from '@src/utils/utxo-chain-history-resolver'; @@ -34,6 +34,7 @@ import { AddressBookSchema, useDbStateValue } from '@lib/storage'; import { getAllWalletsAddresses } from '@src/utils/get-all-wallets-addresses'; import { useCexplorerBaseUrl, useDisallowSignTx } from './hooks'; import { NonRegisteredUserModal } from './NonRegisteredUserModal/NonRegisteredUserModal'; +import { getProviders } from '@stores/slices'; interface DappTransactionContainerProps { errorMessage?: string; @@ -69,8 +70,6 @@ export const DappTransactionContainer = withAddressBookContext( const { fiatCurrency } = useCurrencyStore(); const { priceResult } = useFetchCoinPrice(); - const [{ chainName }] = useAppSettingsContext(); - const [fromAddressTokens, setFromAddressTokens] = useState< Map | undefined >(); @@ -81,7 +80,7 @@ export const DappTransactionContainer = withAddressBookContext( TransactionSummaryInspection | undefined >(); - const chainHistoryProvider = useChainHistoryProvider({ chainName }); + const { chainHistoryProvider } = getProviders(); const txInputResolver = useMemo( () => diff --git a/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/__tests__/DappTransactionContainer.test.tsx b/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/__tests__/DappTransactionContainer.test.tsx index 9d98f1a560..11f94b7939 100644 --- a/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/__tests__/DappTransactionContainer.test.tsx +++ b/apps/browser-extension-wallet/src/features/dapp/components/confirm-transaction/__tests__/DappTransactionContainer.test.tsx @@ -19,11 +19,6 @@ const mockWithAddressBookContext = jest.fn((children) => children); const mockUseCurrencyStore = jest.fn().mockReturnValue({ fiatCurrency: { code: 'usd', symbol: '$' } }); const mockUseFetchCoinPrice = jest.fn().mockReturnValue({ priceResult: { cardano: { price: 2 }, tokens: new Map() } }); const mockUseComputeTxCollateral = jest.fn().mockReturnValue(BigInt(1_000_000)); -const mockUseChainHistoryProvider = jest.fn().mockReturnValue({ - transactionsByAddress: jest.fn().mockResolvedValue([]), - transactionsByHashes: jest.fn().mockResolvedValue([]), - blocksByHashes: jest.fn().mockResolvedValue([]) -}); import * as React from 'react'; import { cleanup, render } from '@testing-library/react'; import { DappTransactionContainer } from '../DappTransactionContainer'; @@ -127,9 +122,19 @@ jest.mock('@providers/currency', (): typeof CurrencyProvider => ({ useCurrencyStore: mockUseCurrencyStore })); -jest.mock('@hooks/useChainHistoryProvider', (): typeof CurrencyProvider => ({ - ...jest.requireActual('@hooks/useChainHistoryProvider'), - useChainHistoryProvider: mockUseChainHistoryProvider +const mockProviders = { + chainHistoryProvider: { + transactionsByAddress: jest.fn().mockResolvedValue([]), + transactionsByHashes: jest.fn().mockResolvedValue([]), + blocksByHashes: jest.fn().mockResolvedValue([]) + }, + assetProvider +}; + +jest.mock('@stores/slices/blockchain-provider-slice', () => ({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ...jest.requireActual('@stores/slices/blockchain-provider-slice'), + getProviders: () => mockProviders })); jest.mock('@lace/core', () => { diff --git a/apps/browser-extension-wallet/src/hooks/index.ts b/apps/browser-extension-wallet/src/hooks/index.ts index 4b7a8e4f88..18a7f3052f 100644 --- a/apps/browser-extension-wallet/src/hooks/index.ts +++ b/apps/browser-extension-wallet/src/hooks/index.ts @@ -21,7 +21,6 @@ export * from './useAssetInfo'; export * from './useUpdateAddressStatus'; export * from './useOnAddressSave'; export * from './useAppInit'; -export * from './useChainHistoryProvider'; export * from './useWalletAvatar'; export * from './useActionExecution'; export * from './useCustomSubmitApi'; diff --git a/apps/browser-extension-wallet/src/hooks/useChainHistoryProvider.ts b/apps/browser-extension-wallet/src/hooks/useChainHistoryProvider.ts deleted file mode 100644 index 4165ef9e8c..0000000000 --- a/apps/browser-extension-wallet/src/hooks/useChainHistoryProvider.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { getBaseUrlForChain } from '@src/utils/chain'; -import { useMemo } from 'react'; -import { chainHistoryHttpProvider } from '@cardano-sdk/cardano-services-client'; -import { logger } from '@lib/wallet-api-ui'; -import axiosFetchAdapter from '@shiroyasha9/axios-fetch-adapter'; - -export type NetworkType = 'Mainnet' | 'Preprod' | 'Preview' | 'Sanchonet'; - -type UseChainHistoryProviderArgs = { - chainName: NetworkType; -}; - -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const useChainHistoryProvider = ({ chainName }: UseChainHistoryProviderArgs) => { - const baseCardanoServicesUrl = getBaseUrlForChain(chainName); - - return useMemo( - () => chainHistoryHttpProvider({ adapter: axiosFetchAdapter, baseUrl: baseCardanoServicesUrl, logger }), - [baseCardanoServicesUrl] - ); -}; diff --git a/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts b/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts index 2bc05ff738..b089ade1c4 100644 --- a/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts +++ b/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts @@ -1,5 +1,5 @@ import { runtime, storage as webStorage } from 'webextension-polyfill'; -import { of, combineLatest, map, EMPTY } from 'rxjs'; +import { of, combineLatest, map, EMPTY, BehaviorSubject } from 'rxjs'; import { getProviders } from './config'; import { DEFAULT_LOOK_AHEAD_SEARCH, @@ -60,17 +60,23 @@ const chainIdToChainName = (chainId: Cardano.ChainId): Wallet.ChainName => { } }; +// eslint-disable-next-line unicorn/no-null +const currentWalletProviders$ = new BehaviorSubject(null); + const walletFactory: WalletFactory = { create: async ({ chainId, accountIndex }, wallet, { stores, witnesser }) => { const chainName: Wallet.ChainName = chainIdToChainName(chainId); const providers = await getProviders(chainName); + // Caches current wallet providers. + currentWalletProviders$.next(providers); + const baseUrl = getBaseUrlForChain(chainName); // Sanchonet does not have a handle provider const supportsHandleResolver = chainName !== 'Sanchonet'; - // This is used in place of the handle provider for environments where the handle provider is not available + // This is used in place ofgetProviders the handle provider for environments where the handle provider is not available const noopHandleResolver: HandleProvider = { resolveHandles: async () => [], healthCheck: async () => ({ ok: true }), @@ -232,6 +238,15 @@ walletManager }, { logger, runtime } ); + + exposeApi( + { + api$: currentWalletProviders$, + baseChannel: Wallet.walletProvidersChannel(process.env.WALLET_NAME), + properties: Wallet.walletProvidersProperties + }, + { logger, runtime } + ); }) .catch((error) => { logger.error('Failed to initialize wallet manager', error); diff --git a/apps/browser-extension-wallet/src/stores/slices/blockchain-provider-slice.ts b/apps/browser-extension-wallet/src/stores/slices/blockchain-provider-slice.ts index d8de1d50e8..b7a5d02458 100644 --- a/apps/browser-extension-wallet/src/stores/slices/blockchain-provider-slice.ts +++ b/apps/browser-extension-wallet/src/stores/slices/blockchain-provider-slice.ts @@ -1,10 +1,7 @@ import { BlockchainProviderSlice, SliceCreator } from '../types'; import { Wallet } from '@lace/cardano'; -import { getBaseUrlForChain } from '@src/utils/chain'; -import axiosFetchAdapter from '@shiroyasha9/axios-fetch-adapter'; -import { config } from '@src/config'; - -const { CHAIN } = config(); +import { consumeRemoteApi } from '@cardano-sdk/web-extension'; +import { runtime } from 'webextension-polyfill'; export interface IBlockchainProvider { stakePoolProvider: Wallet.StakePoolProvider; @@ -16,45 +13,38 @@ export interface IBlockchainProvider { rewardsProvider: Wallet.RewardsProvider; } -export type BlockchainProviderFactory = (chainName: Wallet.ChainName) => IBlockchainProvider; +export type BlockchainProviderFactory = () => IBlockchainProvider; export const IBlockchainProvider = { toWalletProviders: (providers: IBlockchainProvider): Wallet.WalletProvidersDependencies => ({ - stakePoolProvider: providers.stakePoolProvider, - assetProvider: providers.assetProvider, - txSubmitProvider: providers.txSubmitProvider, - networkInfoProvider: providers.networkInfoProvider, - utxoProvider: providers.utxoProvider, - rewardsProvider: providers.rewardsProvider, - chainHistoryProvider: providers.chainHistoryProvider + stakePoolProvider: providers?.stakePoolProvider, + assetProvider: providers?.assetProvider, + txSubmitProvider: providers?.txSubmitProvider, + networkInfoProvider: providers?.networkInfoProvider, + utxoProvider: providers?.utxoProvider, + rewardsProvider: providers?.rewardsProvider, + chainHistoryProvider: providers?.chainHistoryProvider }), fromWalletProviders: (providers: Wallet.WalletProvidersDependencies): IBlockchainProvider => ({ - txSubmitProvider: providers.txSubmitProvider, - assetProvider: providers.assetProvider, - stakePoolProvider: providers.stakePoolProvider, - networkInfoProvider: providers.networkInfoProvider, - utxoProvider: providers.utxoProvider, - rewardsProvider: providers.rewardsProvider, - chainHistoryProvider: providers.chainHistoryProvider + txSubmitProvider: providers?.txSubmitProvider, + assetProvider: providers?.assetProvider, + stakePoolProvider: providers?.stakePoolProvider, + networkInfoProvider: providers?.networkInfoProvider, + utxoProvider: providers?.utxoProvider, + rewardsProvider: providers?.rewardsProvider, + chainHistoryProvider: providers?.chainHistoryProvider }) }; -export const getProviderByChain: BlockchainProviderFactory = (chain = CHAIN) => { - const baseCardanoServicesUrl = getBaseUrlForChain(chain); - - // TODO: LW-11761 reuse providers that are running in SW instead - const providers = Wallet.createProviders({ - axiosAdapter: axiosFetchAdapter, - env: { - baseCardanoServicesUrl, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - blockfrostConfig: {} as any - }, - experiments: {} - }); +const providers = consumeRemoteApi( + { + baseChannel: Wallet.walletProvidersChannel(process.env.WALLET_NAME), + properties: Wallet.walletProvidersProperties + }, + { logger: console, runtime } +); - return IBlockchainProvider.fromWalletProviders(providers); -}; +export const getProviders: BlockchainProviderFactory = () => IBlockchainProvider.fromWalletProviders(providers); /** * has all wallet info related actions and states @@ -63,7 +53,7 @@ export const blockchainProviderSlice: SliceCreator< BlockchainProviderSlice, BlockchainProviderSlice, { currentChainName: Wallet.ChainName; blockchainProviderFactory?: BlockchainProviderFactory } -> = ({ set }, { currentChainName, blockchainProviderFactory = getProviderByChain }) => ({ - blockchainProvider: blockchainProviderFactory(currentChainName), - setBlockchainProvider: (chain) => set({ blockchainProvider: blockchainProviderFactory(chain) }) +> = ({ set }, { blockchainProviderFactory = getProviders }) => ({ + blockchainProvider: blockchainProviderFactory(), + setBlockchainProvider: () => set({ blockchainProvider: blockchainProviderFactory() }) }); diff --git a/apps/browser-extension-wallet/src/views/browser-view/components/QRInfoWalletDrawer/QRInfoWalletDrawer.tsx b/apps/browser-extension-wallet/src/views/browser-view/components/QRInfoWalletDrawer/QRInfoWalletDrawer.tsx index a14fe23712..6e0a5f861d 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/components/QRInfoWalletDrawer/QRInfoWalletDrawer.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/components/QRInfoWalletDrawer/QRInfoWalletDrawer.tsx @@ -9,16 +9,17 @@ import { useDrawer } from '../../stores'; import { getQRCodeOptions } from '@src/utils/qrCodeHelpers'; import { Banner, useKeyboardShortcut, useObservable } from '@lace/common'; import { getAssetImageUrl } from '@src/utils/get-asset-image-url'; -import { useAnalyticsContext, useAppSettingsContext } from '@providers'; +import { useAnalyticsContext } from '@providers'; import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker'; import { Button, Flex } from '@input-output-hk/lace-ui-toolkit'; import { ExclamationCircleOutlined, PlusCircleOutlined } from '@ant-design/icons'; -import { useChainHistoryProvider, useLocalStorage } from '@hooks'; +import { useLocalStorage } from '@hooks'; import { Divider } from 'antd'; import { Wallet } from '@lace/cardano'; import { getTransactionTotalOutputByAddress } from '@src/utils/get-transaction-total-output'; import { getTotalAssetsByAddress } from '@src/utils/assets-transformers'; import { formatBalance } from '@src/utils/format-number'; +import { getProviders } from '@stores/slices'; type WalletData = { address: Wallet.Cardano.PaymentAddress; @@ -99,8 +100,7 @@ export const QRInfoWalletDrawer = (): React.ReactElement => { const [currentUnusedAddress, setCurrentUnusedAddress] = useState(); const [, closeDrawer] = useDrawer(); const [isReceiveInAdvancedMode] = useLocalStorage('isReceiveInAdvancedMode', false); - const [{ chainName }] = useAppSettingsContext(); - const chainHistoryProvider = useChainHistoryProvider({ chainName }); + const { chainHistoryProvider } = getProviders(); useKeyboardShortcut(['Escape'], () => closeDrawer()); diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/WalletOverview.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/WalletOverview.tsx index 628216643c..ca9ee0db5e 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/WalletOverview.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/WalletOverview.tsx @@ -19,7 +19,7 @@ import { Wallet } from '@lace/cardano'; import { compactNumberWithUnit } from '@src/utils/format-number'; import { PortfolioBalance } from '@src/views/browser-view/components'; import { addEllipsis, WarningBanner, toast } from '@lace/common'; -import { getProviderByChain } from '@src/stores/slices'; +import { getProviders } from '@src/stores/slices'; import { CARDANO_COIN_SYMBOL, COINGECKO_URL } from '@src/utils/constants'; import BigNumber from 'bignumber.js'; import styles from './WalletOverview.module.scss'; @@ -59,7 +59,7 @@ export const WalletOverview = (): JSX.Element => { const getData = async () => { if (!walletMetadata || !coinPricing.priceResult.cardano.price) return; try { - const { utxoProvider } = getProviderByChain(walletMetadata.chain); + const { utxoProvider } = getProviders(); const utxos: Wallet.Cardano.Utxo[] = await utxoProvider.utxoByAddresses({ addresses: [walletMetadata.address] }); diff --git a/packages/cardano/package.json b/packages/cardano/package.json index acd9bf97c1..8e028a6785 100644 --- a/packages/cardano/package.json +++ b/packages/cardano/package.json @@ -40,7 +40,7 @@ "watch": "yarn build --watch" }, "dependencies": { - "@cardano-sdk/cardano-services-client": "0.21.6", + "@cardano-sdk/cardano-services-client": "0.21.7", "@cardano-sdk/core": "0.41.2", "@cardano-sdk/crypto": "0.1.30", "@cardano-sdk/hardware-ledger": "0.12.10", @@ -48,8 +48,8 @@ "@cardano-sdk/key-management": "0.24.8", "@cardano-sdk/tx-construction": "0.21.10", "@cardano-sdk/util": "0.15.5", - "@cardano-sdk/wallet": "0.44.14", - "@cardano-sdk/web-extension": "0.34.13", + "@cardano-sdk/wallet": "0.44.15", + "@cardano-sdk/web-extension": "0.34.14", "@lace/common": "0.1.0", "@ledgerhq/devices": "^8.2.1", "@stablelib/chacha20poly1305": "1.0.1", @@ -73,7 +73,7 @@ }, "devDependencies": { "@blockfrost/blockfrost-js": "^5.5.0", - "@cardano-sdk/util-dev": "0.23.8", + "@cardano-sdk/util-dev": "0.23.9", "@emurgo/cardano-message-signing-browser": "1.0.1", "@types/webextension-polyfill": "0.10.0", "axios": "^1.7.4", diff --git a/packages/cardano/src/wallet/lib/providers.ts b/packages/cardano/src/wallet/lib/providers.ts index 018ac40792..7f617ffdfd 100644 --- a/packages/cardano/src/wallet/lib/providers.ts +++ b/packages/cardano/src/wallet/lib/providers.ts @@ -29,6 +29,7 @@ import { } from '@cardano-sdk/cardano-services-client'; import { BlockfrostClient, BlockfrostClientConfig, RateLimiter } from './blockfrost/blockfrost-client'; import { BlockfrostAssetProvider } from './blockfrost'; +import { RemoteApiProperties, RemoteApiPropertyType } from '@cardano-sdk/web-extension'; const createTxSubmitProvider = ( httpProviderConfig: CreateHttpProviderConfig, @@ -159,3 +160,45 @@ export const createProviders = ({ rewardsProvider }; }; + +export const walletProvidersChannel = (walletName: string): string => `${walletName}-providers`; +export const walletProvidersProperties: RemoteApiProperties = { + stakePoolProvider: { + queryStakePools: RemoteApiPropertyType.MethodReturningPromise, + stakePoolStats: RemoteApiPropertyType.MethodReturningPromise, + healthCheck: RemoteApiPropertyType.MethodReturningPromise + }, + assetProvider: { + getAsset: RemoteApiPropertyType.MethodReturningPromise, + getAssets: RemoteApiPropertyType.MethodReturningPromise, + healthCheck: RemoteApiPropertyType.MethodReturningPromise + }, + txSubmitProvider: { + submitTx: RemoteApiPropertyType.MethodReturningPromise, + healthCheck: RemoteApiPropertyType.MethodReturningPromise + }, + networkInfoProvider: { + ledgerTip: RemoteApiPropertyType.MethodReturningPromise, + protocolParameters: RemoteApiPropertyType.MethodReturningPromise, + genesisParameters: RemoteApiPropertyType.MethodReturningPromise, + lovelaceSupply: RemoteApiPropertyType.MethodReturningPromise, + stake: RemoteApiPropertyType.MethodReturningPromise, + eraSummaries: RemoteApiPropertyType.MethodReturningPromise, + healthCheck: RemoteApiPropertyType.MethodReturningPromise + }, + utxoProvider: { + utxoByAddresses: RemoteApiPropertyType.MethodReturningPromise, + healthCheck: RemoteApiPropertyType.MethodReturningPromise + }, + rewardsProvider: { + rewardsHistory: RemoteApiPropertyType.MethodReturningPromise, + rewardAccountBalance: RemoteApiPropertyType.MethodReturningPromise, + healthCheck: RemoteApiPropertyType.MethodReturningPromise + }, + chainHistoryProvider: { + transactionsByAddresses: RemoteApiPropertyType.MethodReturningPromise, + transactionsByHashes: RemoteApiPropertyType.MethodReturningPromise, + blocksByHashes: RemoteApiPropertyType.MethodReturningPromise, + healthCheck: RemoteApiPropertyType.MethodReturningPromise + } +}; diff --git a/packages/core/package.json b/packages/core/package.json index 126bca1b59..cd125d2298 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -43,8 +43,8 @@ }, "dependencies": { "@ant-design/icons": "^4.7.0", - "@cardano-sdk/wallet": "0.44.14", - "@cardano-sdk/web-extension": "0.34.13", + "@cardano-sdk/wallet": "0.44.15", + "@cardano-sdk/web-extension": "0.34.14", "@input-output-hk/lace-ui-toolkit": "1.19.0", "@lace/cardano": "0.1.0", "@lace/common": "0.1.0", diff --git a/packages/nami/package.json b/packages/nami/package.json index 40b4ed3581..53b229150e 100644 --- a/packages/nami/package.json +++ b/packages/nami/package.json @@ -56,12 +56,13 @@ "watch": "yarn build --watch" }, "dependencies": { + "@biglup/is-cid": "^1.0.3", "@cardano-foundation/ledgerjs-hw-app-cardano": "^6.0.0", "@cardano-sdk/core": "0.41.2", "@cardano-sdk/crypto": "0.1.30", "@cardano-sdk/tx-construction": "0.21.10", "@cardano-sdk/util": "0.15.5", - "@cardano-sdk/web-extension": "0.34.13", + "@cardano-sdk/web-extension": "0.34.14", "@chakra-ui/css-reset": "1.0.0", "@chakra-ui/icons": "1.0.13", "@chakra-ui/react": "1.6.4", diff --git a/packages/nami/src/api/util.ts b/packages/nami/src/api/util.ts index b620ef9c5d..7da20b6523 100644 --- a/packages/nami/src/api/util.ts +++ b/packages/nami/src/api/util.ts @@ -3,6 +3,7 @@ /* eslint-disable max-params */ /* eslint-disable unicorn/no-null */ /* eslint-disable @typescript-eslint/naming-convention */ +import * as CidValidator from '@biglup/is-cid'; import { Serialization } from '@cardano-sdk/core'; import { minAdaRequired as minAdaRequiredSDK } from '@cardano-sdk/tx-construction'; import { crc8 } from 'crc'; @@ -32,6 +33,12 @@ export const convertMetadataPropToString = ( return null; }; +const looksLikeIpfsUrlWithoutProtocol = (uri: string) => { + const [cid] = uri.split('/'); + if (!cid) return false; + return CidValidator.isValid(cid); +}; + export const linkToSrc = (link: string, base64 = false) => { const base64regex = /^([\d+/A-Za-z]{4})*(([\d+/A-Za-z]{2}==)|([\d+/A-Za-z]{3}=))?$/; @@ -42,10 +49,7 @@ export const linkToSrc = (link: string, base64 = false) => { '/' + link.split('ipfs://')[1].split('ipfs/').slice(-1)[0] ); - else if ( - (link.startsWith('Qm') && link.length === 46) || - (link.startsWith('baf') && link.length === 59) - ) { + else if (looksLikeIpfsUrlWithoutProtocol(link)) { return provider.api.ipfs + '/' + link; } else if (base64 && base64regex.test(link)) return 'data:image/png;base64,' + link; diff --git a/packages/staking/package.json b/packages/staking/package.json index e467a9aead..0d40481fba 100644 --- a/packages/staking/package.json +++ b/packages/staking/package.json @@ -80,8 +80,8 @@ "@cardano-sdk/input-selection": "0.13.25", "@cardano-sdk/tx-construction": "0.21.10", "@cardano-sdk/util": "0.15.5", - "@cardano-sdk/wallet": "0.44.14", - "@cardano-sdk/web-extension": "0.34.13", + "@cardano-sdk/wallet": "0.44.15", + "@cardano-sdk/web-extension": "0.34.14", "@storybook/addon-actions": "^7.6.7", "@storybook/addon-essentials": "^7.6.7", "@storybook/addon-interactions": "^7.6.7", @@ -129,8 +129,8 @@ "@cardano-sdk/input-selection": "0.13.25", "@cardano-sdk/tx-construction": "0.21.10", "@cardano-sdk/util": "0.15.5", - "@cardano-sdk/wallet": "0.44.14", - "@cardano-sdk/web-extension": "0.34.13", + "@cardano-sdk/wallet": "0.44.15", + "@cardano-sdk/web-extension": "0.34.14", "@lace/cardano": "^0.1.0", "@lace/common": "^0.1.0", "@lace/core": "0.1.0", diff --git a/yarn.lock b/yarn.lock index 23c3c5fb81..a3983b0ed9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9074,9 +9074,9 @@ __metadata: languageName: node linkType: hard -"@cardano-sdk/cardano-services-client@npm:0.21.6": - version: 0.21.6 - resolution: "@cardano-sdk/cardano-services-client@npm:0.21.6" +"@cardano-sdk/cardano-services-client@npm:0.21.7": + version: 0.21.7 + resolution: "@cardano-sdk/cardano-services-client@npm:0.21.7" dependencies: "@cardano-sdk/core": ~0.41.2 "@cardano-sdk/util": ~0.15.5 @@ -9086,7 +9086,7 @@ __metadata: json-bigint: ~1.0.0 ts-log: ^2.2.4 ws: ^8.17.1 - checksum: 5317fc1379b2ece8f5120da7bf4b2adc0c458ca54c8e10de6e070900c7d93b2dcd0a8b480e0ad6e49b0edd7561358a3e2b433553a3545b2da32e43f79f58136e + checksum: f1cea57221eca3413377507d04efe4adc8439b7ed49166d56016b5a85c7043d2bc418060660c27014a5e6c382e2360236bf8ebf17dd3887d5a22cb562ff15978 languageName: node linkType: hard @@ -9234,15 +9234,15 @@ __metadata: languageName: node linkType: hard -"@cardano-sdk/ogmios@npm:~0.18.8": - version: 0.18.8 - resolution: "@cardano-sdk/ogmios@npm:0.18.8" +"@cardano-sdk/ogmios@npm:~0.18.9": + version: 0.18.9 + resolution: "@cardano-sdk/ogmios@npm:0.18.9" dependencies: "@cardano-ogmios/client": 6.5.0 "@cardano-ogmios/schema": 6.5.0 "@cardano-sdk/core": ~0.41.2 "@cardano-sdk/crypto": ~0.1.30 - "@cardano-sdk/projection": ~0.12.8 + "@cardano-sdk/projection": ~0.12.9 "@cardano-sdk/util": ~0.15.5 backoff-rxjs: ^7.0.0 buffer: 5.7.1 @@ -9251,17 +9251,17 @@ __metadata: nanoid: ^3.1.31 rxjs: ^7.4.0 ts-log: ^2.2.3 - checksum: d316f38349b9958dd3e40a7b9347f914577b4a425eff4a03e86e52f70613ca835b03bd8ce7ca25191f5fdb2e41acb2de71685a387ac9c8c444a0a73541108620 + checksum: 8da911c56f71ad6675c665bb939e9a148f723c7b2f3c90297d3a913e7f52637cd752cf7493a04ca190a8fcbec9e42f6ffd151f5789c6765ff8b4ab816edef727 languageName: node linkType: hard -"@cardano-sdk/projection@npm:~0.12.8": - version: 0.12.8 - resolution: "@cardano-sdk/projection@npm:0.12.8" +"@cardano-sdk/projection@npm:~0.12.9": + version: 0.12.9 + resolution: "@cardano-sdk/projection@npm:0.12.9" dependencies: "@cardano-sdk/core": ~0.41.2 "@cardano-sdk/crypto": ~0.1.30 - "@cardano-sdk/ogmios": ~0.18.8 + "@cardano-sdk/ogmios": ~0.18.9 "@cardano-sdk/util": ~0.15.5 "@cardano-sdk/util-rxjs": ~0.7.38 lodash: ^4.17.21 @@ -9269,7 +9269,7 @@ __metadata: ts-custom-error: ^3.2.0 ts-log: ^2.2.4 tsc-alias: ^1.8.10 - checksum: 9d2bf0dbba4e48a4c2091eec63905fdb457e074ecb75e462ddbaf1b9420367b057ac0c2c7374aa91ef73c6b5abfd65a7fba198f721a4217420639bffe4ae9c0b + checksum: a0d4e3cb28ca9d6e1711772295fc364590482073c47ec8f99a935da133dd978bb23c5860099057545440870c73092759ce413c04bb2551ceb6e27bf2b0a50358 languageName: node linkType: hard @@ -9292,14 +9292,14 @@ __metadata: languageName: node linkType: hard -"@cardano-sdk/util-dev@npm:0.23.8": - version: 0.23.8 - resolution: "@cardano-sdk/util-dev@npm:0.23.8" +"@cardano-sdk/util-dev@npm:0.23.9": + version: 0.23.9 + resolution: "@cardano-sdk/util-dev@npm:0.23.9" dependencies: "@cardano-sdk/core": ~0.41.2 "@cardano-sdk/crypto": ~0.1.30 "@cardano-sdk/key-management": ~0.24.8 - "@cardano-sdk/projection": ~0.12.8 + "@cardano-sdk/projection": ~0.12.9 "@cardano-sdk/util": ~0.15.5 "@types/dockerode": ^3.3.8 axios: ^1.7.4 @@ -9313,7 +9313,7 @@ __metadata: lodash: ^4.17.21 rxjs: ^7.4.0 ts-log: ^2.2.4 - checksum: f3b2f73271688561def6643aae6d3bd87b94dbe6988d098a7ad889be67c0e77aaf3c38a428b0a23864e52aae4fc57ea6be73c4b451a23a0b28b3bb67cd038197 + checksum: 16f9d4e8d4d5e93d007aaeeaf8e4469b9a3c9189ad19f897b40d34dd9e2d5191f8b8a38ff48991500cbfdbcf5fc5cbb0bf49a5e30d08a4e40f085bbcad1d166c languageName: node linkType: hard @@ -9342,9 +9342,9 @@ __metadata: languageName: node linkType: hard -"@cardano-sdk/wallet@npm:0.44.14, @cardano-sdk/wallet@npm:~0.44.14": - version: 0.44.14 - resolution: "@cardano-sdk/wallet@npm:0.44.14" +"@cardano-sdk/wallet@npm:0.44.15, @cardano-sdk/wallet@npm:~0.44.15": + version: 0.44.15 + resolution: "@cardano-sdk/wallet@npm:0.44.15" dependencies: "@cardano-sdk/core": ~0.41.2 "@cardano-sdk/crypto": ~0.1.30 @@ -9366,13 +9366,13 @@ __metadata: ts-custom-error: ^3.2.0 ts-log: ^2.2.3 uuid: ^8.3.2 - checksum: f2700074ed812ac0e8f178343d926fd94abd7a2873fb46fa13db1d38df50e531aff438841268a63cefe0acb55937adef6b1e9c9829c9f54f822ae9d7f9143f2a + checksum: 2cf459a538bf5b49450904a9105988f420191eff3283c4e377be5aecb280337557d1622eff7c2f5b60c68b09c93b1771e57ea230bd7263e749fbe3d12c48ba7f languageName: node linkType: hard -"@cardano-sdk/web-extension@npm:0.34.13": - version: 0.34.13 - resolution: "@cardano-sdk/web-extension@npm:0.34.13" +"@cardano-sdk/web-extension@npm:0.34.14": + version: 0.34.14 + resolution: "@cardano-sdk/web-extension@npm:0.34.14" dependencies: "@cardano-sdk/core": ~0.41.2 "@cardano-sdk/crypto": ~0.1.30 @@ -9383,7 +9383,7 @@ __metadata: "@cardano-sdk/tx-construction": ~0.21.10 "@cardano-sdk/util": ~0.15.5 "@cardano-sdk/util-rxjs": ~0.7.38 - "@cardano-sdk/wallet": ~0.44.14 + "@cardano-sdk/wallet": ~0.44.15 backoff-rxjs: ^7.0.0 lodash: ^4.17.21 rxjs: ^7.4.0 @@ -9391,7 +9391,7 @@ __metadata: ts-log: ^2.2.3 uuid: ^8.3.2 webextension-polyfill: ^0.8.0 - checksum: 55c930dee9bfd26e08012a3658fe56d84b24043cfda4862309e3b0ef32fb6399ddd6aad09a1bffdc632937333d45f8f36f08e326af537309e8f54c0f9fb3c8b6 + checksum: ceab19ba54647d06d05cf6a558e0d7fbf66bacd11b571a3f604ab0d20249354c01a87b9e75c98efcbba242fd04c69bfdd565b06aef5bce27a13599ea598ebdfc languageName: node linkType: hard @@ -13450,7 +13450,7 @@ __metadata: resolution: "@lace/browser-extension-wallet@workspace:apps/browser-extension-wallet" dependencies: "@ant-design/icons": ^4.7.0 - "@cardano-sdk/cardano-services-client": 0.21.6 + "@cardano-sdk/cardano-services-client": 0.21.7 "@cardano-sdk/core": 0.41.2 "@cardano-sdk/dapp-connector": 0.12.42 "@cardano-sdk/hardware-ledger": 0.12.10 @@ -13458,8 +13458,8 @@ __metadata: "@cardano-sdk/tx-construction": 0.21.10 "@cardano-sdk/util": 0.15.5 "@cardano-sdk/util-rxjs": 0.7.38 - "@cardano-sdk/wallet": 0.44.14 - "@cardano-sdk/web-extension": 0.34.13 + "@cardano-sdk/wallet": 0.44.15 + "@cardano-sdk/web-extension": 0.34.14 "@emurgo/cardano-message-signing-asmjs": 1.0.1 "@emurgo/cip14-js": ~3.0.1 "@input-output-hk/lace-ui-toolkit": 1.21.0 @@ -13536,7 +13536,7 @@ __metadata: resolution: "@lace/cardano@workspace:packages/cardano" dependencies: "@blockfrost/blockfrost-js": ^5.5.0 - "@cardano-sdk/cardano-services-client": 0.21.6 + "@cardano-sdk/cardano-services-client": 0.21.7 "@cardano-sdk/core": 0.41.2 "@cardano-sdk/crypto": 0.1.30 "@cardano-sdk/hardware-ledger": 0.12.10 @@ -13544,9 +13544,9 @@ __metadata: "@cardano-sdk/key-management": 0.24.8 "@cardano-sdk/tx-construction": 0.21.10 "@cardano-sdk/util": 0.15.5 - "@cardano-sdk/util-dev": 0.23.8 - "@cardano-sdk/wallet": 0.44.14 - "@cardano-sdk/web-extension": 0.34.13 + "@cardano-sdk/util-dev": 0.23.9 + "@cardano-sdk/wallet": 0.44.15 + "@cardano-sdk/web-extension": 0.34.14 "@emurgo/cardano-message-signing-browser": 1.0.1 "@lace/common": 0.1.0 "@ledgerhq/devices": ^8.2.1 @@ -13611,8 +13611,8 @@ __metadata: "@babel/preset-env": ^7.22.20 "@babel/preset-react": ^7.22.15 "@babel/preset-typescript": ^7.22.15 - "@cardano-sdk/wallet": 0.44.14 - "@cardano-sdk/web-extension": 0.34.13 + "@cardano-sdk/wallet": 0.44.15 + "@cardano-sdk/web-extension": 0.34.14 "@input-output-hk/lace-ui-toolkit": 1.19.0 "@lace/cardano": 0.1.0 "@lace/common": 0.1.0 @@ -13706,12 +13706,13 @@ __metadata: version: 0.0.0-use.local resolution: "@lace/nami@workspace:packages/nami" dependencies: + "@biglup/is-cid": ^1.0.3 "@cardano-foundation/ledgerjs-hw-app-cardano": ^6.0.0 "@cardano-sdk/core": 0.41.2 "@cardano-sdk/crypto": 0.1.30 "@cardano-sdk/tx-construction": 0.21.10 "@cardano-sdk/util": 0.15.5 - "@cardano-sdk/web-extension": 0.34.13 + "@cardano-sdk/web-extension": 0.34.14 "@chakra-ui/css-reset": 1.0.0 "@chakra-ui/icons": 1.0.13 "@chakra-ui/react": 1.6.4 @@ -13794,8 +13795,8 @@ __metadata: "@cardano-sdk/input-selection": 0.13.25 "@cardano-sdk/tx-construction": 0.21.10 "@cardano-sdk/util": 0.15.5 - "@cardano-sdk/wallet": 0.44.14 - "@cardano-sdk/web-extension": 0.34.13 + "@cardano-sdk/wallet": 0.44.15 + "@cardano-sdk/web-extension": 0.34.14 "@input-output-hk/lace-ui-toolkit": 1.19.0 "@lace/cardano": ^0.1.0 "@lace/common": ^0.1.0 @@ -13863,8 +13864,8 @@ __metadata: "@cardano-sdk/input-selection": 0.13.25 "@cardano-sdk/tx-construction": 0.21.10 "@cardano-sdk/util": 0.15.5 - "@cardano-sdk/wallet": 0.44.14 - "@cardano-sdk/web-extension": 0.34.13 + "@cardano-sdk/wallet": 0.44.15 + "@cardano-sdk/web-extension": 0.34.14 "@lace/cardano": ^0.1.0 "@lace/common": ^0.1.0 "@lace/core": 0.1.0