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');
|
||||
|
||||
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: {
|
||||
'Authorization': `Bearer ${config.wrenApiKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
@ -139,16 +140,11 @@ export async function getPortfolios(): Promise<Portfolio[]> {
|
||||
return response.data.portfolios.map((portfolio: any) => {
|
||||
let pricePerTon = 200; // Default price
|
||||
|
||||
if (portfolio.price_per_ton !== undefined && portfolio.price_per_ton !== null) {
|
||||
const rawPrice = portfolio.price_per_ton;
|
||||
if (typeof rawPrice === 'number') {
|
||||
pricePerTon = rawPrice;
|
||||
} else if (typeof rawPrice === 'string') {
|
||||
const parsed = parseFloat(rawPrice);
|
||||
if (!isNaN(parsed)) {
|
||||
pricePerTon = parsed;
|
||||
}
|
||||
}
|
||||
// Check for both pricePerTon and costPerTon as the API might use different formats
|
||||
if (portfolio.pricePerTon !== undefined && portfolio.pricePerTon !== null) {
|
||||
pricePerTon = typeof portfolio.pricePerTon === 'number' ? portfolio.pricePerTon : parseFloat(portfolio.pricePerTon) || 200;
|
||||
} else if (portfolio.costPerTon !== undefined && portfolio.costPerTon !== null) {
|
||||
pricePerTon = typeof portfolio.costPerTon === 'number' ? portfolio.costPerTon : parseFloat(portfolio.costPerTon) || 200;
|
||||
}
|
||||
|
||||
return {
|
||||
@ -181,25 +177,29 @@ export async function createOffsetOrder(
|
||||
console.log(`[wrenClient] Creating offset order: portfolio=${portfolioId}, tons=${tons}`);
|
||||
|
||||
const api = createApiClient();
|
||||
const response = await api.post('/orders', {
|
||||
portfolio_id: portfolioId,
|
||||
// Updated to use the correct endpoint and parameter names
|
||||
const response = await api.post('/offset-orders', {
|
||||
portfolioId,
|
||||
tons,
|
||||
dry_run: dryRun,
|
||||
dryRun,
|
||||
currency: 'USD'
|
||||
});
|
||||
|
||||
const order = response.data;
|
||||
|
||||
// Updated to handle costPerTon vs pricePerTon
|
||||
let pricePerTon = 200;
|
||||
if (order.portfolio?.price_per_ton !== undefined && order.portfolio.price_per_ton !== null) {
|
||||
const rawPrice = order.portfolio.price_per_ton;
|
||||
pricePerTon = typeof rawPrice === 'number' ? rawPrice : parseFloat(rawPrice) || 200;
|
||||
if (order.portfolio?.pricePerTon !== undefined && order.portfolio.pricePerTon !== null) {
|
||||
pricePerTon = typeof order.portfolio.pricePerTon === 'number' ? order.portfolio.pricePerTon : parseFloat(order.portfolio.pricePerTon) || 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 {
|
||||
id: order.id,
|
||||
amountCharged: order.amount_charged,
|
||||
currency: 'USD',
|
||||
amountCharged: order.amountCharged,
|
||||
currency: order.currency || 'USD',
|
||||
tons: order.tons,
|
||||
portfolio: {
|
||||
id: order.portfolio.id,
|
||||
@ -207,11 +207,11 @@ export async function createOffsetOrder(
|
||||
description: order.portfolio.description || '',
|
||||
projects: order.portfolio.projects || [],
|
||||
pricePerTon,
|
||||
currency: 'USD'
|
||||
currency: order.currency || 'USD'
|
||||
},
|
||||
status: order.status,
|
||||
createdAt: order.created_at,
|
||||
dryRun: order.dry_run
|
||||
createdAt: order.createdAt || order.created_at,
|
||||
dryRun: order.dryRun
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
logError(error);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user