Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Upgrade stellar-sdk + use Node v18 (#346)
Browse files Browse the repository at this point in the history
* Upgrade stellar-sdk + use Node v18

* Bump version to 0.11.0
  • Loading branch information
quietbits authored Dec 11, 2023
1 parent 41e66c6 commit cc16340
Show file tree
Hide file tree
Showing 30 changed files with 2,404 additions and 2,262 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## In master

## [v0.11.0](https://github.com/stellar/js-stellar-wallets/compare/v0.10.0...v0.11.0)

- Add support for Protocol 20 using stable `@stellar/stellar-sdk` `v11.0.1`
- Use Node v18
- Might still be unstable, use at your own risk

## [v0.10.0](https://github.com/stellar/js-stellar-wallets/compare/v0.9.1...v0.10.0)

- Add support for Protocol 20 (Experimental - use at your own risk)
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/wallet-sdk",
"version": "0.10.0",
"version": "0.11.0",
"description": "Libraries to help you write Stellar-enabled wallets in Javascript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"prettier": "@stellar/prettier-config",
"peerDependencies": {
"bignumber.js": "*",
"stellar-sdk": "^11.0.0-beta.3"
"@stellar/stellar-sdk": "^11.0.1"
},
"scripts": {
"prepare": "yarn build ; yarn build:commonjs",
Expand Down Expand Up @@ -44,52 +44,52 @@
}
},
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.1",
"@babel/preset-typescript": "^7.3.3",
"@babel/core": "^7.23.5",
"@babel/preset-env": "^7.23.5",
"@babel/preset-typescript": "^7.23.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/node-localstorage": "^1.3.3",
"@types/sinon": "^7.0.11",
"babel-jest": "^24.5.0",
"babel-loader": "^8.0.6",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
"bignumber.js": "^8.1.1",
"concurrently": "^4.1.1",
"husky": "^1.3.1",
"jest": "^24.7.1",
"jest-fetch-mock": "^3.0.3",
"jest-mock-random": "^1.0.3",
"jest-mock-random": "^1.1.1",
"lint-staged": "^8.1.5",
"node-localstorage": "^2.1.5",
"node-localstorage": "^3.0.5",
"path": "^0.12.7",
"prettier": "^1.17.0",
"regenerator-runtime": "^0.13.3",
"regenerator-runtime": "^0.14.0",
"sinon": "^7.3.1",
"stellar-sdk": "^11.0.0-beta.3",
"terser-webpack-plugin": "^2.3.0",
"ts-loader": "^6.2.1",
"terser-webpack-plugin": "^5.3.9",
"ts-loader": "^9.5.1",
"tsc-watch": "^2.1.2",
"tslint": "^5.14.0",
"typedoc": "^0.14.2",
"typescript": "^4.9.5",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@albedo-link/intent": "^0.9.2",
"@ledgerhq/hw-app-str": "^5.28.0",
"@ledgerhq/hw-transport-u2f": "^5.26.0",
"@stellar/freighter-api": "^1.1.2",
"@ledgerhq/hw-transport-u2f": "^5.36.0-deprecated",
"@stellar/freighter-api": "^1.7.1",
"@stellar/stellar-sdk": "^11.0.1",
"@types/jest": "^24.0.11",
"change-case": "^3.1.0",
"lodash": "^4.17.14",
"lodash": "^4.17.21",
"query-string": "^6.4.2",
"scrypt-async": "^2.0.1",
"trezor-connect": "^8.1.16",
"trezor-connect": "^8.2.12",
"tslib": "^2.6.2",
"tweetnacl": "^1.0.1",
"tweetnacl-util": "^0.15.0"
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1"
}
}
2 changes: 1 addition & 1 deletion src/KeyManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import StellarBase, { Operation, Transaction } from "@stellar/stellar-base";
import { mockRandomForEach } from "jest-mock-random";
import randomBytes from "randombytes";
import sinon from "sinon";
import StellarBase, { Operation, Transaction } from "stellar-base";

import { KeyType } from "./constants/keys";
import { KeyManager } from "./KeyManager";
Expand Down
4 changes: 2 additions & 2 deletions src/KeyManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Networks, Transaction, Utils } from "stellar-sdk";
import { Networks, Transaction, WebAuth } from "@stellar/stellar-sdk";

import { albedoHandler } from "./keyTypeHandlers/albedo";
import { freighterHandler } from "./keyTypeHandlers/freighter";
Expand Down Expand Up @@ -391,7 +391,7 @@ export class KeyManager {
);
}

let transaction = Utils.readChallengeTx(
let transaction = WebAuth.readChallengeTx(
json.transaction,
authServerKey,
keyNetwork,
Expand Down
2 changes: 1 addition & 1 deletion src/PluginTesting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as StellarSdk from "stellar-sdk";
import * as StellarSdk from "@stellar/stellar-sdk";

import { KeyType } from "./constants/keys";
import { generateEncryptedKey } from "./fixtures/keys";
Expand Down
2 changes: 1 addition & 1 deletion src/data/DataProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Networks } from "stellar-sdk";
import { Networks } from "@stellar/stellar-sdk";
import { generatePlaintextKey } from "../fixtures/keys";
import { DataProvider } from "./DataProvider";

Expand Down
45 changes: 23 additions & 22 deletions src/data/DataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import debounce from "lodash/debounce";
import {
Account as StellarAccount,
Asset,
Horizon,
Keypair,
Operation,
Server,
ServerApi,
StrKey,
TransactionBuilder,
} from "stellar-sdk";
} from "@stellar/stellar-sdk";
import debounce from "lodash/debounce";

import {
Account,
Expand Down Expand Up @@ -64,7 +63,7 @@ interface WatcherTimeoutsObject {
export class DataProvider {
private accountKey: string;
private serverUrl: string;
private server: Server;
private server: Horizon.Server;
private networkPassphrase: string;
private _watcherTimeouts: WatcherTimeoutsObject;

Expand Down Expand Up @@ -103,7 +102,7 @@ export class DataProvider {
this.effectStreamEnder = undefined;
this.networkPassphrase = params.networkPassphrase;
this.serverUrl = params.serverUrl;
this.server = new Server(this.serverUrl, metadata);
this.server = new Horizon.Server(this.serverUrl, metadata);
this.accountKey = accountKey;
this._watcherTimeouts = {};
}
Expand All @@ -127,7 +126,7 @@ export class DataProvider {
* Return the server object, in case the consumer wants to call an
* unsupported function.
*/
public getServer(): Server {
public getServer(): Horizon.Server {
return this.server;
}

Expand Down Expand Up @@ -404,10 +403,10 @@ export class DataProvider {

// get ALL offers for the account
// (we don't need trade details, so skip those)
let offers: ServerApi.OfferRecord[] = [];
let offers: Horizon.ServerApi.OfferRecord[] = [];
try {
let additionalOffers: ServerApi.OfferRecord[] | undefined;
let next: () => Promise<Collection<ServerApi.OfferRecord>> = () =>
let additionalOffers: Horizon.ServerApi.OfferRecord[] | undefined;
let next: () => Promise<Collection<Horizon.ServerApi.OfferRecord>> = () =>
this.server
.offers()
.forAccount(this.accountKey)
Expand Down Expand Up @@ -550,11 +549,11 @@ export class DataProvider {
}

private async _processOpenOffers(
offers: ServerApi.CollectionPage<ServerApi.OfferRecord>,
offers: Horizon.ServerApi.CollectionPage<Horizon.ServerApi.OfferRecord>,
): Promise<Collection<Offer>> {
// find all offerids and check for trades of each
const tradeRequests: Array<
Promise<ServerApi.CollectionPage<ServerApi.TradeRecord>>
Promise<Horizon.ServerApi.CollectionPage<Horizon.ServerApi.TradeRecord>>
> = offers.records.map(({ id }: { id: number | string }) =>
this.server
.trades()
Expand All @@ -572,16 +571,19 @@ export class DataProvider {
{
offers: offers.records,
tradeResponses: tradeResponses.map(
(res: ServerApi.CollectionPage<ServerApi.TradeRecord>) =>
res.records,
(
res: Horizon.ServerApi.CollectionPage<
Horizon.ServerApi.TradeRecord
>,
) => res.records,
),
},
),
};
}

private async _processTrades(
trades: ServerApi.CollectionPage<ServerApi.TradeRecord>,
trades: Horizon.ServerApi.CollectionPage<Horizon.ServerApi.TradeRecord>,
): Promise<Collection<Trade>> {
return {
next: () => trades.next().then((res) => this._processTrades(res)),
Expand All @@ -594,15 +596,14 @@ export class DataProvider {
}

private async _processPayments(
payments: ServerApi.CollectionPage<
| ServerApi.PaymentOperationRecord
| ServerApi.CreateAccountOperationRecord
| ServerApi.PathPaymentOperationRecord
>,
// using any type as a temp fix
payments: any,
): Promise<Collection<Payment>> {
return {
next: () => payments.next().then((res) => this._processPayments(res)),
prev: () => payments.prev().then((res) => this._processPayments(res)),
next: () =>
payments.next().then((res: any) => this._processPayments(res)),
prev: () =>
payments.prev().then((res: any) => this._processPayments(res)),
records: await makeDisplayablePayments(
{ publicKey: this.accountKey },
payments.records,
Expand Down
2 changes: 1 addition & 1 deletion src/data/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Asset } from "stellar-sdk";
import { Asset } from "@stellar/stellar-sdk";
import {
getBalanceIdentifier,
getStellarSdkAsset,
Expand Down
6 changes: 4 additions & 2 deletions src/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Asset, Horizon } from "stellar-sdk";
import { Asset, Horizon } from "@stellar/stellar-sdk";

import { AssetToken, Token } from "../types";

Expand All @@ -21,7 +21,9 @@ export function getTokenIdentifier(token: Token): string {
* through `getTokenIdentifier`
* @returns Returns `${tokenCode}:${issuerKey}`.
*/
export function getBalanceIdentifier(balance: Horizon.BalanceLine): string {
export function getBalanceIdentifier(
balance: Horizon.HorizonApi.BalanceLine,
): string {
if ("asset_issuer" in balance && !balance.asset_issuer) {
return "native";
}
Expand Down
10 changes: 6 additions & 4 deletions src/data/makeDisplayableBalances.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Horizon } from "@stellar/stellar-sdk";
import BigNumber from "bignumber.js";
import { Horizon, ServerApi } from "stellar-sdk";

import { BASE_RESERVE, BASE_RESERVE_MIN_COUNT } from "../constants/stellar";
import { BalanceMap } from "../types";
import { getBalanceIdentifier } from "./";

export function makeDisplayableBalances(
accountDetails: ServerApi.AccountRecord,
accountDetails: Horizon.ServerApi.AccountRecord,
): BalanceMap {
const {
balances,
Expand Down Expand Up @@ -60,7 +60,9 @@ export function makeDisplayableBalances(
};
}

const liquidityPoolBalance = balance as Horizon.BalanceLineLiquidityPool;
/* tslint:disable */
const liquidityPoolBalance = balance as Horizon.HorizonApi.BalanceLineLiquidityPool;
/* tslint:enable */

if (identifier.includes(":lp")) {
return {
Expand All @@ -73,7 +75,7 @@ export function makeDisplayableBalances(
};
}

const assetBalance = balance as Horizon.BalanceLineAsset;
const assetBalance = balance as Horizon.HorizonApi.BalanceLineAsset;
const assetSponsor = assetBalance.sponsor
? { sponsor: assetBalance.sponsor }
: {};
Expand Down
10 changes: 5 additions & 5 deletions src/data/makeDisplayableOffers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { AssetType } from "@stellar/stellar-base";
import { Horizon } from "@stellar/stellar-sdk";
import BigNumber from "bignumber.js";
import flatten from "lodash/flatten";
import { AssetType } from "stellar-base";
import { ServerApi } from "stellar-sdk";

import { makeDisplayableTrades } from "./makeDisplayableTrades";

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

export type TradeCollection = ServerApi.TradeRecord[];
export type TradeCollection = Horizon.ServerApi.TradeRecord[];

export interface DisplayableOffersParams {
offers: ServerApi.OfferRecord[];
offers: Horizon.ServerApi.OfferRecord[];
tradeResponses: TradeCollection[];
}

Expand Down Expand Up @@ -42,7 +42,7 @@ export function makeDisplayableOffers(
}, {});

return offers.map(
(offer: ServerApi.OfferRecord): Offer => {
(offer: Horizon.ServerApi.OfferRecord): Offer => {
const {
id,
selling,
Expand Down
Loading

0 comments on commit cc16340

Please sign in to comment.