Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/5.6.0 #954

Merged
merged 5 commits into from
Sep 13, 2023
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
27 changes: 27 additions & 0 deletions @shared/api/helpers/soroban.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { xdr, Address, ScInt, scValToBigInt } from "soroban-client";

export const accountIdentifier = (account: string) =>
new Address(account).toScVal();

export const valueToI128String = (value: xdr.ScVal) =>
scValToBigInt(value).toString();

// How do we decode these in a more generic way?
export const decodei128 = (b64: string) => {
const value = xdr.ScVal.fromXDR(b64, "base64");
try {
return valueToI128String(value);
} catch (error) {
console.error(error);
return 0;
}
};

export const decodeStr = (b64: string) =>
xdr.ScVal.fromXDR(b64, "base64").str().toString();

export const decodeU32 = (b64: string) =>
xdr.ScVal.fromXDR(b64, "base64").u32();

export const numberToI128 = (value: number): xdr.ScVal =>
new ScInt(value).toI128();
15 changes: 13 additions & 2 deletions @shared/api/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
MAINNET_NETWORK_DETAILS,
DEFAULT_NETWORKS,
NetworkDetails,
SOROBAN_RPC_URLS,
NETWORKS,
SOROBAN_RPC_URLS
} from "../constants/stellar";
import { SERVICE_TYPES } from "../constants/services";
import { APPLICATION_STATE } from "../constants/applicationState";
Expand Down Expand Up @@ -636,7 +637,17 @@ export const submitFreighterSorobanTransaction = async ({
console.error(e);
}

const server = new SorobanClient.Server(SOROBAN_RPC_URLS.FUTURENET!, {
if (!networkDetails.sorobanRpcUrl && networkDetails.network !== NETWORKS.FUTURENET) {
throw new Error("soroban rpc not supported")
}

// TODO: after enough time has passed to assume most clients have ran
// the migrateSorobanRpcUrlNetworkDetails migration, remove and use networkDetails.sorobanRpcUrl
const serverUrl = !networkDetails.sorobanRpcUrl
? SOROBAN_RPC_URLS[NETWORKS.FUTURENET]!
: networkDetails.sorobanRpcUrl

const server = new SorobanClient.Server(serverUrl, {
allowHttp: true,
});

Expand Down
1 change: 1 addition & 0 deletions @shared/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface Response {
isValidatingSafeAssetsEnabled: boolean;
isExperimentalModeEnabled: boolean;
networkDetails: NetworkDetails;
sorobanRpcUrl: string;
networksList: NetworkDetails[];
allAccounts: Array<Account>;
accountName: string;
Expand Down
1 change: 1 addition & 0 deletions @shared/constants/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface NetworkDetails {
networkUrl: string;
networkPassphrase: string;
friendbotUrl?: string;
sorobanRpcUrl?: string
}

export const MAINNET_NETWORK_DETAILS: NetworkDetails = {
Expand Down
2 changes: 2 additions & 0 deletions @shared/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }
21 changes: 21 additions & 0 deletions extension/src/background/helpers/dataStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NETWORKS,
TESTNET_NETWORK_DETAILS,
FUTURENET_NETWORK_DETAILS,
SOROBAN_RPC_URLS,
} from "@shared/constants/stellar";

interface SetItemParams {
Expand Down Expand Up @@ -105,3 +106,23 @@ export const migrateFriendBotUrlNetworkDetails = async () => {

await localStore.setItem(NETWORKS_LIST_ID, migratedNetworkList);
};

export const migrateSorobanRpcUrlNetworkDetails = async () => {
const localStore = dataStorageAccess(browserLocalStorage);

const networksList: NetworkDetails[] =
(await localStore.getItem(NETWORKS_LIST_ID)) || DEFAULT_NETWORKS;

const migratedNetworkList = networksList.map((network) => {
if (network.network === NETWORKS.FUTURENET) {
return {
...FUTURENET_NETWORK_DETAILS,
sorobanRpcUrl: SOROBAN_RPC_URLS[NETWORKS.FUTURENET]
}
}

return network;
});

await localStore.setItem(NETWORKS_LIST_ID, migratedNetworkList);
}
2 changes: 2 additions & 0 deletions extension/src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { timeoutAccountAccess } from "./ducks/session";
import {
migrateFriendBotUrlNetworkDetails,
normalizeMigratedData,
migrateSorobanRpcUrlNetworkDetails
} from "./helpers/dataStorage";

export const initContentScriptMessageListener = () => {
Expand Down Expand Up @@ -56,6 +57,7 @@ export const initInstalledListener = () => {
});
browser?.runtime?.onInstalled.addListener(normalizeMigratedData);
browser?.runtime?.onInstalled.addListener(migrateFriendBotUrlNetworkDetails);
browser?.runtime?.onInstalled.addListener(migrateSorobanRpcUrlNetworkDetails);
};

export const initAlarmListener = (sessionStore: Store) => {
Expand Down
31 changes: 24 additions & 7 deletions extension/src/popup/SorobanContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import React from "react";
import { useSelector } from "react-redux";
import * as SorobanClient from "soroban-client";

import { NETWORKS, SOROBAN_RPC_URLS } from "@shared/constants/stellar";
import {
SOROBAN_RPC_URLS,
NETWORKS
} from "@shared/constants/stellar";

import { settingsNetworkDetailsSelector } from "./ducks/settings";

Expand All @@ -28,14 +31,16 @@ export const SorobanProvider = ({
pubKey: string;
}) => {
const networkDetails = useSelector(settingsNetworkDetailsSelector);
const serverUrl = SOROBAN_RPC_URLS[networkDetails.network as NETWORKS];

let server: SorobanContextInterface["server"];
let newTxBuilder: SorobanContextInterface["newTxBuilder"];
let server: SorobanContextInterface['server']
let newTxBuilder: SorobanContextInterface['newTxBuilder']
if (!networkDetails.sorobanRpcUrl && networkDetails.network === NETWORKS.FUTURENET) {
// TODO: after enough time has passed to assume most clients have ran
// the migrateSorobanRpcUrlNetworkDetails migration, remove and use networkDetails.sorobanRpcUrl
const serverUrl = SOROBAN_RPC_URLS[NETWORKS.FUTURENET]!

if (serverUrl) {
server = new SorobanClient.Server(serverUrl, {
allowHttp: networkDetails.networkUrl.startsWith("http://"),
allowHttp: serverUrl.startsWith("http://"),
});

newTxBuilder = async (fee = SorobanClient.BASE_FEE) => {
Expand All @@ -45,8 +50,20 @@ export const SorobanProvider = ({
networkPassphrase: networkDetails.networkPassphrase,
});
};
}
} else if (networkDetails.sorobanRpcUrl) {
server = new SorobanClient.Server(networkDetails.sorobanRpcUrl, {
allowHttp: networkDetails.sorobanRpcUrl.startsWith("http://"),
});

newTxBuilder = async (fee = SorobanClient.BASE_FEE) => {
const sourceAccount = await server!.getAccount(pubKey);
return new SorobanClient.TransactionBuilder(sourceAccount, {
fee,
networkPassphrase: networkDetails.networkPassphrase,
});
};
}

return (
<SorobanContext.Provider value={{ server, newTxBuilder }}>
{children}
Expand Down
26 changes: 26 additions & 0 deletions extension/src/popup/assets/illo-pin-extension.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading