Skip to content

Commit

Permalink
added frontend route for invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
tokdaniel committed Nov 2, 2023
1 parent 2c44526 commit 51d10fa
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion apps/backend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 14 additions & 28 deletions apps/backend/src/super-token-accounting/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
* Do not make direct changes to the file.
*/


export interface paths {
'/v1/stream-periods': {
"/v1/stream-periods": {
/** @description Fetch virtualized stream periods */
get: {
parameters: {
query: {
/** @description Number array for the Chain IDs you want to limit your accounting data to. */
chains: components['schemas']['Network'][];
chains: components["schemas"]["Network"][];
/** @description The addresses array you’re getting accounting data for. */
addresses: string[];
/** @description The Unix timestamp where your accounting data is to start from. */
start: number;
/** @description The Unix timestamp where your accounting data is to end. */
end: number;
/** @description When getting pricing data for each accounting record, you have the choice as to whether you want the instanteous price at the end of the timeframe of the accounting record or the average price over a certain lag from the end of the timeframe of the accounting record. */
priceGranularity: components['schemas']['VirtualizationPeriod'];
priceGranularity: components["schemas"]["VirtualizationPeriod"];
/** @description The duration represented in each accounting record in your accounting data. (NB! Please use hourly period with small timeframe or single sender/receiver address.) */
virtualization: components['schemas']['VirtualizationPeriod'];
virtualization: components["schemas"]["VirtualizationPeriod"];
/** @description The currency with which price data will be displayed in. */
currency: components['schemas']['Currency'];
currency: components["schemas"]["Currency"];
/** @description Addresses that are either sending or receiving streams from the addresses account(s) that you want to limit your accounting data to. */
counterparties?: string[];
};
Expand All @@ -31,7 +32,7 @@ export interface paths {
/** @description Array of stream periods containing virtualized periods. */
200: {
content: {
'application/json': components['schemas']['StreamPeriod'][];
"application/json": components["schemas"]["StreamPeriod"];
};
};
};
Expand All @@ -44,25 +45,9 @@ export type webhooks = Record<string, never>;
export interface components {
schemas: {
/** @enum {string} */
VirtualizationPeriod: 'hour' | 'day' | 'week' | 'month' | 'year';
VirtualizationPeriod: "hour" | "day" | "week" | "month" | "year";
/** @enum {string} */
Currency:
| 'USD'
| 'EUR'
| 'AUD'
| 'BRL'
| 'CAD'
| 'CHF'
| 'CNY'
| 'GBP'
| 'HKD'
| 'INR'
| 'JPY'
| 'KRW'
| 'MXN'
| 'NOK'
| 'RUB'
| 'SEK';
Currency: "USD" | "EUR" | "AUD" | "BRL" | "CAD" | "CHF" | "CNY" | "GBP" | "HKD" | "INR" | "JPY" | "KRW" | "MXN" | "NOK" | "RUB" | "SEK";
/** @enum {number} */
Network: 1 | 10 | 56 | 100 | 137 | 42161 | 42220 | 43114 | 8453;
Token: {
Expand All @@ -80,8 +65,8 @@ export interface components {
StreamPeriod: {
id: string;
flowRate: string;
token: components['schemas']['Token'];
chainId: components['schemas']['Network'];
token: components["schemas"]["Token"];
chainId: components["schemas"]["Network"];
sender: string;
receiver: string;
startedAtTimestamp: number;
Expand All @@ -91,11 +76,12 @@ export interface components {
stoppedAtBlockNumber?: number;
stoppedAtEvent?: string;
totalAmountStreamed: string;
virtualPeriods?: components['schemas']['VirtualPeriod'][];
virtualPeriods?: components["schemas"]["VirtualPeriod"][];
};
};
responses: never;
parameters: {};
parameters: {
};
requestBodies: never;
headers: never;
pathItems: never;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ export class SuperTokenAccountingService {
if (error) {
throw error;
} else {
const streamPeriods = response.data.filter(
(x) => x.token!.id!.toLowerCase() === superTokenAddress.toLowerCase(),
);
const sumTransferred = streamPeriods.reduce(
(acc, { sender, totalAmountStreamed }) =>
acc +
(sender.toLowerCase() === senderAddress.toLowerCase() ? 1n : -1n) *
(totalAmountStreamed ? BigInt(totalAmountStreamed) : 0n),
0n,
);
return sumTransferred;
// const streamPeriods = response.data.filter(
// (x) => x.token!.id!.toLowerCase() === superTokenAddress.toLowerCase(),
// );
// const sumTransferred = streamPeriods.reduce(
// (acc, { sender, totalAmountStreamed }) =>
// acc +
// (sender.toLowerCase() === senderAddress.toLowerCase() ? 1n : -1n) *
// (totalAmountStreamed ? BigInt(totalAmountStreamed) : 0n),
// 0n,
// );
// return sumTransferred;

return 0n;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type ProductResponse = {
paymentDetails: WidgetProps['paymentDetails'];
};

type InvoiceResponse = {
stripeInvoice: Stripe.Invoice;
productConfig: ProductResponse;
};

@Controller('superfluid-stripe-converter')
export class SuperfluidStripeConverterController {
constructor(
Expand Down Expand Up @@ -93,6 +98,21 @@ export class SuperfluidStripeConverterController {
await this.superfluidStripeConfigService.loadOrInitializeLookAndFeelConfig();
return lookAndFeelConfig;
}

@Get('invoice')
async invoice(@Query('invoice-id') invoiceId: string): Promise<InvoiceResponse> {
const stripeInvoice = await this.stripeClient.invoices.retrieve(invoiceId);
const product = await this.stripeClient.products.retrieve(
stripeInvoice.lines.data[0].price?.product as string,
);

const productConfig = await this.mapStripeProductToCheckoutWidget(product.id);

return {
stripeInvoice,
productConfig,
};
}
}

const logger = new Logger(SuperfluidStripeConverterController.name);
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51d10fa

Please sign in to comment.