Skip to content

Update rewards api #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Update rewards api #12

wants to merge 2 commits into from

Conversation

lizard-boy
Copy link

What changed? Why?

Rewards api changes

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

Qualified Impact

Copy link

@greptile-apps greptile-apps bot left a comment

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

@@ -35,7 +35,7 @@ export class HistoricalBalance {
public static fromModel(model: HistoricalBalanceModel): HistoricalBalance {
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

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

@@ -85,6 +85,7 @@ export class StakingReward {
* @returns The amount.
*/
public amount(): Amount {
if (this.model.amount == "") return 0;
Copy link

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

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

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