feat: added few checks for widgetOwner address and returned Referral method and made deprecated

This commit is contained in:
Mikhail Gladchenko
2024-06-04 08:53:18 +01:00
parent 38635f560e
commit e130d4df09
3 changed files with 30 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@orionprotocol/sdk", "name": "@orionprotocol/sdk",
"version": "0.21.2-rc2", "version": "0.21.2-rc3",
"description": "Orion Protocol SDK", "description": "Orion Protocol SDK",
"main": "./lib/index.cjs", "main": "./lib/index.cjs",
"module": "./lib/index.js", "module": "./lib/index.js",

View File

@@ -16,7 +16,7 @@ import {
import type networkCodes from '../../constants/networkCodes.js'; import type networkCodes from '../../constants/networkCodes.js';
import toUpperCase from '../../utils/toUpperCase.js'; import toUpperCase from '../../utils/toUpperCase.js';
import httpToWS from '../../utils/httpToWS.js'; import httpToWS from '../../utils/httpToWS.js';
import { ethers } from 'ethers'; import { ZeroAddress, ethers, isAddress } from 'ethers';
import orderSchema from './schemas/orderSchema.js'; import orderSchema from './schemas/orderSchema.js';
import { fetchWithValidation } from 'simple-typed-fetch'; import { fetchWithValidation } from 'simple-typed-fetch';
import { pmmOrderSchema } from '../../Unit/Pmm/schemas/order'; import { pmmOrderSchema } from '../../Unit/Pmm/schemas/order';
@@ -219,7 +219,7 @@ class Aggregator {
}, },
...(partnerId !== undefined) && { 'X-Partner-Id': partnerId }, ...(partnerId !== undefined) && { 'X-Partner-Id': partnerId },
...(source !== undefined) && { 'X-Source': source }, ...(source !== undefined) && { 'X-Source': source },
...(widgetOwner !== undefined) && { 'X-Widget-Owner': widgetOwner }, ...(widgetOwner !== undefined && widgetOwner !== ZeroAddress && isAddress(widgetOwner)) && { 'X-Widget-Owner': widgetOwner },
...this.basicAuthHeaders, ...this.basicAuthHeaders,
}; };

View File

@@ -1,3 +1,4 @@
import { z } from 'zod';
import { fetchWithValidation } from 'simple-typed-fetch'; import { fetchWithValidation } from 'simple-typed-fetch';
import { import {
errorSchema, errorSchema,
@@ -40,6 +41,14 @@ type SignatureType = {
signature: string signature: string
}; };
type submitTransactionDataForWidgetPayload = {
partner_domain: string
sender_address: string
tx_hash: string
chain_id: number
signature: string
}
class ReferralSystem { class ReferralSystem {
private readonly apiUrl: string private readonly apiUrl: string
@@ -67,6 +76,7 @@ class ReferralSystem {
this.getContractsAddresses = this.getContractsAddresses.bind(this); this.getContractsAddresses = this.getContractsAddresses.bind(this);
this.getClaimInfo = this.getClaimInfo.bind(this); this.getClaimInfo = this.getClaimInfo.bind(this);
this.getAggregatedHistory = this.getAggregatedHistory.bind(this); this.getAggregatedHistory = this.getAggregatedHistory.bind(this);
this.submitTransactionDataForWidget = this.submitTransactionDataForWidget.bind(this);
} }
getLink = (refererAddress: string) => getLink = (refererAddress: string) =>
@@ -292,6 +302,23 @@ class ReferralSystem {
errorSchema errorSchema
); );
}; };
/**
* @deprecated and should be removed in future versions
*/
submitTransactionDataForWidget = (payload: submitTransactionDataForWidgetPayload) => {
return fetchWithValidation(
`${this.apiUrl}/referer/widget/submit`,
z.unknown(),
{
headers: {
'Content-type': 'application/json',
},
method: 'POST',
body: JSON.stringify(payload)
}
);
};
} }
export * as schemas from './schemas/index.js'; export * as schemas from './schemas/index.js';