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

Fix/typescript bindings #1066

Merged
merged 3 commits into from
Nov 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dependencies": {
"@stellar/freighter-api": "1.5.1",
"buffer": "6.0.3",
"soroban-client": "1.0.0-beta.2"
"soroban-client": "1.0.0-beta.3"
},
"scripts": {
"build": "node ./scripts/build.mjs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {

export type Tx = Transaction<Memo<MemoType>, Operation[]>;

export class SendFailedError extends Error { }
elizabethengelman marked this conversation as resolved.
Show resolved Hide resolved
/**
* Get account details from the Soroban network for the publicKey currently
* selected in Freighter. If not connected to Freighter, return null.
Expand Down Expand Up @@ -82,7 +83,7 @@ export async function invoke<R extends ResponseTypes, T = string>({
contractId,
wallet,
}: InvokeArgs<R, T>): Promise<T | string | SomeRpcResponse> {
wallet = wallet ?? (await import("@stellar/freighter-api"));
wallet = wallet ?? (await import("@stellar/freighter-api")).default;
let parse = parseResultXdr;
const server = new SorobanClient.Server(rpcUrl, {
allowHttp: rpcUrl.startsWith("http://"),
Expand Down Expand Up @@ -162,7 +163,11 @@ export async function invoke<R extends ResponseTypes, T = string>({
if ("returnValue" in raw) return parse(raw.returnValue!);

// otherwise, it returned the result of `sendTransaction`
if ("errorResultXdr" in raw) return parse(raw.errorResultXdr!);
if ("errorResult" in raw) {
throw new SendFailedError(
`errorResult.result(): ${JSON.stringify(raw.errorResult?.result())}`
)
}

// if neither of these are present, something went wrong
console.error("Don't know how to parse result! Returning full RPC response.");
Expand Down
Loading