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

chore(blookbook): rename token type to standard #16286

Open
wants to merge 2 commits into
base: develop
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
10 changes: 8 additions & 2 deletions packages/blockchain-link-types/src/blockbook-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* Do not change, this code is generated from Golang structs */
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this file should not be changed manually as it originates from Blockbook repo. Make the necessary changes in blockbook.ts file instead (if they're really necessary, which may not be this case; see the main comment).


import { TokenStandard } from './common';

export interface APIError {
Text: string;
Public: boolean;
Expand Down Expand Up @@ -125,7 +127,7 @@ export interface StakingPool {
autocompoundBalance: string;
}
export interface ContractInfo {
type: string;
standard: string;
contract: string;
name: string;
symbol: string;
Expand All @@ -134,7 +136,11 @@ export interface ContractInfo {
destructedInBlock?: number;
}
export interface Token {
type: 'XPUBAddress' | 'ERC20' | 'ERC721' | 'ERC1155' | 'BEP20' | 'BEP721' | 'BEP1155';
standard: TokenStandard;
/**
* @deprecated Use `standard` instead.
*/
type?: TokenStandard;
name: string;
path?: string;
contract?: string;
Expand Down
34 changes: 33 additions & 1 deletion packages/blockchain-link-types/src/blockbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ type BlockFiltersBatch = `${string}:${string}:${string}`[];

// XPUBAddress, ERC20, ERC721, ERC1155 - blockbook generated type (Token) is not strict enough
export type XPUBAddress = {
/**
* @deprecated Use `standard` instead.
*/
type: 'XPUBAddress';
standard: 'XPUBAddress';
} & Required<Pick<BlockbookToken, 'path' | 'decimals' | 'balance'>> &
Pick<BlockbookToken, 'name' | 'transfers'>;

Expand All @@ -77,27 +81,51 @@ type BaseERC = Required<Pick<BlockbookToken, 'contract'>> &
Pick<BlockbookToken, 'name' | 'symbol' | 'decimals'>;

export type ERC20 = BaseERC & {
/**
* @deprecated Use `standard` instead.
*/
type: 'ERC20';
standard: 'ERC20';
} & Pick<BlockbookToken, 'balance' | 'baseValue' | 'secondaryValue'>;

export type ERC721 = BaseERC & {
/**
* @deprecated Use `standard` instead.
*/
type: 'ERC721';
standard: 'ERC721';
} & Required<Pick<BlockbookToken, 'ids'>>;

export type ERC1155 = BaseERC & {
/**
* @deprecated Use `standard` instead.
*/
type: 'ERC1155';
standard: 'ERC1155';
} & Required<Pick<BlockbookToken, 'multiTokenValues'>>;

export type BEP20 = BaseERC & {
/**
* @deprecated Use `standard` instead.
*/
type: 'BEP20';
standard: 'BEP20';
} & Pick<BlockbookToken, 'balance' | 'baseValue' | 'secondaryValue'>;

export type BEP721 = BaseERC & {
/**
* @deprecated Use `standard` instead.
*/
type: 'BEP721';
standard: 'BEP721';
} & Required<Pick<BlockbookToken, 'ids'>>;

export type BEP1155 = BaseERC & {
/**
* @deprecated Use `standard` instead.
*/
type: 'BEP1155';
standard: 'BEP1155';
} & Required<Pick<BlockbookToken, 'multiTokenValues'>>;

export interface AccountInfo {
Expand Down Expand Up @@ -137,7 +165,11 @@ export interface EthereumInternalTransfer {
export interface Transaction extends BlockbookTx {
fees: string; // optional in Tx, seems to always be there
tokenTransfers?: (BlockbookTokenTransfer & {
type: TokenStandard; // string in Tx, seems to always be ERC20 | ERC721 | ERC1155
standard: TokenStandard; // string in Tx, seems to always be ERC20 | ERC721 | ERC1155
/**
* @deprecated Use `standard` instead.
*/
type: TokenStandard;
})[];
}

Expand Down
4 changes: 4 additions & 0 deletions packages/blockchain-link-types/src/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ export interface AssetBalance {
}

export type BlockfrostToken = {
standard: 'BLOCKFROST';
/**
* @deprecated Use `standard` instead.
*/
type: 'BLOCKFROST';
name: string; // from unit or fingerprint
contract: string; // unit
Expand Down
9 changes: 7 additions & 2 deletions packages/blockchain-link-types/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export type TokenStandard =
| 'ERC1155'
| 'BEP1155'
| 'SPL'
| 'SPL-2022';
| 'SPL-2022'
| 'BLOCKFROST';

export type TransferType = 'sent' | 'recv' | 'self' | 'unknown';

Expand Down Expand Up @@ -201,7 +202,11 @@ export interface TokenAccount {
}

export interface TokenInfo extends Partial<Pick<Token, 'multiTokenValues' | 'ids'>> {
type: string; // token type: ERC20...
standard: string; // token type: ERC20...
/**
* @deprecated Use `standard` instead.
*/
type?: string;
contract: string; // token address, token unit for ADA
balance?: string; // token balance
name?: string; // token name
Expand Down
6 changes: 3 additions & 3 deletions packages/blockchain-link-utils/src/blockbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const filterTokenTransfers = (
type,
decimals: transfer.decimals || 0,
amount: transfer.value || '',
standard: transfer.type,
standard: transfer.standard,
};
delete tokenTransfer.value;

Expand Down Expand Up @@ -309,7 +309,7 @@ export const transformTokenInfo = (
): TokenInfo[] | undefined => {
if (!tokens || !Array.isArray(tokens)) return undefined;
const info = tokens.reduce((arr, token) => {
if (token.type === 'XPUBAddress') return arr;
if (token.standard === 'XPUBAddress') return arr;

return arr.concat([
{
Expand All @@ -327,7 +327,7 @@ export const transformAddresses = (
): AccountAddresses | undefined => {
if (!tokens || !Array.isArray(tokens)) return undefined;
const addresses = tokens.reduce((arr, t) => {
if (t.type !== 'XPUBAddress') return arr;
if (t.standard !== 'XPUBAddress') return arr;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit funny to have token standard XPUBAddress, but it was funny even as token type, so this is no problem. But, as there's no backend data transformation up to this point, field standard is never there so BTC accounts have no addresses and therefore are not shown in Suite (at least in my case 🤷‍♂️)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, well XPUBAddress is there under "type" even in blockbook, alongside with ERC types...

Also for me Bitcoin accounts are displayed but they are empty, so maybe that's why I didn't notice the bug, will investigate

Copy link
Contributor

Choose a reason for hiding this comment

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

XPUBAddress is there under "type" even in blockbook

Yes I know, that's fine. But if they're coming with type, we can't detect them based on standard.


return arr.concat([
{
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-link-utils/src/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const transformTokenInfo = (
}

const info = tokens.map(token => ({
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
Copy link
Contributor

Choose a reason for hiding this comment

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

If we wanna make the whole deprecation thing in a non-breaking way (which I don't insist on), all the currently outgoing data must be preserved and some new may be added => we want to signal that type can no longer be relied on, but it's not possible to remove it yet.

balance: token.quantity,
...transformToken(token),
}));
Expand Down
6 changes: 3 additions & 3 deletions packages/blockchain-link-utils/src/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const transformTokenInfo = (
} = tokenAccount.account.data;

return {
type: tokenProgramsInfo[program].tokenStandard,
standard: tokenProgramsInfo[program].tokenStandard,
Copy link
Contributor

Choose a reason for hiding this comment

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

dtto

contract: info.mint,
balance: info.tokenAmount.amount,
decimals: info.tokenAmount.decimals,
Expand All @@ -171,9 +171,9 @@ export const transformTokenInfo = (
balance: token.balance || '0',
});
} else {
const { type, contract, balance, decimals, name, symbol } = token;
const { standard, contract, balance, decimals, name, symbol } = token;
acc[token.contract] = {
type,
standard,
contract,
balance,
decimals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const tOut = {

const tIn = {
name: 'Token name',
type: 'ERC20',
standard: 'ERC20',
symbol: 'TN',
contract: '0x0',
value: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default {
],
result: [
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
fingerprint: 'asset1hwnpal5vap799t6kkjmjf6myhse4zl2vu4ahzz',
policyId: 'b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f',
symbol: 'BerrySapphire',
Expand All @@ -163,7 +163,7 @@ export default {
'b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f42657272795361707068697265',
},
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
decimals: 0,
fingerprint: 'asset108xu02ckwrfc8qs9d97mgyh4kn8gdu9w8f5sxk',
name: 'Snek',
Expand All @@ -173,7 +173,7 @@ export default {
contract: '279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f534e454b',
},
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
fingerprint: 'asset1zvclg2cvj4e5jfz5vswf3sx0lasy79xn8cdap9',
policyId: '02477d7c23b4c2834b0be8ca8578dde47af0cc82a964688f6fc95a7a',
symbol: 'GRIC',
Expand Down Expand Up @@ -514,7 +514,7 @@ export default {
},
tokens: [
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
fingerprint: 'asset1eevmdlaz5424s3663ypw8w4vyxdlxkm3lefz06',
contract:
'2f712364ec46f0cf707d412106ce71ef3370f76e27fb56b6bb14708776657465726e696b4e657a6a6564656e79',
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain-link-utils/src/tests/fixtures/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ export const fixtures = {
},
expectedOutput: [
{
type: 'SPL',
standard: 'SPL',
contract: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
balance: '2000000',
decimals: 6,
Expand All @@ -963,7 +963,7 @@ export const fixtures = {
},
expectedOutput: [
{
type: 'SPL',
standard: 'SPL',
contract: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
balance: '3000000',
decimals: 6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ const fixtures: {
unconfirmedTxs: 0,
tokens: [
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
path: "m/44'/0'/100'/1/0",
name: '1J8tVQD9KZZeLhnkMRHHDawsYmwjWAnC5d',
transfers: 0,
},
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
path: "m/44'/0'/100'/0/0",
name: '19SW698tGLusJZVBmGDYmHvSwn79WqJP65',
transfers: 0,
Expand Down Expand Up @@ -144,7 +144,7 @@ const fixtures: {
txs: 1,
tokens: [
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
path: "m/44'/0'/100'/1/0",
name: '1J8tVQD9KZZeLhnkMRHHDawsYmwjWAnC5d',
transfers: 1,
Expand Down Expand Up @@ -257,13 +257,13 @@ const fixtures: {
txs: 2,
tokens: [
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
path: "m/44'/0'/100'/1/0",
name: '1J8tVQD9KZZeLhnkMRHHDawsYmwjWAnC5d',
transfers: 2,
},
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
path: "m/44'/0'/100'/1/1",
name: '1RXiBGixLSBRAAXtZMsCx75EuFqqJnmXZ',
transfers: 1,
Expand Down Expand Up @@ -455,7 +455,7 @@ const fixtures: {
nonTokenTxs: 0,
tokens: [
{
type: 'ERC20',
standard: 'ERC20',
name: 'Token name',
symbol: 'TKNNME',
contract: '0x0',
Expand All @@ -475,7 +475,7 @@ const fixtures: {
},
tokens: [
{
type: 'ERC20',
standard: 'ERC20',
name: 'Token name',
symbol: 'TKNNME',
contract: '0x0',
Expand Down Expand Up @@ -599,7 +599,7 @@ const fixtures: {
nonce: '100',
address: '0x3c205C8B3e02421Da82064646788c82f7bd753B9',
contractInfo: {
type: 'ERC20',
standard: 'ERC20',
contract: '0x3c205C8B3e02421Da82064646788c82f7bd753B9',
name: 'PureFi Token',
symbol: 'UFI',
Expand All @@ -618,7 +618,7 @@ const fixtures: {
stakingPools: undefined,
addressAliases: undefined,
contractInfo: {
type: 'ERC20',
standard: 'ERC20',
contract: '0x3c205C8B3e02421Da82064646788c82f7bd753B9',
name: 'PureFi Token',
symbol: 'UFI',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getToken = (contract: string, symbol: string, decimals: number) => ({
contract,
symbol,
decimals,
type: 'ERC20',
standard: 'ERC20',
});

const TOKEN_1 = getToken('0xaea46a60368a7bd060eec7df8cba43b7ef41ad85', 'FET', 6);
Expand Down
8 changes: 4 additions & 4 deletions packages/suite-web/e2e/fixtures/send-form-doge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const DOGE_ACCOUNT = {
usedTokens: 1,
tokens: [
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
name: 'DHoUv6AUXrxadt5GhqK2TLN6Lw4bgKZnjG',
path: "m/44'/3'/0'/0/0",
transfers: 1,
Expand All @@ -92,21 +92,21 @@ const DOGE_ACCOUNT = {
totalSent: '0',
},
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
name: 'DBNkNukxRcH6QTPSp69KhVHQWkUpVLotWs',
path: "m/44'/3'/0'/0/1",
transfers: 0,
decimals: 8,
},
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
name: 'DCsP6RCfFHvTKFRocJEoW1CjYEPMk9pk3i',
path: "m/44'/3'/0'/1/0",
transfers: 0,
decimals: 8,
},
{
type: 'XPUBAddress',
standard: 'XPUBAddress',
name: 'DMRZ3D9ppogDQoY7AUCLy5EaRTTEv6xJ5f',
path: "m/44'/3'/0'/1/1",
transfers: 0,
Expand Down
Loading
Loading