Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions src/api/version.js

This file was deleted.

68 changes: 68 additions & 0 deletions src/api/version.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub is not able to automatically show the changes done to the version.ts file, and instead shows that a file was deleted and this one was created.

To see only the changed lines, look at the commit dd55317

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) Hathor Labs and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { createRequestInstance } from './axiosInstance';
import { ApiVersion } from '../types';

/**
* Api calls for version
*
* @namespace ApiVersion
*/

const versionApi = {
/**
* Get version of full node running in connected server
*
* @param resolve Method to be called after response arrives
*
* @deprecated Use asyncGetVersion instead
* @return Promise that resolves to void (result is passed through callback)
* @memberof ApiVersion
* @inner
*/
// TODO: This method uses a callback pattern but also returns a Promise, which is an anti-pattern
// NOTE: createRequestInstance has legacy typing (resolve?: null) that doesn't match actual usage.
getVersion(resolve: (data: ApiVersion) => void) {
return createRequestInstance(resolve as unknown as null)
.get<ApiVersion>(`version`)
.then(
res => {
resolve(res.data);
},
res => {
return Promise.reject(res);
}
);
},

/**
* Get version of full node running in connected server
*
* @return Promise resolving to the version data
* @memberof ApiVersion
* @inner
*/
async asyncGetVersion(): Promise<ApiVersion> {
// FIXME: This function wraps a Promise around another Promise, which is an anti-pattern.
return new Promise((resolve, reject) => {
// NOTE: createRequestInstance has legacy typing (resolve?: null) that doesn't match actual usage.
createRequestInstance(resolve as unknown as null)
.get<ApiVersion>(`version`)
.then(
res => {
resolve(res.data);
},
err => {
reject(err);
}
);
});
},
};

export default versionApi;
9 changes: 5 additions & 4 deletions src/new/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import { ErrorMessages } from '../errorMessages';
import P2SHSignature from '../models/p2sh_signature';
import {
ApiVersion,
AddressScanPolicyData,
AuthorityType,
FullNodeVersionData,
Expand Down Expand Up @@ -448,8 +449,8 @@
* */
// eslint-disable-next-line class-methods-use-this -- The server address is fetched directly from the configs
async getVersionData(): Promise<FullNodeVersionData> {
const versionData: any = await new Promise((resolve, reject) => {
versionApi.getVersion(resolve).catch((error: any) => reject(error));
const versionData: ApiVersion = await new Promise((resolve, reject) => {
versionApi.getVersion(resolve).catch(error => reject(error));

Check warning on line 453 in src/new/wallet.ts

View check run for this annotation

Codecov / codecov/patch

src/new/wallet.ts#L452-L453

Added lines #L452 - L453 were not covered by tests
});

return {
Expand Down Expand Up @@ -1612,7 +1613,7 @@
* 'password': password to decrypt xpriv information. Required if not set in object.
* }
*/
async start(optionsParams: any = {}): Promise<any> {
async start(optionsParams: any = {}): Promise<ApiVersion> {
const options: any = { pinCode: null, password: null, ...optionsParams };
const pinCode: any = options.pinCode || this.pinCode;
const password: any = options.password || this.password;
Expand Down Expand Up @@ -1672,7 +1673,7 @@
this.walletStopped = false;
this.setState(HathorWallet.CONNECTING);

const info = await new Promise((resolve, reject) => {
const info = await new Promise<ApiVersion>((resolve, reject) => {
versionApi.getVersion(resolve).catch(error => reject(error));
});
if (info.network.indexOf(this.conn.network) >= 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ export interface IFillTxOptions {
export interface ApiVersion {
version: string;
network: string;
// min_weight: number; // DEPRECATED
/** @deprecated */
min_weight: number;
min_tx_weight: number;
min_tx_weight_coefficient: number;
min_tx_weight_k: number;
Expand Down
Loading