Skip to content
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

revert wallet level historical balance call #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Reverted

- Remove `listHistoricalBalances` wallet method to avoid confusion.

## [0.1.0] - 2024-08-22

### Added
Expand Down
26 changes: 0 additions & 26 deletions src/coinbase/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
Amount,
CreateTransferOptions,
CreateTradeOptions,
ListHistoricalBalancesOptions,
ListHistoricalBalancesResult,
SeedData,
ServerSignerStatus,
StakeOptionsMode,
Expand Down Expand Up @@ -415,30 +413,6 @@ export class Wallet {
return await this.getDefaultAddress()!.historicalStakingBalances(assetId, startTime, endTime);
}

/**
* Lists the historical balances for a given asset belonging to the default address of the wallet.
*
* @param options - The options to list historical balances.
* @param options.assetId - The asset ID.
* @param options.limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
* @param options.page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
* @returns The list of historical balance of the asset and next page token.
*/
public async listHistoricalBalances({
assetId,
limit,
page,
}: ListHistoricalBalancesOptions): Promise<ListHistoricalBalancesResult> {
if (!this.getDefaultAddress()) {
throw new InternalError("Default address not found");
}
return await this.getDefaultAddress()!.listHistoricalBalances({
assetId: assetId,
limit: limit,
page: page,
});
}

/**
* Creates a staking operation to stake, signs it, and broadcasts it on the blockchain.
*
Expand Down
58 changes: 0 additions & 58 deletions src/tests/wallet_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Transfer } from "../coinbase/transfer";
import { ServerSignerStatus, StakeOptionsMode, TransferStatus } from "../coinbase/types";
import {
AddressBalanceList,
AddressHistoricalBalanceList,
Address as AddressModel,
Balance as BalanceModel,
TransactionStatusEnum,
Expand Down Expand Up @@ -441,63 +440,6 @@ describe("Wallet Class", () => {
});
});

describe(".listHistoricalBalances", () => {
beforeEach(() => {
const mockHistoricalBalanceResponse: AddressHistoricalBalanceList = {
data: [
{
amount: "1000000",
block_hash: "0x0dadd465fb063ceb78babbb30abbc6bfc0730d0c57a53e8f6dc778dafcea568f",
block_height: "12345",
asset: {
asset_id: "usdc",
network_id: Coinbase.networks.EthereumHolesky,
decimals: 6,
},
},
{
amount: "5000000",
block_hash: "0x5c05a37dcb4910b22a775fc9480f8422d9d615ad7a6a0aa9d8778ff8cc300986",
block_height: "67890",
asset: {
asset_id: "usdc",
network_id: Coinbase.networks.EthereumHolesky,
decimals: 6,
},
},
],
has_more: false,
next_page: "",
};
Coinbase.apiClients.externalAddress = externalAddressApiMock;
Coinbase.apiClients.externalAddress!.listAddressHistoricalBalance = mockReturnValue(
mockHistoricalBalanceResponse,
);
});

it("should throw an error when the wallet does not have a default address", async () => {
const newWallet = Wallet.init(walletModel);
await expect(
async () =>
await newWallet.listHistoricalBalances({
assetId: Coinbase.assets.Usdc,
}),
).rejects.toThrow(InternalError);
});

it("should successfully return historical balances", async () => {
const wallet = await Wallet.create({ networkId: Coinbase.networks.EthereumHolesky });
Coinbase.apiClients.asset!.getAsset = getAssetMock();
const response = await wallet.listHistoricalBalances({
assetId: Coinbase.assets.Usdc,
});
expect(response.historicalBalances.length).toEqual(2);
expect(response.historicalBalances[0].amount).toEqual(new Decimal(1));
expect(response.historicalBalances[1].amount).toEqual(new Decimal(5));
expect(response.nextPageToken).toEqual("");
});
});

describe(".createTransfer", () => {
let weiAmount, destination, intervalSeconds, timeoutSeconds;
let balanceModel: BalanceModel;
Expand Down
Loading