Skip to content

Commit

Permalink
Upgrade stellar-sdk to v11.0.0-beta.3 (stellar#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
quietbits authored Sep 19, 2023
1 parent 16a925b commit cf50ec8
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 159 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"dependencies": {
"demo-wallet-shared": "^1.0.0",
"npm-run-all": "^4.1.5",
"stellar-sdk": "^10.4.1"
"stellar-sdk": "^11.0.0-beta.3"
}
}
2 changes: 1 addition & 1 deletion packages/demo-wallet-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"react-redux": "^8.1.2",
"react-router-dom": "^6.15.0",
"redux": "^4.2.1",
"stellar-sdk": "^10.4.1",
"stellar-sdk": "^11.0.0-beta.3",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"styled-components": "^6.0.7",
Expand Down
6 changes: 3 additions & 3 deletions packages/demo-wallet-client/src/components/WarningBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import StellarSdk from "stellar-sdk";
import { Networks } from "stellar-sdk";
import { StatusBar } from "@stellar/design-system";
import { getNetworkConfig } from "demo-wallet-shared/build/helpers/getNetworkConfig";

export const WarningBanner = () => {
const { network, url } = getNetworkConfig();

if (!network || network === StellarSdk.Networks.TESTNET) {
if (!network || network === Networks.TESTNET) {
return null;
}

const message =
network === StellarSdk.Networks.PUBLIC
network === Networks.PUBLIC
? "You’ve connected a real account to this demo. You are not on the test server. Any actions you take here will affect actual assets."
: `You’ve connected to ${url}`;

Expand Down
4 changes: 2 additions & 2 deletions packages/demo-wallet-client/src/ducks/claimableBalances.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import StellarSdk, { ServerApi } from "stellar-sdk";
import { ServerApi, Server } from "stellar-sdk";
import { RootState } from "config/store";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
import { getNetworkConfig } from "demo-wallet-shared/build/helpers/getNetworkConfig";
Expand All @@ -20,7 +20,7 @@ export const fetchClaimableBalancesAction = createAsyncThunk<
"claimableBalances/fetchClaimableBalancesAction",
async ({ publicKey }, { rejectWithValue }) => {
const networkConfig = getNetworkConfig();
const server = new StellarSdk.Server(networkConfig.url);
const server = new Server(networkConfig.url);

try {
const claimableBalanceResponse = await server
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-wallet-client/src/ducks/sendPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "types/types";

export const sendPaymentAction = createAsyncThunk<
Horizon.TransactionResponse,
Horizon.SubmitTransactionResponse,
PaymentTransactionParams,
{ rejectValue: RejectMessage; state: RootState }
>(
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-wallet-client/src/ducks/sep8Send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const sep8ReviseTransactionAction = createAsyncThunk<
);

export const sep8SubmitRevisedTransactionAction = createAsyncThunk<
Horizon.TransactionResponse,
Horizon.SubmitTransactionResponse,
undefined,
{ rejectValue: RejectMessage; state: RootState }
>(
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-wallet-client/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export interface LogsInitialState {
}

export interface SendPaymentInitialState {
data: Horizon.TransactionResponse | null;
data: Horizon.SubmitTransactionResponse | null;
errorString?: string;
status: ActionStatus | undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-wallet-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"dotenv": "^16.3.1",
"express": "^4.18.2",
"stellar-sdk": "^10.4.1",
"stellar-sdk": "^11.0.0-beta.3",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
Expand Down
12 changes: 7 additions & 5 deletions packages/demo-wallet-shared/helpers/getNetworkConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import StellarSdk from "stellar-sdk";
import { Networks } from "stellar-sdk";

export const getNetworkConfig = () => ({
network: window._env_.HORIZON_PASSPHRASE || StellarSdk.Networks.TESTNET,
url: window._env_.HORIZON_URL || "https://horizon-testnet.stellar.org",
});
export const getNetworkConfig = () => {
return {
network: window._env_.HORIZON_PASSPHRASE || Networks.TESTNET,
url: window._env_.HORIZON_URL || "https://horizon-testnet.stellar.org",
};
};
5 changes: 3 additions & 2 deletions packages/demo-wallet-shared/methods/claimClaimableBalance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import StellarSdk, {
import {
Account,
Keypair,
Operation,
TransactionBuilder,
Server,
} from "stellar-sdk";
import { getErrorMessage } from "../helpers/getErrorMessage";
import { log } from "../helpers/log";
Expand Down Expand Up @@ -32,7 +33,7 @@ export const claimClaimableBalance = async ({

try {
const keypair = Keypair.fromSecret(secretKey);
const server = new StellarSdk.Server(networkUrl);
const server = new Server(networkUrl);
const accountRecord = await server
.accounts()
.accountId(keypair.publicKey())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StellarSdk from "stellar-sdk";
import { Server } from "stellar-sdk";
import { log } from "../helpers/log";

export const getHomeDomainFromAssetIssuer = async ({
Expand All @@ -13,7 +13,7 @@ export const getHomeDomainFromAssetIssuer = async ({
body: `Asset issuer ${assetIssuer}`,
});

const server = new StellarSdk.Server(networkUrl);
const server = new Server(networkUrl);
const accountRecord = await server.loadAccount(assetIssuer);
const homeDomain: string | undefined = accountRecord.home_domain;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import StellarSdk, {
import {
Account,
Asset,
BASE_FEE,
Keypair,
Operation,
Server,
TransactionBuilder,
} from "stellar-sdk";
import { log } from "../../helpers/log";
Expand Down Expand Up @@ -32,7 +33,7 @@ export const pollWithdrawUntilComplete = async ({
assetIssuer: string;
}) => {
const keypair = Keypair.fromSecret(secretKey);
const server = new StellarSdk.Server(networkUrl);
const server = new Server(networkUrl);
let currentStatus = TransactionStatus.INCOMPLETE;

const transactionUrl = new URL(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import StellarSdk, {
import {
Account,
Asset,
BASE_FEE,
Keypair,
Operation,
Server,
TransactionBuilder,
} from "stellar-sdk";
import { log } from "../../helpers/log";
Expand Down Expand Up @@ -32,7 +33,7 @@ export const pollWithdrawUntilComplete = async ({
assetIssuer: string;
}) => {
const keypair = Keypair.fromSecret(secretKey);
const server = new StellarSdk.Server(networkUrl);
const server = new Server(networkUrl);
let currentStatus = TransactionStatus.INCOMPLETE;

const transactionUrl = new URL(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StellarSdk, { Transaction } from "stellar-sdk";
import { Server, Transaction } from "stellar-sdk";
import { getErrorString } from "../../helpers/getErrorString";
import { getNetworkConfig } from "../../helpers/getNetworkConfig";
import { log } from "../../helpers/log";
Expand All @@ -15,7 +15,7 @@ export const revisePaymentTransaction = async ({
}: {
params: Sep8PaymentTransactionParams;
}): Promise<Sep8ApprovalResponse> => {
const server = new StellarSdk.Server(getNetworkConfig().url);
const server = new Server(getNetworkConfig().url);
const { approvalServer } = params;

// build transaction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import StellarSdk, {
import {
Horizon,
Keypair,
Server,
Transaction,
TransactionBuilder,
} from "stellar-sdk";
Expand All @@ -22,7 +23,7 @@ export const submitRevisedTransaction = async ({
secretKey: string;
}) => {
const networkConfig = getNetworkConfig();
const server = new StellarSdk.Server(networkConfig.url);
const server = new Server(networkConfig.url);
const transaction = TransactionBuilder.fromXDR(
revisedTxXdr,
networkConfig.network,
Expand All @@ -43,9 +44,8 @@ export const submitRevisedTransaction = async ({
title: "Submitting send payment transaction",
body: transaction,
});
const result: Horizon.TransactionResponse = await server.submitTransaction(
transaction,
);
const result: Horizon.SubmitTransactionResponse =
await server.submitTransaction(transaction);
log.response({ title: "Submitted send payment transaction", body: result });
log.instruction({
title: "SEP-8 send payment completed 🎉",
Expand Down
24 changes: 16 additions & 8 deletions packages/demo-wallet-shared/methods/submitPaymentTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import StellarSdk, { BASE_FEE, Keypair } from "stellar-sdk";
import {
BASE_FEE,
Keypair,
Server,
Account,
Asset,
Operation,
TransactionBuilder,
} from "stellar-sdk";
import { getErrorMessage } from "../helpers/getErrorMessage";
import { getErrorString } from "../helpers/getErrorString";
import { getNetworkConfig } from "../helpers/getNetworkConfig";
Expand All @@ -12,7 +20,7 @@ export const submitPaymentTransaction = async ({
params: PaymentTransactionParams;
secretKey: string;
}) => {
const server = new StellarSdk.Server(getNetworkConfig().url);
const server = new Server(getNetworkConfig().url);

log.instruction({
title: `Sending payment of ${params.amount} ${params.assetCode}`,
Expand Down Expand Up @@ -79,16 +87,16 @@ export const buildPaymentTransaction = async ({
publicKey,
} = params;
const { sequence } = await server.loadAccount(publicKey);
const source = await new StellarSdk.Account(publicKey, sequence);
const source = await new Account(publicKey, sequence);
let operation;

if (isDestinationFunded) {
const asset =
!assetCode || assetCode === "XLM"
? StellarSdk.Asset.native()
: new StellarSdk.Asset(assetCode, assetIssuer);
? Asset.native()
: new Asset(assetCode, assetIssuer);

operation = StellarSdk.Operation.payment({
operation = Operation.payment({
destination,
asset,
amount: amount.toString(),
Expand All @@ -100,13 +108,13 @@ export const buildPaymentTransaction = async ({
});

// If destination account is not funded, create and fund it
operation = StellarSdk.Operation.createAccount({
operation = Operation.createAccount({
destination,
startingBalance: amount.toString(),
});
}

transaction = new StellarSdk.TransactionBuilder(source, {
transaction = new TransactionBuilder(source, {
fee: BASE_FEE,
networkPassphrase: getNetworkConfig().network,
timebounds: await server.fetchTimebounds(100),
Expand Down
5 changes: 3 additions & 2 deletions packages/demo-wallet-shared/methods/trustAsset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import StellarSdk, {
import {
TransactionBuilder,
BASE_FEE,
Operation,
Asset,
Keypair,
Server,
} from "stellar-sdk";
import { getErrorMessage } from "../helpers/getErrorMessage";
import { log } from "../helpers/log";
Expand All @@ -25,7 +26,7 @@ export const trustAsset = async ({
title: `Adding \`${untrustedAsset.assetCode}:${untrustedAsset.assetIssuer}\` trustline`,
});
const keypair = Keypair.fromSecret(secretKey);
const server = new StellarSdk.Server(networkUrl);
const server = new Server(networkUrl);

log.instruction({
title:
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-wallet-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lodash": "^4.17.21",
"marked": "^7.0.3",
"rimraf": "^5.0.1",
"stellar-sdk": "^10.4.1",
"stellar-sdk": "^11.0.0-beta.3",
"toml": "^3.0.0",
"tslib": "^2.6.1",
"typescript": "~5.1.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-wallet-shared/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export interface LogsInitialState {
}

export interface SendPaymentInitialState {
data: Horizon.TransactionResponse | null;
data: Horizon.SubmitTransactionResponse | null;
errorString?: string;
status: ActionStatus | undefined;
}
Expand Down
Loading

0 comments on commit cf50ec8

Please sign in to comment.