Skip to content

Update rewards api - #12

Open
lizard-boy wants to merge 2 commits into
masterfrom
update-rewards-api
Open

Update rewards api#12
lizard-boy wants to merge 2 commits into
masterfrom
update-rewards-api

Conversation

@lizard-boy

Copy link
Copy Markdown

What changed? Why?

Rewards api changes

  • Date field is now a timestamp
  • Handle empty strings as balance amounts

Qualified Impact

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR updates the Coinbase SDK to handle changes in the rewards API, focusing on timestamp formatting and empty balance handling.

  • Updated HistoricalBalance.fromModel() in src/coinbase/historical_balance.ts to handle empty string amounts
  • Modified StakingReward.amount() in src/coinbase/staking_reward.ts to return 0 for empty string amounts
  • Added src/examples/solana_list_rewards.ts demonstrating Solana staking rewards and balances retrieval
  • Updated test files to reflect API changes and new empty string handling
  • Potential issue: Hardcoded future date (2024) in the Solana example script may cause unexpected behavior

5 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

const asset = Asset.fromModel(model.asset);
return new HistoricalBalance(
asset.fromAtomicAmount(new Decimal(model.amount)),
model.amount != "" ? asset.fromAtomicAmount(new Decimal(model.amount)) : new Decimal(0),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using model.amount === '' for strict equality comparison

* @returns The amount.
*/
public amount(): Amount {
if (this.model.amount == "") return 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using strict equality (===) instead of loose equality (==) for consistency with TypeScript best practices.

async function printStakingInfo() {
Coinbase.configureFromJson({ filePath: "~/Downloads/cdp_api_key.json" });

const startTime = new Date(2024, 5).toISOString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Using a future date (2024) as the start time may lead to unexpected results or errors. Consider using a more recent or dynamic start date.

console.log(balances);
}

printStakingInfo();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Function is defined but not exported. If this file is intended to be used as a module, consider exporting the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants