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
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
"stellar-sdk": "^9.0.1"
},
"scripts": {
"prepare": "yarn build ; yarn build:commonjs",
"prepare": "yarn build && yarn build:commonjs",
"build": "tsc -p tsconfig.json",
"build:commonjs": "webpack --mode production",
"dev": "tsc-watch --project tsconfig.json --onSuccess 'yarn lint'",
"dev": "tsc-watch --project tsconfig.json --onSuccess \"yarn lint\"",
"docs": "typedoc",
"lint": "tslint --fix --format verbose --project tsconfig.json",
"lintAndTest": "yarn lint && jest",
"prettier": "prettier --write '**/*.{js,ts,md}'",
"prettier": "prettier --write \"**/*.{js,ts,md}\"",
"test": "jest --watch",
"test:ci": "jest"
},
"husky": {
"hooks": {
"pre-commit": "concurrently 'lint-staged' 'yarn build'"
"pre-commit": "concurrently \"lint-staged\" \"yarn build\""
}
},
"lint-staged": {
Expand All @@ -48,23 +48,23 @@
"@babel/preset-env": "^7.4.1",
"@babel/preset-typescript": "^7.3.3",
"@stellar/prettier-config": "^1.0.1",
"@stellar/tsconfig": "^1.0.1",
"@stellar/tsconfig": "^1.0.2",
"@stellar/tslint-config": "^1.0.4",
"@types/ledgerhq__hw-transport-u2f": "^4.21.1",
"@types/node-localstorage": "^1.3.0",
"@types/sinon": "^7.0.11",
"babel-jest": "^24.5.0",
"babel-jest": "^26.6.3",
"babel-loader": "^8.0.6",
"bignumber.js": "^8.1.1",
"concurrently": "^4.1.1",
"husky": "^1.3.1",
"jest": "^24.7.1",
"jest": "^26.6.3",
"jest-fetch-mock": "^3.0.3",
"jest-mock-random": "^1.0.3",
"lint-staged": "^8.1.5",
"node-localstorage": "^2.1.5",
"path": "^0.12.7",
"prettier": "^1.17.0",
"prettier": ">=2.0.0",
"regenerator-runtime": "^0.13.3",
"sinon": "^7.3.1",
"stellar-sdk": "^10.4.0",
Expand All @@ -73,7 +73,7 @@
"tsc-watch": "^2.1.2",
"tslint": "^5.14.0",
"typedoc": "^0.14.2",
"typescript": "^3.3.3333",
"typescript": "^4.9.4",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
},
Expand All @@ -82,7 +82,7 @@
"@ledgerhq/hw-app-str": "^5.28.0",
"@ledgerhq/hw-transport-u2f": "^5.26.0",
"@stellar/freighter-api": "^1.1.2",
"@trezor/connect-plugin-stellar": "^9.0.0",
"@trezor/connect-plugin-stellar": "^9.0.1",
"@trezor/connect-web": "^9.0.5",
"@types/jest": "^24.0.11",
"change-case": "^3.1.0",
Expand Down
5 changes: 5 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Stellar default Prettier config (@stellar/prettier-config) overrides for TS4
module.exports = {
...require("@stellar/prettier-config"),
bracketSameLine: false,
};
22 changes: 11 additions & 11 deletions src/KeyManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MemoryKeyStore } from "./plugins/MemoryKeyStore";
import { ScryptEncrypter } from "./plugins/ScryptEncrypter";

// tslint:disable-next-line
describe("KeyManager", function() {
describe("KeyManager", function () {
let clock: sinon.SinonFakeTimers;

beforeEach(() => {
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("KeyManager", function() {
expect(
"The function should have thrown but didn't, the test failed!",
).toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain("Key not found");
}
});
Expand Down Expand Up @@ -173,7 +173,7 @@ describe("KeyManager", function() {
expect(
"The function should have thrown but didn't, the test failed!",
).toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain("Key not found");
}
});
Expand Down Expand Up @@ -295,7 +295,7 @@ describe("KeyManager", function() {
});

expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toBe(`Error: ${error}`);
}
});
Expand Down Expand Up @@ -479,7 +479,7 @@ describe("KeyManager", function() {
});

expect("This test failed: transaction didn't cause error").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`InvalidSep10ChallengeError: The transaction` +
` sequence number should be zero`,
Expand Down Expand Up @@ -576,7 +576,7 @@ describe("KeyManager", function() {
});

expect(res).toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain("Network mismatch");
}
});
Expand Down Expand Up @@ -671,7 +671,7 @@ describe("KeyManager", function() {
});

expect("This test failed: transaction didn't cause error").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`InvalidSep10ChallengeError: Transaction not signed by server`,
);
Expand Down Expand Up @@ -860,7 +860,7 @@ describe("KeyManager", function() {
});

expect("This test failed: transaction didn't cause error").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`InvalidSep10ChallengeError: 'web_auth_domain' operation ` +
`value does not match www.stellar.org`,
Expand Down Expand Up @@ -959,7 +959,7 @@ describe("KeyManager", function() {
});

expect("This test failed: transaction didn't cause error").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`InvalidSep10ChallengeError: The transaction source account` +
` is not equal to the server's account`,
Expand Down Expand Up @@ -1019,7 +1019,7 @@ describe("KeyManager Scrypt", () => {
expect(
"The function should have thrown but didn't, the test failed!",
).toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain("Couldn’t decrypt key");
}

Expand All @@ -1030,7 +1030,7 @@ describe("KeyManager Scrypt", () => {
expect(
"The function should have thrown but didn't, the test failed!",
).toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain("Key not found");
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/data/DataProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Account validation", () => {
networkPassphrase: Networks.PUBLIC,
});
expect(provider).not.toBeInstanceOf(DataProvider);
} catch (e) {
} catch (e: any) {
expect(e).toBeTruthy();
expect(e.toString()).toBe("Error: No account key provided.");
}
Expand Down
31 changes: 16 additions & 15 deletions src/data/DataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ export class DataProvider {
try {
await this.fetchAccountDetails();
return true;
} catch (e) {
} catch (e: any) {
if (e.isUnfunded === undefined) {
return false;
}
return !e.isUnfunded;
}
}
Expand Down Expand Up @@ -224,7 +227,7 @@ export class DataProvider {
sequenceNumber: accountSummary.sequence,
balances,
};
} catch (err) {
} catch (err: any) {
err.isUnfunded = err.response && err.response.status === 404;
throw err as FetchAccountError;
}
Expand All @@ -246,9 +249,7 @@ export class DataProvider {
.then((res) => {
onMessage(res);
this.callbacks.accountDetails = debounce(() => {
this.fetchAccountDetails()
.then(onMessage)
.catch(onError);
this.fetchAccountDetails().then(onMessage).catch(onError);
}, 2000);
this.errorHandlers.accountDetails = onError;

Expand All @@ -258,7 +259,7 @@ export class DataProvider {
})

// otherwise, if it's a 404, try again in a bit.
.catch((err) => {
.catch((err: any) => {
if (err.isUnfunded) {
this._watcherTimeouts.watchAccountDetails = setTimeout(() => {
this.watchAccountDetails(params);
Expand Down Expand Up @@ -319,7 +320,7 @@ export class DataProvider {
})

// otherwise, if it's a 404, try again in a bit.
.catch((err) => {
.catch((err: any) => {
if (err.isUnfunded) {
this._watcherTimeouts.watchPayments = setTimeout(() => {
this.watchPayments(params);
Expand Down Expand Up @@ -361,7 +362,7 @@ export class DataProvider {
});

destinationProvider.fetchAccountDetails();
} catch (e) {
} catch (e: any) {
if (e.isUnfunded) {
throw new Error("The destination account is not funded yet.");
}
Expand All @@ -376,7 +377,7 @@ export class DataProvider {
// fetch the current account
try {
account = await this.fetchAccountDetails();
} catch (e) {
} catch (e: any) {
throw new Error(`Couldn't fetch account details, error: ${e.toString()}`);
}

Expand Down Expand Up @@ -417,8 +418,11 @@ export class DataProvider {
next = res.next;
offers = [...offers, ...additionalOffers];
}
} catch (e) {
throw new Error(`Couldn't fetch open offers, error: ${e.stack}`);
} catch (e: any) {
if (e instanceof Error) {
throw new Error(`Couldn't fetch open offers, error: ${e.stack}`);
}
throw new Error(`Couldn't fetch open offers, error: ${e.toString()}`);
}

const accountObject = new StellarAccount(
Expand Down Expand Up @@ -552,10 +556,7 @@ export class DataProvider {
const tradeRequests: Array<
Promise<ServerApi.CollectionPage<ServerApi.TradeRecord>>
> = offers.records.map(({ id }: { id: number | string }) =>
this.server
.trades()
.forOffer(`${id}`)
.call(),
this.server.trades().forOffer(`${id}`).call(),
);

const tradeResponses = await Promise.all(tradeRequests);
Expand Down
3 changes: 2 additions & 1 deletion src/data/makeDisplayablePayments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BigNumber from "bignumber.js";
import { AssetType } from "stellar-base";
import { ServerApi } from "stellar-sdk";
import { AccountCredited } from "stellar-sdk/lib/types/effects";

import { Account, Payment, Token } from "../types";

Expand Down Expand Up @@ -33,7 +34,7 @@ async function getAccountMergePaymentAmount(
try {
const effects = await payment.effects();
const accountMergePayment = effects.records.find(
(record) =>
(record): record is AccountCredited =>
record.type === "account_credited" && record.account === publicKey,
);

Expand Down
2 changes: 1 addition & 1 deletion src/keyTypeHandlers/albedo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const albedoHandler: KeyTypeHandler = {
response.signed_envelope_xdr,
Networks.PUBLIC,
) as Transaction;
} catch (error) {
} catch (error: any) {
throw new Error(
`We couldn’t sign the transaction with Albedo. ${error.toString()}.`,
);
Expand Down
4 changes: 1 addition & 3 deletions src/keyTypeHandlers/freighter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ describe("freighterHandler", () => {
.once()
.withArgs(XDR, undefined)
.returns(Promise.resolve(SIGNED_TRANSACTION));
TransactionBuilderMock.expects("fromXDR")
.once()
.returns(true);
TransactionBuilderMock.expects("fromXDR").once().returns(true);

freighterHandler.signTransaction({
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/keyTypeHandlers/freighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const freighterHandler: KeyTypeHandler = {
response,
Networks.PUBLIC,
) as Transaction;
} catch (error) {
} catch (error: any) {
throw new Error(
`We couldn’t sign the transaction with Freighter. ${error.toString()}.`,
);
Expand Down
2 changes: 1 addition & 1 deletion src/keyTypeHandlers/trezor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const trezorHandler: KeyTypeHandler = {
response.payload.error ||
"We couldn’t sign the transaction with Trezor.",
);
} catch (error) {
} catch (error: any) {
throw new Error(
`We couldn’t sign the transaction with Trezor. ${error.toString()}.`,
);
Expand Down
14 changes: 7 additions & 7 deletions src/sep8/ApprovalProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("ApprovalProvider", () => {
// @ts-ignore
const approvalProvider = new ApprovalProvider("");
expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`Error: Required parameter 'approvalServer' missing!`,
);
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("approve", () => {
// @ts-ignore
await approvalProvider.approve(txBuild);
expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`At least one signature is required before submitting for approval.`,
);
Expand Down Expand Up @@ -80,7 +80,7 @@ describe("approve", () => {
// @ts-ignore
await approvalProvider.approve(txBuild);
expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain(
`Error: Approval server returned unknown status`,
);
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("approve", () => {
// @ts-ignore
await approvalProvider.approve(txBuild);
expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain(
`Error: Error sending base64-encoded transaction`,
);
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("approve", () => {
// @ts-ignore
await approvalProvider.approve(txBuild);
expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toContain(
`Error: Error parsing the approval server response as JSON`,
);
Expand Down Expand Up @@ -348,7 +348,7 @@ describe("postActionUrl", () => {
// @ts-ignore
const res = await approvalProvider.postActionUrl({});
expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`Error: Required field 'action_url' missing!`,
);
Expand All @@ -366,7 +366,7 @@ describe("postActionUrl", () => {
field_value_map: {},
});
expect("This test failed").toBe(null);
} catch (e) {
} catch (e: any) {
expect(e.toString()).toMatch(
`Error: Required field 'field_value_map' missing!`,
);
Expand Down
Loading