Skip to content

Commit

Permalink
feat: add remaining blockfrost provider experiments (#1595)
Browse files Browse the repository at this point in the history
* chore: bump cardano-js-sdk

* feat: add remaining blockfrost provider experiments

- chain history
- network info
- rewards
- tx submit
- utxo
  • Loading branch information
mkazlauskas authored Jan 3, 2025
1 parent d10316d commit 079d93d
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 70 deletions.
6 changes: 3 additions & 3 deletions apps/browser-extension-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@cardano-sdk/cardano-services-client": "0.23.2",
"@cardano-sdk/cardano-services-client": "0.23.3",
"@cardano-sdk/core": "0.42.1",
"@cardano-sdk/dapp-connector": "0.12.47",
"@cardano-sdk/input-selection": "0.13.31",
"@cardano-sdk/tx-construction": "0.23.0",
"@cardano-sdk/util": "0.15.5",
"@cardano-sdk/util-rxjs": "0.8.0",
"@cardano-sdk/wallet": "0.46.2",
"@cardano-sdk/web-extension": "0.36.1",
"@cardano-sdk/wallet": "0.46.3",
"@cardano-sdk/web-extension": "0.36.2",
"@emurgo/cip14-js": "~3.0.1",
"@input-output-hk/lace-ui-toolkit": "1.21.0",
"@lace/cardano": "0.1.0",
Expand Down
17 changes: 11 additions & 6 deletions apps/browser-extension-wallet/src/lib/scripts/background/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export const getProviders = async (chainName: Wallet.ChainName): Promise<Wallet.
const baseCardanoServicesUrl = getBaseUrlForChain(chainName);
const magic = getMagicForChain(chainName);
const { customSubmitTxUrl, featureFlags } = await getBackgroundStorage();
const useWebSocket = !!(featureFlags?.[magic]?.[ExperimentName.WEBSOCKET_API] ?? false);
const useBlockfrostAssetProvider = !!(featureFlags?.[magic]?.[ExperimentName.BLOCKFROST_ASSET_PROVIDER] ?? false);
const useDrepProviderOverrideActiveStatus = !!(
featureFlags?.[magic]?.[ExperimentName.USE_DREP_PROVIDER_OVERRIDE] ?? false
);
const isExperimentEnabled = (experimentName: ExperimentName) => !!(featureFlags?.[magic]?.[experimentName] ?? false);

return Wallet.createProviders({
axiosAdapter: axiosFetchAdapter,
Expand All @@ -61,7 +57,16 @@ export const getProviders = async (chainName: Wallet.ChainName): Promise<Wallet.
}
},
logger,
experiments: { useWebSocket, useBlockfrostAssetProvider, useDrepProviderOverrideActiveStatus }
experiments: {
useDrepProviderOverrideActiveStatus: isExperimentEnabled(ExperimentName.USE_DREP_PROVIDER_OVERRIDE),
useWebSocket: isExperimentEnabled(ExperimentName.WEBSOCKET_API),
useBlockfrostAssetProvider: isExperimentEnabled(ExperimentName.BLOCKFROST_ASSET_PROVIDER),
useBlockfrostChainHistoryProvider: isExperimentEnabled(ExperimentName.BLOCKFROST_CHAIN_HISTORY_PROVIDER),
useBlockfrostNetworkInfoProvider: isExperimentEnabled(ExperimentName.BLOCKFROST_NETWORK_INFO_PROVIDER),
useBlockfrostRewardsProvider: isExperimentEnabled(ExperimentName.BLOCKFROST_REWARDS_PROVIDER),
useBlockfrostTxSubmitProvider: isExperimentEnabled(ExperimentName.BLOCKFROST_TX_SUBMIT_PROVIDER),
useBlockfrostUtxoProvider: isExperimentEnabled(ExperimentName.BLOCKFROST_UTXO_PROVIDER)
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export const getDefaultFeatureFlags = (): FallbackConfiguration => ({
[ExperimentName.SHARED_WALLETS]: false,
[ExperimentName.WEBSOCKET_API]: false,
[ExperimentName.BLOCKFROST_ASSET_PROVIDER]: false,
[ExperimentName.BLOCKFROST_CHAIN_HISTORY_PROVIDER]: false,
[ExperimentName.BLOCKFROST_NETWORK_INFO_PROVIDER]: false,
[ExperimentName.BLOCKFROST_REWARDS_PROVIDER]: false,
[ExperimentName.BLOCKFROST_TX_SUBMIT_PROVIDER]: false,
[ExperimentName.BLOCKFROST_UTXO_PROVIDER]: false,
[ExperimentName.EXTENSION_STORAGE]: false,
[ExperimentName.USE_DREP_PROVIDER_OVERRIDE]: false
});
Expand Down Expand Up @@ -36,6 +41,26 @@ export const experiments: ExperimentsConfig = {
value: false,
default: false
},
[ExperimentName.BLOCKFROST_CHAIN_HISTORY_PROVIDER]: {
value: false,
default: false
},
[ExperimentName.BLOCKFROST_NETWORK_INFO_PROVIDER]: {
value: false,
default: false
},
[ExperimentName.BLOCKFROST_REWARDS_PROVIDER]: {
value: false,
default: false
},
[ExperimentName.BLOCKFROST_TX_SUBMIT_PROVIDER]: {
value: false,
default: false
},
[ExperimentName.BLOCKFROST_UTXO_PROVIDER]: {
value: false,
default: false
},
[ExperimentName.EXTENSION_STORAGE]: {
value: false,
default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export enum ExperimentName {
SHARED_WALLETS = 'shared-wallets',
WEBSOCKET_API = 'websocket-api',
BLOCKFROST_ASSET_PROVIDER = 'blockfrost-asset-provider',
BLOCKFROST_CHAIN_HISTORY_PROVIDER = 'blockfrost-chain-history-provider',
BLOCKFROST_NETWORK_INFO_PROVIDER = 'blockfrost-network-info-provider',
BLOCKFROST_REWARDS_PROVIDER = 'blockfrost-rewards-provider',
BLOCKFROST_TX_SUBMIT_PROVIDER = 'blockfrost-tx-submit-provider',
BLOCKFROST_UTXO_PROVIDER = 'blockfrost-utxo-provider',
EXTENSION_STORAGE = 'extension-storage',
USE_DREP_PROVIDER_OVERRIDE = 'use-drep-provider-override'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type FeatureFlag =
| 'use-switch-to-nami-mode'
| 'websocket-api'
| ExperimentName.BLOCKFROST_ASSET_PROVIDER
| ExperimentName.BLOCKFROST_CHAIN_HISTORY_PROVIDER
| ExperimentName.BLOCKFROST_NETWORK_INFO_PROVIDER
| ExperimentName.BLOCKFROST_REWARDS_PROVIDER
| ExperimentName.BLOCKFROST_TX_SUBMIT_PROVIDER
| ExperimentName.BLOCKFROST_UTXO_PROVIDER
| ExperimentName.EXTENSION_STORAGE
| ExperimentName.USE_DREP_PROVIDER_OVERRIDE;

Expand Down
8 changes: 4 additions & 4 deletions packages/cardano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
"watch": "yarn build --watch"
},
"dependencies": {
"@cardano-sdk/cardano-services-client": "0.23.2",
"@cardano-sdk/cardano-services-client": "0.23.3",
"@cardano-sdk/core": "0.42.1",
"@cardano-sdk/crypto": "0.1.32",
"@cardano-sdk/hardware-ledger": "0.12.16",
"@cardano-sdk/hardware-trezor": "0.6.15",
"@cardano-sdk/key-management": "0.24.13",
"@cardano-sdk/tx-construction": "0.23.0",
"@cardano-sdk/util": "0.15.5",
"@cardano-sdk/wallet": "0.46.2",
"@cardano-sdk/web-extension": "0.36.1",
"@cardano-sdk/wallet": "0.46.3",
"@cardano-sdk/web-extension": "0.36.2",
"@lace/common": "0.1.0",
"@ledgerhq/devices": "^8.4.4",
"@stablelib/chacha20poly1305": "1.0.1",
Expand All @@ -73,7 +73,7 @@
},
"devDependencies": {
"@blockfrost/blockfrost-js": "^5.5.0",
"@cardano-sdk/util-dev": "0.24.1",
"@cardano-sdk/util-dev": "0.24.2",
"@emurgo/cardano-message-signing-browser": "1.0.1",
"@types/webextension-polyfill": "0.10.0",
"axios": "^1.7.4",
Expand Down
48 changes: 40 additions & 8 deletions packages/cardano/src/wallet/lib/providers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-new */
/* eslint-disable no-new, complexity, sonarjs/cognitive-complexity */
import { WalletProvidersDependencies } from '@src/wallet';
import { AxiosAdapter } from 'axios';
import { Logger } from 'ts-log';
Expand Down Expand Up @@ -32,7 +32,12 @@ import {
RateLimiter,
BlockfrostClient,
BlockfrostAssetProvider,
BlockfrostDRepProvider
BlockfrostChainHistoryProvider,
BlockfrostDRepProvider,
BlockfrostUtxoProvider,
BlockfrostRewardsProvider,
BlockfrostTxSubmitProvider,
BlockfrostNetworkInfoProvider
} from '@cardano-sdk/cardano-services-client';
import { RemoteApiProperties, RemoteApiPropertyType } from '@cardano-sdk/web-extension';

Expand Down Expand Up @@ -83,6 +88,11 @@ export interface ProvidersConfig {
useWebSocket?: boolean;
useBlockfrostAssetProvider?: boolean;
useDrepProviderOverrideActiveStatus?: boolean;
useBlockfrostChainHistoryProvider?: boolean;
useBlockfrostNetworkInfoProvider?: boolean;
useBlockfrostRewardsProvider?: boolean;
useBlockfrostTxSubmitProvider?: boolean;
useBlockfrostUtxoProvider?: boolean;
};
}

Expand All @@ -96,7 +106,16 @@ export const createProviders = ({
axiosAdapter,
env: { baseCardanoServicesUrl: baseUrl, customSubmitTxUrl, blockfrostConfig },
logger,
experiments: { useBlockfrostAssetProvider, useWebSocket, useDrepProviderOverrideActiveStatus }
experiments: {
useBlockfrostAssetProvider,
useBlockfrostChainHistoryProvider,
useBlockfrostNetworkInfoProvider,
useBlockfrostRewardsProvider,
useBlockfrostTxSubmitProvider,
useBlockfrostUtxoProvider,
useDrepProviderOverrideActiveStatus,
useWebSocket
}
}: ProvidersConfig): WalletProvidersDependencies => {
if (!logger) logger = console;

Expand All @@ -108,10 +127,19 @@ export const createProviders = ({
const assetProvider = useBlockfrostAssetProvider
? new BlockfrostAssetProvider(blockfrostClient, logger)
: assetInfoHttpProvider(httpProviderConfig);
const chainHistoryProvider = chainHistoryHttpProvider(httpProviderConfig);
const rewardsProvider = rewardsHttpProvider(httpProviderConfig);
const networkInfoProvider = useBlockfrostNetworkInfoProvider
? new BlockfrostNetworkInfoProvider(blockfrostClient, logger)
: networkInfoHttpProvider(httpProviderConfig);
const chainHistoryProvider = useBlockfrostChainHistoryProvider
? new BlockfrostChainHistoryProvider(blockfrostClient, networkInfoProvider, logger)
: chainHistoryHttpProvider(httpProviderConfig);
const rewardsProvider = useBlockfrostRewardsProvider
? new BlockfrostRewardsProvider(blockfrostClient, logger)
: rewardsHttpProvider(httpProviderConfig);
const stakePoolProvider = stakePoolHttpProvider(httpProviderConfig);
const txSubmitProvider = createTxSubmitProvider(httpProviderConfig, customSubmitTxUrl);
const txSubmitProvider = useBlockfrostTxSubmitProvider
? new BlockfrostTxSubmitProvider(blockfrostClient, logger)
: createTxSubmitProvider(httpProviderConfig, customSubmitTxUrl);
const drepProvider = new BlockfrostDRepProvider(blockfrostClient, logger);

// Temporary proxy for drepProvider to overwrite the 'active' property to always be true
Expand Down Expand Up @@ -167,12 +195,16 @@ export const createProviders = ({
};
}

const utxoProvider = useBlockfrostUtxoProvider
? new BlockfrostUtxoProvider(blockfrostClient, logger)
: utxoHttpProvider(httpProviderConfig);

return {
assetProvider,
networkInfoProvider: networkInfoHttpProvider(httpProviderConfig),
networkInfoProvider,
txSubmitProvider,
stakePoolProvider,
utxoProvider: utxoHttpProvider(httpProviderConfig),
utxoProvider,
chainHistoryProvider,
rewardsProvider,
drepProvider: useDrepProviderOverrideActiveStatus ? drepProviderOverrideActiveStatus : drepProvider
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@cardano-sdk/wallet": "0.46.2",
"@cardano-sdk/web-extension": "0.36.1",
"@cardano-sdk/wallet": "0.46.3",
"@cardano-sdk/web-extension": "0.36.2",
"@input-output-hk/lace-ui-toolkit": "1.19.0",
"@lace/cardano": "0.1.0",
"@lace/common": "0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/nami/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@cardano-sdk/crypto": "0.1.32",
"@cardano-sdk/tx-construction": "0.23.0",
"@cardano-sdk/util": "0.15.5",
"@cardano-sdk/web-extension": "0.36.1",
"@cardano-sdk/web-extension": "0.36.2",
"@chakra-ui/css-reset": "1.0.0",
"@chakra-ui/icons": "1.0.13",
"@chakra-ui/react": "1.6.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
"@cardano-sdk/input-selection": "0.13.31",
"@cardano-sdk/tx-construction": "0.23.0",
"@cardano-sdk/util": "0.15.5",
"@cardano-sdk/wallet": "0.46.2",
"@cardano-sdk/web-extension": "0.36.1",
"@cardano-sdk/wallet": "0.46.3",
"@cardano-sdk/web-extension": "0.36.2",
"@storybook/addon-actions": "^7.6.7",
"@storybook/addon-essentials": "^7.6.7",
"@storybook/addon-interactions": "^7.6.7",
Expand Down Expand Up @@ -129,8 +129,8 @@
"@cardano-sdk/input-selection": "0.13.31",
"@cardano-sdk/tx-construction": "0.23.0",
"@cardano-sdk/util": "0.15.5",
"@cardano-sdk/wallet": "0.46.2",
"@cardano-sdk/web-extension": "0.36.1",
"@cardano-sdk/wallet": "0.46.3",
"@cardano-sdk/web-extension": "0.36.2",
"@lace/cardano": "^0.1.0",
"@lace/common": "^0.1.0",
"@lace/core": "0.1.0",
Expand Down
Loading

0 comments on commit 079d93d

Please sign in to comment.