Skip to content

Commit 63caeeb

Browse files
committed
Fixed lucid instance
1 parent 03cbe4e commit 63caeeb

6 files changed

Lines changed: 36 additions & 10 deletions

File tree

src/chains/cardano/cardano.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,24 @@ export class Cardano {
6969

7070
if (!Cardano._instances[network]) {
7171
const instance = new Cardano(network);
72-
await instance.init();
72+
73+
if (
74+
instance.projectId &&
75+
instance.projectId.toLowerCase().startsWith(network.toLowerCase())
76+
) {
77+
try {
78+
await instance.init();
79+
} catch (err: any) {
80+
logger.warn(
81+
`[Cardano] initial init() skipped for network="${network}": ${err.message}`,
82+
);
83+
}
84+
} else {
85+
logger.info(
86+
`[Cardano] skipped init() for network="${network}" because projectId is still placeholder`,
87+
);
88+
}
89+
7390
Cardano._instances[network] = instance;
7491
}
7592

src/chains/cardano/routes/balances.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ export const balancesRoute: FastifyPluginAsync = async (fastify) => {
146146
// Get first wallet address for example
147147
const cardano = await Cardano.getInstance('preprod');
148148

149-
// Default Ethereum address for examples if no wallet is available
149+
// Default Cardano address for examples if no wallet is available
150150
let firstWalletAddress = '';
151151

152152
try {
153-
// Try to get user's first Ethereum wallet if available
154-
// getFirstWalletAddress specifically looks in the /ethereum directory
153+
// Try to get user's first Cardano wallet if available
154+
// getFirstWalletAddress specifically looks in the /cardano directory
155155
const userWallet = await cardano.getFirstWalletAddress();
156156
if (userWallet) {
157157
// Make sure it's a valid Cardano address
@@ -166,7 +166,7 @@ export const balancesRoute: FastifyPluginAsync = async (fastify) => {
166166
}
167167
}
168168
} catch (error) {
169-
logger.warn('No Ethereum wallets found for examples in schema');
169+
logger.warn('No Cardano wallets found for examples in schema');
170170
}
171171

172172
BalanceRequestSchema.properties.address.examples = [firstWalletAddress];

src/config/routes/updateConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ConfigUpdateResponseSchema,
1010
} from '../schemas';
1111
import { updateConfig } from '../utils';
12+
import { Cardano } from '../../chains/cardano/cardano';
1213

1314
export const updateConfigRoute: FastifyPluginAsync = async (fastify) => {
1415
fastify.post<{ Body: ConfigUpdateRequest; Reply: ConfigUpdateResponse }>(
@@ -84,6 +85,14 @@ export const updateConfigRoute: FastifyPluginAsync = async (fastify) => {
8485

8586
// Build descriptive message
8687
const description = `'${namespace}.${path}'`;
88+
// If they updated the projectId for one of the Cardano networks:
89+
if (configPath.startsWith('cardano.') && configPath.endsWith('.projectId')) {
90+
const network = configPath.split('.')[2]; // e.g. 'preprod || mainnet || preview'
91+
console.log('network', network);
92+
const cardano = await Cardano.getInstance(network);
93+
cardano.projectId = String(processedValue); // assign the new key as string
94+
await cardano.init(); // re‐init Lucid on the fly
95+
}
8796

8897
return {
8998
message: `Configuration updated successfully: ${description} set to ${JSON.stringify(processedValue)}`,

src/connectors/minswap/amm-routes/removeLiquidity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const removeLiquidityRoute: FastifyPluginAsync = async (fastify) => {
6868
);
6969
}
7070

71-
// Get Uniswap and Ethereum instances
71+
// Get Minswap and Cardano instances
7272
const minswap = await Minswap.getInstance(networkToUse);
7373

7474
// Get wallet address - either from request or first available

src/connectors/sundaeswap/amm-routes/removeLiquidity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const removeLiquidityRoute: FastifyPluginAsync = async (fastify) => {
7676
);
7777
}
7878

79-
// Get Uniswap and Ethereum instances
79+
// Get Sundaeswap and Cardano instances
8080
const sundaeswap = await Sundaeswap.getInstance(networkToUse);
8181

8282
// Get wallet address - either from request or first available

src/templates/chains/cardano.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ networks:
44
tokenListSource: "/home/gateway/conf/lists/cardano_mainnet_tokens.json"
55
nativeCurrencySymbol: 'ADA'
66
apiurl: 'https://cardano-mainnet.blockfrost.io/api/v0'
7-
projectId: 'your_mainnet_api_key'
7+
projectId: 'your_api_key'
88
preprod:
99
tokenListType: "FILE"
1010
tokenListSource: "/home/gateway/conf/lists/cardano_preprod_tokens.json"
1111
nativeCurrencySymbol: 'ADA'
1212
apiurl: 'https://cardano-preprod.blockfrost.io/api/v0'
13-
projectId: 'your_preprod_api_key'
13+
projectId: 'your_api_key'
1414
preview:
1515
tokenListType: "FILE"
1616
tokenListSource: "/home/gateway/conf/lists/cardano_preview_tokens.json"
1717
nativeCurrencySymbol: 'ADA'
1818
apiurl: 'https://cardano-preview.blockfrost.io/api/v0'
19-
projectId: 'your_preview_api_key'
19+
projectId: 'your_api_key'
2020

0 commit comments

Comments
 (0)