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: Handle transactions after NAJ update to v4.0.x for WalletConnect #1205

Merged
merged 2 commits into from
Oct 4, 2024
Merged
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
24 changes: 22 additions & 2 deletions packages/wallet-connect/src/lib/wallet-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ const disconnect = async ({ state }: { state: WalletConnectState }) => {
});
};

const getSignatureData = (result: Uint8Array) => {
if (result instanceof Uint8Array) {
return result;
} else if (Array.isArray(result)) {
return new Uint8Array(result);
} else if (typeof result === "object" && result !== null) {
return new Uint8Array(Object.values(result));
} else {
throw new Error("Unexpected result type from near_signTransaction");
}
};

const WalletConnect: WalletBehaviourFactory<
BridgeWallet,
{ params: WalletConnectExtraOptions }
Expand Down Expand Up @@ -354,7 +366,11 @@ const WalletConnect: WalletBehaviourFactory<
},
});

return nearAPI.transactions.SignedTransaction.decode(Buffer.from(result));
const signatureData = getSignatureData(result);

return nearAPI.transactions.SignedTransaction.decode(
Buffer.from(signatureData)
);
};

const requestSignTransactions = async (transactions: Array<Transaction>) => {
Expand Down Expand Up @@ -408,7 +424,11 @@ const WalletConnect: WalletBehaviourFactory<
});

return results.map((result) => {
return nearAPI.transactions.SignedTransaction.decode(Buffer.from(result));
const signatureData = getSignatureData(result);

return nearAPI.transactions.SignedTransaction.decode(
Buffer.from(signatureData)
);
});
};

Expand Down
Loading