Skip to content

Commit

Permalink
Fix/typescript bindings (#1066)
Browse files Browse the repository at this point in the history
* Use the default freight-api export

* Update soroban-client to 1.0.0-beta.3

* Update error handling in invoke to conform to soroban-client beta.3

(cherry picked from commit e357ccb)
  • Loading branch information
elizabethengelman authored and chadoh committed Nov 8, 2023
1 parent d3f0dc5 commit 4dc709d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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 { }
/**
* 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

0 comments on commit 4dc709d

Please sign in to comment.