Skip to content

Commit

Permalink
Undefined -> null (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
panieldark authored Nov 29, 2023
1 parent 35df61f commit 21b3781
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-glasses-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nocturne-xyz/frontend-sdk": major
---

Firefox fix
8 changes: 4 additions & 4 deletions packages/client/src/snapJsonRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface SetSpendKeyMethod {
spendKey: string;
eoaAddress: Address;
};
return: string | undefined; // error string or undefined
return: string | null; // error string or null
}

export interface SignCanonAddrRegistryEntryMethod {
Expand All @@ -46,8 +46,8 @@ export interface SignOperationMethod {

export interface RequestSpendKeyEoaMethod {
method: "nocturne_requestSpendKeyEoa";
params: undefined;
return: Address | undefined;
params: null;
return: Address | null;
}

export interface RequestViewingKeyMethodResponse {
Expand All @@ -57,7 +57,7 @@ export interface RequestViewingKeyMethodResponse {

export interface RequestViewingKeyMethod {
method: "nocturne_requestViewingKey";
params: undefined;
params: null;
return: RequestViewingKeyMethodResponse;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/frontend-sdk/src/metamask/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ export class SnapStateSdk {
request: Omit<RpcMethod, "return">,
): Promise<RpcMethod["return"]> {
console.log("[fe-sdk] invoking snap method:", request.method);
const stringifiedParams = request.params
? stringifyObjectValues(request.params)
: undefined;
const jsonRpcRequest = {
method: "wallet_invokeSnap",
params: {
snapId: this.snapId,
request: {
method: request.method,
params: stringifiedParams,
...(request.params && {
params: stringifyObjectValues(request.params),
}),
},
},
};

const response = await window.ethereum.request<{ res: string | null }>(
jsonRpcRequest,
);
Expand Down Expand Up @@ -121,7 +121,7 @@ export class SnapStateSdk {
// Return early if spend key already set
const spendKeyEoa = await this.invoke<RequestSpendKeyEoaMethod>({
method: "nocturne_requestSpendKeyEoa",
params: undefined,
params: null,
});
if (spendKeyEoa) {
return;
Expand Down
45 changes: 28 additions & 17 deletions packages/frontend-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class NocturneSdk {
this.clientThunk = thunk(async () => {
const { vk, vkNonce } = await this.snap.invoke<RequestViewingKeyMethod>({
method: "nocturne_requestViewingKey",
params: undefined,
params: null,
});

const viewer = new NocturneViewer(vk, vkNonce);
Expand Down Expand Up @@ -344,7 +344,7 @@ export class NocturneSdk {

const address = await this.snap.invoke<RequestSpendKeyEoaMethod>({
method: "nocturne_requestSpendKeyEoa",
params: undefined,
params: null,
});
if (!address) {
throw new Error("Nocturne spend key EOA not found");
Expand Down Expand Up @@ -438,20 +438,24 @@ export class NocturneSdk {
return this.formDepositHandlesWithTxReceipt(tx);
}

async prepareOperation(
{ request, meta }: OperationRequestWithMetadata
): Promise<OpWithMetadata<PreSignOperation>> {
async prepareOperation({
request,
meta,
}: OperationRequestWithMetadata): Promise<OpWithMetadata<PreSignOperation>> {
const client = await this.clientThunk();
const op = await client.prepareOperation(request, this.opGasMultiplier);
const op = await client.prepareOperation(request, this.opGasMultiplier);
return {
op,
metadata: meta,
};
}

async signOperation(
{ op, metadata }: OpWithMetadata<PreSignOperation>,
): Promise<OpWithMetadata<SignedOperation>> {
async signOperation({
op,
metadata,
}: OpWithMetadata<PreSignOperation>): Promise<
OpWithMetadata<SignedOperation>
> {
const _op = await this.snap.invoke<SignOperationMethod>({
method: "nocturne_signOperation",
params: { op, metadata },
Expand All @@ -460,17 +464,24 @@ export class NocturneSdk {
return { op: _op, metadata };
}

async proveOperation(
{ op, metadata }: OpWithMetadata<SignedOperation>,
): Promise<OpWithMetadata<SubmittableOperationWithNetworkInfo>> {
async proveOperation({
op,
metadata,
}: OpWithMetadata<SignedOperation>): Promise<
OpWithMetadata<SubmittableOperationWithNetworkInfo>
> {
const prover = await this.joinSplitProverThunk();
const _op = await proveOperation(prover, op);
return { op: _op, metadata };
}

async performOperation(
{ op, metadata }: OpWithMetadata<PreSignOperation> | OpWithMetadata<SignedOperation> | OpWithMetadata<SubmittableOperationWithNetworkInfo>
): Promise<OperationHandle> {
async performOperation({
op,
metadata,
}:
| OpWithMetadata<PreSignOperation>
| OpWithMetadata<SignedOperation>
| OpWithMetadata<SubmittableOperationWithNetworkInfo>): Promise<OperationHandle> {
const client = await this.clientThunk();

const kind = getOperationKind(op);
Expand Down Expand Up @@ -658,7 +669,7 @@ export class NocturneSdk {
default:
throw new Error(`Unsupported protocol: ${protocol}`);
}
}
}

async verifyProvenOperation(operation: ProvenOperation): Promise<boolean> {
const opDigest = OperationTrait.computeDigest(operation);
Expand Down Expand Up @@ -865,7 +876,7 @@ export class NocturneSdk {
// get EOA address from snap
const eoaAddr = await this.snap.invoke<RequestSpendKeyEoaMethod>({
method: "nocturne_requestSpendKeyEoa",
params: undefined,
params: null,
});

if (!eoaAddr) {
Expand Down

0 comments on commit 21b3781

Please sign in to comment.