Skip to content

Commit

Permalink
Return false from areBCSArguments function if array is empty (#221)
Browse files Browse the repository at this point in the history
* return false from areBCSArguments function if array is empty

* fix typing
  • Loading branch information
0xmaayan authored Dec 18, 2023
1 parent fee17c2 commit 3f38c51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-numbers-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aptos-labs/wallet-adapter-core": patch
---

Return false from areBCSArguments function if array is empty
18 changes: 15 additions & 3 deletions packages/wallet-adapter-core/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Serializable } from "@aptos-labs/ts-sdk";
import {
EntryFunctionArgumentTypes,
Serializable,
SimpleEntryFunctionArgumentTypes,
} from "@aptos-labs/ts-sdk";

export function isMobile(): boolean {
return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(
Expand Down Expand Up @@ -37,6 +41,14 @@ export function generalizedErrorMessage(error: any): string {
// In @aptos-labs/ts-sdk each move representative class extends
// Serializable, so if each argument is of an instance of a class
// the extends Serializable - we know these are BCS arguments
export const areBCSArguments = (args: any): boolean => {
return args.every((arg: any) => arg instanceof Serializable);
export const areBCSArguments = (
args: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>
): boolean => {
// `every` returns true if the array is empty, so
// first check the array length
if (args.length === 0) return false;
return args.every(
(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes) =>
arg instanceof Serializable
);
};

0 comments on commit 3f38c51

Please sign in to comment.