Skip to content

Commit

Permalink
fix: updated broken aptos types. (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored May 12, 2023
1 parent 0f54445 commit 26f20c8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .changeset/thirty-monkeys-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-aptos-utils': patch
'@moralisweb3/aptos-api': patch
'moralis': patch
---

Set some properties as optional for the `AptosNFTTransferResponse` class.
7 changes: 7 additions & 0 deletions .changeset/violet-baboons-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-aptos-utils': patch
'@moralisweb3/aptos-api': patch
'moralis': patch
---

Fixed the return type of the `getNFTTransfersByIds()` method in the Aptos API module.
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,13 @@ export abstract class AbstractClient {
* @param {String[]} [request.walletBlacklist] The addresses of the wallets to blacklist (optional)
* @param {String[]} [request.walletWhitelist] The addresses of the wallets to whitelist (optional)
* @param {Object} [request.network] The network of query. Defaults to mainnet. (optional)
* @returns {Object[]} Response for the request.
* @returns {Object} Response for the request.
*/
getNFTTransfersByIds: this.createEndpoint<
GetNFTTransfersByIdsOperationRequest,
GetNFTTransfersByIdsOperationRequestJSON,
AptosNFTTransfersByTokensResponse[],
AptosNFTTransfersByTokensResponseJSON[]
AptosNFTTransfersByTokensResponse,
AptosNFTTransfersByTokensResponseJSON
>(GetNFTTransfersByIdsOperation),
/**
* @description Get NFT Transfers by Collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export const GetNFTTransfersByIdsOperation = {
hasResponse: true,
hasBody: false,

parseResponse(json: AptosNFTTransfersByTokensResponseJSON[]): AptosNFTTransfersByTokensResponse[] {
return json.map((item) => AptosNFTTransfersByTokensResponse.fromJSON(item));
parseResponse(json: AptosNFTTransfersByTokensResponseJSON): AptosNFTTransfersByTokensResponse {
return AptosNFTTransfersByTokensResponse.fromJSON(json);
},

serializeRequest(request: GetNFTTransfersByIdsOperationRequest): GetNFTTransfersByIdsOperationRequestJSON {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import { AptosNative, AptosNativeInput, AptosNativeJSON, AptosAddress, AptosAddr
// - transfer_type ($ref: #/components/schemas/NFTTransferResponse/properties/transfer_type)

export interface AptosNFTTransferResponseJSON {
readonly coin_amount: AptosNativeJSON;
readonly coin_type: string;
readonly coin_amount?: AptosNativeJSON;
readonly coin_type?: string;
readonly collection_data_id_hash: string;
readonly collection_name: string;
readonly creator_address: AptosAddressJSON;
readonly event_account_address: string;
readonly event_creation_number: string;
readonly event_sequence_number: string;
readonly from_address: AptosAddressJSON;
readonly from_address?: AptosAddressJSON;
readonly name: string;
readonly property_version: string;
readonly to_address: AptosAddressJSON;
readonly to_address?: AptosAddressJSON;
readonly token_amount: AptosNativeJSON;
readonly token_data_id_hash: string;
readonly transaction_timestamp: string;
Expand All @@ -42,18 +42,18 @@ export interface AptosNFTTransferResponseJSON {
}

export interface AptosNFTTransferResponseInput {
readonly coinAmount: AptosNativeInput | AptosNative;
readonly coinType: string;
readonly coinAmount?: AptosNativeInput | AptosNative;
readonly coinType?: string;
readonly collectionDataIdHash: string;
readonly collectionName: string;
readonly creatorAddress: AptosAddressInput | AptosAddress;
readonly eventAccountAddress: string;
readonly eventCreationNumber: string;
readonly eventSequenceNumber: string;
readonly fromAddress: AptosAddressInput | AptosAddress;
readonly fromAddress?: AptosAddressInput | AptosAddress;
readonly name: string;
readonly propertyVersion: string;
readonly toAddress: AptosAddressInput | AptosAddress;
readonly toAddress?: AptosAddressInput | AptosAddress;
readonly tokenAmount: AptosNativeInput | AptosNative;
readonly tokenDataIdHash: string;
readonly transactionTimestamp: string;
Expand All @@ -71,18 +71,18 @@ export class AptosNFTTransferResponse {

public static fromJSON(json: AptosNFTTransferResponseJSON): AptosNFTTransferResponse {
const input: AptosNFTTransferResponseInput = {
coinAmount: AptosNative.fromJSON(json.coin_amount),
coinAmount: json.coin_amount ? AptosNative.fromJSON(json.coin_amount) : undefined,
coinType: json.coin_type,
collectionDataIdHash: json.collection_data_id_hash,
collectionName: json.collection_name,
creatorAddress: AptosAddress.fromJSON(json.creator_address),
eventAccountAddress: json.event_account_address,
eventCreationNumber: json.event_creation_number,
eventSequenceNumber: json.event_sequence_number,
fromAddress: AptosAddress.fromJSON(json.from_address),
fromAddress: json.from_address ? AptosAddress.fromJSON(json.from_address) : undefined,
name: json.name,
propertyVersion: json.property_version,
toAddress: AptosAddress.fromJSON(json.to_address),
toAddress: json.to_address ? AptosAddress.fromJSON(json.to_address) : undefined,
tokenAmount: AptosNative.fromJSON(json.token_amount),
tokenDataIdHash: json.token_data_id_hash,
transactionTimestamp: json.transaction_timestamp,
Expand All @@ -95,11 +95,11 @@ export class AptosNFTTransferResponse {
/**
* @description The number of tokens transferred
*/
public readonly coinAmount: AptosNative;
public readonly coinAmount?: AptosNative;
/**
* @description The type of tokens transferred
*/
public readonly coinType: string;
public readonly coinType?: string;
/**
* @description The identifier of the collection
*/
Expand Down Expand Up @@ -127,7 +127,7 @@ export class AptosNFTTransferResponse {
/**
* @description The address sending the transfer
*/
public readonly fromAddress: AptosAddress;
public readonly fromAddress?: AptosAddress;
/**
* @description The name of the token
*/
Expand All @@ -139,7 +139,7 @@ export class AptosNFTTransferResponse {
/**
* @description The address recieving the transfer
*/
public readonly toAddress: AptosAddress;
public readonly toAddress?: AptosAddress;
/**
* @description The number of tokens transferred
*/
Expand All @@ -162,18 +162,18 @@ export class AptosNFTTransferResponse {
public readonly transferType: string;

private constructor(input: AptosNFTTransferResponseInput) {
this.coinAmount = AptosNative.create(input.coinAmount);
this.coinAmount = input.coinAmount ? AptosNative.create(input.coinAmount) : undefined;
this.coinType = input.coinType;
this.collectionDataIdHash = input.collectionDataIdHash;
this.collectionName = input.collectionName;
this.creatorAddress = AptosAddress.create(input.creatorAddress);
this.eventAccountAddress = input.eventAccountAddress;
this.eventCreationNumber = input.eventCreationNumber;
this.eventSequenceNumber = input.eventSequenceNumber;
this.fromAddress = AptosAddress.create(input.fromAddress);
this.fromAddress = input.fromAddress ? AptosAddress.create(input.fromAddress) : undefined;
this.name = input.name;
this.propertyVersion = input.propertyVersion;
this.toAddress = AptosAddress.create(input.toAddress);
this.toAddress = input.toAddress ? AptosAddress.create(input.toAddress) : undefined;
this.tokenAmount = AptosNative.create(input.tokenAmount);
this.tokenDataIdHash = input.tokenDataIdHash;
this.transactionTimestamp = input.transactionTimestamp;
Expand All @@ -183,18 +183,18 @@ export class AptosNFTTransferResponse {

public toJSON(): AptosNFTTransferResponseJSON {
return {
coin_amount: this.coinAmount.toJSON(),
coin_amount: this.coinAmount ? this.coinAmount.toJSON() : undefined,
coin_type: this.coinType,
collection_data_id_hash: this.collectionDataIdHash,
collection_name: this.collectionName,
creator_address: this.creatorAddress.toJSON(),
event_account_address: this.eventAccountAddress,
event_creation_number: this.eventCreationNumber,
event_sequence_number: this.eventSequenceNumber,
from_address: this.fromAddress.toJSON(),
from_address: this.fromAddress ? this.fromAddress.toJSON() : undefined,
name: this.name,
property_version: this.propertyVersion,
to_address: this.toAddress.toJSON(),
to_address: this.toAddress ? this.toAddress.toJSON() : undefined,
token_amount: this.tokenAmount.toJSON(),
token_data_id_hash: this.tokenDataIdHash,
transaction_timestamp: this.transactionTimestamp,
Expand Down

1 comment on commit 26f20c8

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 20%
20.6% (61/296) 20.48% (17/83) 19.04% (12/63)
auth Coverage: 89%
92.45% (98/106) 83.33% (20/24) 86.66% (26/30)
evm-api Coverage: 96%
96.84% (92/95) 66.66% (6/9) 95.16% (59/62)
common-aptos-utils Coverage: 4%
4.56% (151/3306) 4.49% (25/556) 5.53% (45/813)
common-evm-utils Coverage: 65%
65.8% (1484/2255) 27.2% (256/941) 45.35% (410/904)
sol-api Coverage: 96%
97.5% (39/40) 66.66% (6/9) 93.33% (14/15)
common-sol-utils Coverage: 74%
74.55% (167/224) 66.66% (18/27) 65.38% (51/78)
common-streams-utils Coverage: 90%
90.73% (1204/1327) 73.63% (363/493) 82.07% (444/541)
streams Coverage: 88%
88.2% (576/653) 68.81% (64/93) 88.02% (125/142)

Please sign in to comment.