Skip to content

Commit

Permalink
default to testnet (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
piyalbasu authored May 30, 2024
1 parent 462c55b commit c29e6ee
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 35 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ The Atomic Swap DApp relies on the following dependencies:

- Freighter wallet(v5.0 or newer): https://www.freighter.app/

You need access to/funds from the following contracts - Atomic Swap:
https://github.com/stellar/soroban-examples/tree/main/atomic_swap Token:
https://github.com/stellar/soroban-examples/tree/main/token
You need access to/funds from the following contracts:

Atomic Swap: https://github.com/stellar/soroban-examples/tree/main/atomic_swap
Token: https://github.com/stellar/soroban-examples/tree/main/token

This demo involves a minimum of 2 parties and 2 different tokens to swap between
the parties.
Expand Down Expand Up @@ -88,8 +89,8 @@ below:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/soroban_atomic_swap_contract.wasm \
--source <ADMIN_ACCOUNT_SECRET_KEY> \
--rpc-url https://rpc-futurenet.stellar.org:443 \
--network-passphrase 'Test SDF Future Network ; October 2022'
--rpc-url https://soroban-testnet.stellar.org \
--network-passphrase 'Test SDF Network ; September 2015'
```

This will return a contract id that we will need to use later on.
Expand Down Expand Up @@ -138,8 +139,8 @@ follow the steps below:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/soroban_token_contract.wasm \
--source <ADMIN_ACCOUNT_SECRET_KEY> \
--rpc-url https://rpc-futurenet.stellar.org:443 \
--network-passphrase 'Test SDF Future Network ; October 2022'
--rpc-url https://soroban-testnet.stellar.org \
--network-passphrase 'Test SDF Network ; September 2015'
```

This will return a contract id that we will need to use later on.
Expand All @@ -153,8 +154,8 @@ CCZZ763JDLSHEXUFUIHIKOVAAKYU2CUXSUH5MP4MH2HDZYGOYMM3RDD5
soroban contract invoke \
--id <TOKEN_A_CONTRACT_ID> \
--source-account <ADMIN_ACCOUNT_SECRET_KEY> \
--rpc-url https://rpc-futurenet.stellar.org:443 \
--network-passphrase 'Test SDF Future Network ; October 2022' \
--rpc-url https://soroban-testnet.stellar.org \
--network-passphrase 'Test SDF Network ; September 2015' \
-- initialize \
--admin <ADMIN_PUBLIC_KEY> \
--decimal 7 \
Expand All @@ -169,8 +170,8 @@ following command:
soroban contract invoke \
--id <TOKEN_A_CONTRACT_ID> \
--source-account <ADMIN_ACCOUNT_SECRET_KEY> \
--rpc-url https://rpc-futurenet.stellar.org:443 \
--network-passphrase 'Test SDF Future Network ; October 2022' \
--rpc-url https://soroban-testnet.stellar.org \
--network-passphrase 'Test SDF Network ; September 2015' \
-- mint \
--to <USER_A_OR_B_PUBLIC_KEY> \
--amount 1000000000
Expand All @@ -191,8 +192,8 @@ _See the example below for initializing and minting the second token contract_
soroban contract invoke \
--id <TOKEN_B_CONTRACT_ID> \
--source-account <ADMIN_ACCOUNT_SECRET_KEY> \
--rpc-url https://rpc-futurenet.stellar.org:443 \
--network-passphrase 'Test SDF Future Network ; October 2022' \
--rpc-url https://soroban-testnet.stellar.org \
--network-passphrase 'Test SDF Network ; September 2015' \
-- initialize \
--admin <ADMIN_PUBLIC_KEY> \
--decimal 7 \
Expand All @@ -206,8 +207,8 @@ soroban contract invoke \
soroban contract invoke \
--id <TOKEN_B_CONTRACT_ID> \
--source-account <ADMIN_ACCOUNT_SECRET_KEY> \
--rpc-url https://rpc-futurenet.stellar.org:443 \
--network-passphrase 'Test SDF Future Network ; October 2022' \
--rpc-url https://soroban-testnet.stellar.org \
--network-passphrase 'Test SDF Network ; September 2015' \
-- mint \
--to <USER_A_OR_B_PUBLIC_KEY> \
--amount 1000000000
Expand Down
18 changes: 12 additions & 6 deletions src/components/atomic-swap/exchange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const Exchange = (props: ExchangeProps) => {
props.swkKit.setWallet(option.type);
const publicKey = await props.swkKit.getPublicKey();

props.swkKit.setNetwork(WalletNetwork.FUTURENET);
props.swkKit.setNetwork(WalletNetwork.TESTNET);
props.setPubKey(publicKey);

setStepCount((stepCount + 1) as StepCount);
Expand Down Expand Up @@ -182,11 +182,17 @@ export const Exchange = (props: ExchangeProps) => {
)
.build();

const _signedXdr = await signTx(
finalTx.toXDR(),
props.pubKey,
props.swkKit,
);
let _signedXdr = "";

try {
_signedXdr = await signTx(
finalTx.toXDR(),
props.pubKey,
props.swkKit,
);
} catch (e) {
console.error(e);
}

try {
const result = await submitTx(
Expand Down
2 changes: 1 addition & 1 deletion src/components/atomic-swap/swapper-A.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const SwapperA = (props: SwapperAProps) => {
props.swkKit.setWallet(option.type);
const publicKey = await props.swkKit.getPublicKey();

await props.swkKit.setNetwork(WalletNetwork.FUTURENET);
await props.swkKit.setNetwork(WalletNetwork.TESTNET);

props.setPubKey(publicKey);
setStepCount((stepCount + 1) as StepCount);
Expand Down
2 changes: 1 addition & 1 deletion src/components/atomic-swap/swapper-B.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const SwapperB = (props: SwapperBProps) => {
props.swkKit.setWallet(option.type);
const publicKey = await props.swkKit.getPublicKey();

props.swkKit.setNetwork(WalletNetwork.FUTURENET);
props.swkKit.setNetwork(WalletNetwork.TESTNET);

const server = getServer(props.networkDetails);
const tx = TransactionBuilder.fromXDR(
Expand Down
9 changes: 4 additions & 5 deletions src/helpers/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export interface NetworkDetails {
networkPassphrase: string;
}

// Soroban is only supported on Futurenet right now
export const FUTURENET_DETAILS = {
network: "FUTURENET",
networkUrl: "https://horizon-futurenet.stellar.org",
networkPassphrase: "Test SDF Future Network ; October 2022",
export const TESTNET_DETAILS = {
network: "TESTNET",
networkUrl: "https://horizon-testnet.stellar.org",
networkPassphrase: "Test SDF Network ; September 2015",
};

export const signData = async (
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/soroban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const SendTxStatus: {
export const BASE_FEE = "100";

export const RPC_URLS: { [key: string]: string } = {
FUTURENET: "https://rpc-futurenet.stellar.org:443",
TESTNET: "https://soroban-testnet.stellar.org",
};

// Given a display value for a token and a number of decimals, return the corresponding BigNumber
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Exchange } from "./components/atomic-swap/exchange";
import { SwapperA } from "./components/atomic-swap/swapper-A";
import { SwapperB } from "./components/atomic-swap/swapper-B";

import { FUTURENET_DETAILS } from "./helpers/network";
import { TESTNET_DETAILS } from "./helpers/network";

import "@stellar/design-system/build/styles.min.css";
import "./index.scss";
Expand All @@ -25,8 +25,8 @@ const App = (props: AppProps) => {
// This is only needed when this component is consumed by other components that display a different header
const hasHeader = props.hasHeader === undefined ? true : props.hasHeader;

// Default to Futurenet network, only supported network for now
const [selectedNetwork] = React.useState(FUTURENET_DETAILS);
// Default to Testnet network
const [selectedNetwork] = React.useState(TESTNET_DETAILS);

// Initial state, empty states for token/transaction details
const [activePubKey, setActivePubKey] = React.useState("");
Expand Down
6 changes: 3 additions & 3 deletions src/sub-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Exchange } from "./components/atomic-swap/exchange";
import { SwapperA } from "./components/atomic-swap/swapper-A";
import { SwapperB } from "./components/atomic-swap/swapper-B";

import { FUTURENET_DETAILS } from "./helpers/network";
import { TESTNET_DETAILS } from "./helpers/network";

import "@stellar/design-system/build/styles.min.css";
import "./index.scss";
Expand All @@ -27,8 +27,8 @@ export const AppSubRouter = (props: AppProps) => {
// This is only needed when this component is consumed by other components that display a different header
const hasHeader = props.hasHeader === undefined ? true : props.hasHeader;

// Default to Futurenet network, only supported network for now
const [selectedNetwork] = React.useState(FUTURENET_DETAILS);
// Default to Testnet network
const [selectedNetwork] = React.useState(TESTNET_DETAILS);

// Initial state, empty states for token/transaction details
const [activePubKey, setActivePubKey] = React.useState("");
Expand Down

0 comments on commit c29e6ee

Please sign in to comment.