Skip to content

Commit

Permalink
stone's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
John-peterson-coinbase committed Aug 12, 2024
1 parent fc8df8c commit e04f3f7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/coinbase/sponsored_send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SponsoredSend {
/**
* Returns the signature of the typed data.
*
* @returns The Keccak256 hash of the typed data.
* @returns The hash of the typed data signature.
*/
getSignature(): string | undefined {
return this.model.signature;
Expand All @@ -50,8 +50,7 @@ export class SponsoredSend {
ethers.toBeArray;
const signature = key.signingKey.sign(ethers.getBytes(this.getTypedDataHash())).serialized;
this.model.signature = signature;
// Removes the '0x' prefix as required by the API.
return signature.slice(2);
return signature;
}

/**
Expand All @@ -60,7 +59,7 @@ export class SponsoredSend {
* @returns if the Sponsored Send has been signed.
*/
isSigned(): boolean {
return this.getSignature() ? true : false;
return !!this.getSignature();
}

/**
Expand Down Expand Up @@ -92,9 +91,10 @@ export class SponsoredSend {
*/
isTerminalState(): boolean {
const status = this.getStatus();
return !status
? false
: [SponsoredSendStatus.COMPLETE, SponsoredSendStatus.FAILED].includes(status);

if (!status) return false;

return [SponsoredSendStatus.COMPLETE, SponsoredSendStatus.FAILED].includes(status);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/coinbase/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ export class Transaction {
*/
isTerminalState(): boolean {
const status = this.getStatus();
return !status
? false
: [TransactionStatus.COMPLETE, TransactionStatus.FAILED].includes(status);

if (!status) return false;

return [TransactionStatus.COMPLETE, TransactionStatus.FAILED].includes(status);
}

/**
Expand Down Expand Up @@ -145,7 +146,7 @@ export class Transaction {
* @returns The Signed Payload
*/
getSignature(): string | undefined {
return this.getSignedPayload();
return this.getSignedPayload()?.slice(2);
}

/**
Expand All @@ -154,7 +155,7 @@ export class Transaction {
* @returns if the transaction has been signed.
*/
isSigned(): boolean {
return this.getSignature() ? true : false;
return !!this.getSignature();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/coinbase/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class Transfer {
throw new Error("Cannot broadcast unsigned Transfer");

const broadcastTransferRequest = {
signed_payload: this.getSendTransactionDelegate()!.getSignature()!.slice(2),
signed_payload: this.getSendTransactionDelegate()!.getSignature()!,
};

const response = await Coinbase.apiClients.transfer!.broadcastTransfer(
Expand Down
2 changes: 1 addition & 1 deletion src/tests/sponsored_send_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe("SponsoredSend", () => {
});

it("sets the signature", () => {
expect(sponsoredSend.getSignature().slice(2)).toEqual(signature);
expect(sponsoredSend.getSignature()).toEqual(signature);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/tests/transfer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe("Transfer Class", () => {
},
});
const signature = await transfer.sign(signingKey);
expect(signature).toEqual(transfer.getTransaction()!.getSignature()!.slice(2));
expect(signature).toEqual(transfer.getTransaction()!.getSignature()!);
});
});

Expand Down

0 comments on commit e04f3f7

Please sign in to comment.