fixes
This commit is contained in:
parent
0ce149bf89
commit
04160a2fd2
1
api-tutorials/web/node/wren-api-tutorial
Submodule
1
api-tutorials/web/node/wren-api-tutorial
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit a73b96c463b92b02beb8772d0436b653a5e1404c
|
||||||
1
api-tutorials/web/wren-api-tutorial-web
Submodule
1
api-tutorials/web/wren-api-tutorial-web
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit cc08200ca6314cf8940a80725cbdf34fdedfa304
|
||||||
@ -52,7 +52,8 @@ const createApiClient = () => {
|
|||||||
console.log('[wrenClient] Creating API client with key:', config.wrenApiKey ? '********' + config.wrenApiKey.slice(-4) : 'MISSING');
|
console.log('[wrenClient] Creating API client with key:', config.wrenApiKey ? '********' + config.wrenApiKey.slice(-4) : 'MISSING');
|
||||||
|
|
||||||
const client = axios.create({
|
const client = axios.create({
|
||||||
baseURL: 'https://api.wren.co/v1',
|
// Updated base URL to match the sample code
|
||||||
|
baseURL: 'https://www.wren.co/api',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${config.wrenApiKey}`,
|
'Authorization': `Bearer ${config.wrenApiKey}`,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -139,16 +140,11 @@ export async function getPortfolios(): Promise<Portfolio[]> {
|
|||||||
return response.data.portfolios.map((portfolio: any) => {
|
return response.data.portfolios.map((portfolio: any) => {
|
||||||
let pricePerTon = 200; // Default price
|
let pricePerTon = 200; // Default price
|
||||||
|
|
||||||
if (portfolio.price_per_ton !== undefined && portfolio.price_per_ton !== null) {
|
// Check for both pricePerTon and costPerTon as the API might use different formats
|
||||||
const rawPrice = portfolio.price_per_ton;
|
if (portfolio.pricePerTon !== undefined && portfolio.pricePerTon !== null) {
|
||||||
if (typeof rawPrice === 'number') {
|
pricePerTon = typeof portfolio.pricePerTon === 'number' ? portfolio.pricePerTon : parseFloat(portfolio.pricePerTon) || 200;
|
||||||
pricePerTon = rawPrice;
|
} else if (portfolio.costPerTon !== undefined && portfolio.costPerTon !== null) {
|
||||||
} else if (typeof rawPrice === 'string') {
|
pricePerTon = typeof portfolio.costPerTon === 'number' ? portfolio.costPerTon : parseFloat(portfolio.costPerTon) || 200;
|
||||||
const parsed = parseFloat(rawPrice);
|
|
||||||
if (!isNaN(parsed)) {
|
|
||||||
pricePerTon = parsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -181,25 +177,29 @@ export async function createOffsetOrder(
|
|||||||
console.log(`[wrenClient] Creating offset order: portfolio=${portfolioId}, tons=${tons}`);
|
console.log(`[wrenClient] Creating offset order: portfolio=${portfolioId}, tons=${tons}`);
|
||||||
|
|
||||||
const api = createApiClient();
|
const api = createApiClient();
|
||||||
const response = await api.post('/orders', {
|
// Updated to use the correct endpoint and parameter names
|
||||||
portfolio_id: portfolioId,
|
const response = await api.post('/offset-orders', {
|
||||||
|
portfolioId,
|
||||||
tons,
|
tons,
|
||||||
dry_run: dryRun,
|
dryRun,
|
||||||
currency: 'USD'
|
currency: 'USD'
|
||||||
});
|
});
|
||||||
|
|
||||||
const order = response.data;
|
const order = response.data;
|
||||||
|
|
||||||
|
// Updated to handle costPerTon vs pricePerTon
|
||||||
let pricePerTon = 200;
|
let pricePerTon = 200;
|
||||||
if (order.portfolio?.price_per_ton !== undefined && order.portfolio.price_per_ton !== null) {
|
if (order.portfolio?.pricePerTon !== undefined && order.portfolio.pricePerTon !== null) {
|
||||||
const rawPrice = order.portfolio.price_per_ton;
|
pricePerTon = typeof order.portfolio.pricePerTon === 'number' ? order.portfolio.pricePerTon : parseFloat(order.portfolio.pricePerTon) || 200;
|
||||||
pricePerTon = typeof rawPrice === 'number' ? rawPrice : parseFloat(rawPrice) || 200;
|
} else if (order.portfolio?.costPerTon !== undefined && order.portfolio.costPerTon !== null) {
|
||||||
|
pricePerTon = typeof order.portfolio.costPerTon === 'number' ? order.portfolio.costPerTon : parseFloat(order.portfolio.costPerTon) || 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjusted to use camelCase as per API response
|
||||||
return {
|
return {
|
||||||
id: order.id,
|
id: order.id,
|
||||||
amountCharged: order.amount_charged,
|
amountCharged: order.amountCharged,
|
||||||
currency: 'USD',
|
currency: order.currency || 'USD',
|
||||||
tons: order.tons,
|
tons: order.tons,
|
||||||
portfolio: {
|
portfolio: {
|
||||||
id: order.portfolio.id,
|
id: order.portfolio.id,
|
||||||
@ -207,11 +207,11 @@ export async function createOffsetOrder(
|
|||||||
description: order.portfolio.description || '',
|
description: order.portfolio.description || '',
|
||||||
projects: order.portfolio.projects || [],
|
projects: order.portfolio.projects || [],
|
||||||
pricePerTon,
|
pricePerTon,
|
||||||
currency: 'USD'
|
currency: order.currency || 'USD'
|
||||||
},
|
},
|
||||||
status: order.status,
|
status: order.status,
|
||||||
createdAt: order.created_at,
|
createdAt: order.createdAt || order.created_at,
|
||||||
dryRun: order.dry_run
|
dryRun: order.dryRun
|
||||||
};
|
};
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
logError(error);
|
logError(error);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user