Skip to content

Commit

Permalink
fix: get-starknet execute txn not working in firefox (#242)
Browse files Browse the repository at this point in the history
* fix: firefox undefined issue

* fix: lint style
  • Loading branch information
stanleyyconsensys authored May 22, 2024
1 parent 9c0a282 commit 634152d
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions packages/get-starknet/src/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ export class MetaMaskSnap {
signerAddress: string,
transactions: Call[],
transactionsDetail: InvocationsSignerDetails,
abis?: Abi[] | undefined,
abis?: Abi[],
): Promise<Signature> {
return (await this.#provider.request({
method: 'wallet_invokeSnap',
params: {
snapId: this.#snapId,
request: {
method: 'starkNet_signTransaction',
params: {
params: this.removeUndefined({
signerAddress,
transactions,
transactionsDetail,
abis: abis,
...(await this.#getSnapParams()),
},
}),
},
},
})) as Signature;
Expand All @@ -75,11 +75,11 @@ export class MetaMaskSnap {
snapId: this.#snapId,
request: {
method: 'starkNet_signDeployAccountTransaction',
params: {
params: this.removeUndefined({
signerAddress,
transaction,
...(await this.#getSnapParams()),
},
}),
},
},
})) as Signature;
Expand All @@ -92,11 +92,11 @@ export class MetaMaskSnap {
snapId: this.#snapId,
request: {
method: 'starkNet_signDeclareTransaction',
params: {
params: this.removeUndefined({
signerAddress,
transaction,
...(await this.#getSnapParams()),
},
}),
},
},
})) as Signature;
Expand All @@ -105,7 +105,7 @@ export class MetaMaskSnap {
async execute(
senderAddress: string,
txnInvocation: AllowArray<Call>,
abis?: Abi[] | undefined,
abis?: Abi[],
invocationsDetails?: InvocationsDetails,
): Promise<InvokeFunctionResponse> {
return (await this.#provider.request({
Expand All @@ -114,13 +114,13 @@ export class MetaMaskSnap {
snapId: this.#snapId,
request: {
method: 'starkNet_executeTxn',
params: {
params: this.removeUndefined({
senderAddress,
txnInvocation,
abis,
invocationsDetails,
abis,
...(await this.#getSnapParams()),
},
}),
},
},
})) as InvokeFunctionResponse;
Expand All @@ -133,12 +133,12 @@ export class MetaMaskSnap {
snapId: this.#snapId,
request: {
method: 'starkNet_signMessage',
params: {
params: this.removeUndefined({
signerAddress,
typedDataMessage,
enableAuthorize: enableAuthorize,
...(await this.#getSnapParams()),
},
}),
},
},
})) as Signature;
Expand All @@ -155,12 +155,12 @@ export class MetaMaskSnap {
snapId: this.#snapId,
request: {
method: 'starkNet_declareContract',
params: {
params: this.removeUndefined({
senderAddress,
contractPayload,
invocationsDetails,
...(await this.#getSnapParams()),
},
}),
},
},
})) as DeclareContractResponse;
Expand Down Expand Up @@ -236,12 +236,12 @@ export class MetaMaskSnap {
snapId: this.#snapId,
request: {
method: 'starkNet_addNetwork',
params: {
params: this.removeUndefined({
networkName: chainName,
networkChainId: chainId,
networkNodeUrl: rpcUrl,
networkVoyagerUrl: explorerUrl,
},
}),
},
},
})) as boolean;
Expand All @@ -254,12 +254,12 @@ export class MetaMaskSnap {
snapId: this.#snapId,
request: {
method: 'starkNet_addErc20Token',
params: {
params: this.removeUndefined({
tokenAddress: address,
tokenName: name,
tokenSymbol: symbol,
tokenDecimals: decimals,
},
}),
},
},
}) as unknown as boolean;
Expand Down Expand Up @@ -350,4 +350,9 @@ export class MetaMaskSnap {
return false;
}
}

removeUndefined(obj: Record<string, unknown>) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined));
}
}

0 comments on commit 634152d

Please sign in to comment.