Skip to content

Commit

Permalink
chore(connect): if duplicated coins, let's check if all are unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Aug 8, 2024
1 parent ecab819 commit fff8e5c
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 8 deletions.
94 changes: 93 additions & 1 deletion packages/connect/src/utils/__tests__/deviceFeaturesUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
parseCapabilities,
parseRevision,
} from '../deviceFeaturesUtils';
import { Features, DeviceModelInternal } from '../../types';
import { Features, DeviceModelInternal, CoinInfo } from '../../types';

describe('utils/deviceFeaturesUtils', () => {
beforeEach(() => {
Expand Down Expand Up @@ -248,6 +248,98 @@ describe('utils/deviceFeaturesUtils', () => {
done();
});
});

it('handles duplicated shortcuts correctly, ', () => {
const customCoins = [
{ shortcut: 'BNB', type: 'ethereum', support: { T2T1: '2.4.4' } },
{ shortcut: 'BNB', type: 'misc', support: { T2T1: '2.3.3' } },
{ shortcut: 'ETH', type: 'ethereum', support: { T2T1: false } },
];
const customFeatures = {
major_version: 2,
minor_version: 3,
patch_version: 3,
capabilities: ['Capability_Bitcoin', 'Capability_Ethereum', 'Capability_Binance'],
internal_model: DeviceModelInternal.T2T1,
} as unknown as Features;

const result = getUnavailableCapabilities(customFeatures, customCoins as CoinInfo[]);

expect(result).toEqual({
eth: 'no-support',
bnb: 'update-required',
amountUnit: 'update-required',
chunkify: 'update-required',
coinjoin: 'update-required',
decreaseOutput: 'update-required',
eip1559: 'update-required',
'eip712-domain-only': 'update-required',
replaceTransaction: 'update-required',
signMessageNoScriptType: 'update-required',
taproot: 'update-required',
});
});

it('handles duplicated shortcuts correctly, does not include bnb: no-support', () => {
const customCoins = [
{ shortcut: 'BNB', type: 'ethereum', support: { T1B1: '1.1.3' } },
{ shortcut: 'BNB', type: 'misc', support: { T1B1: false } },
{ shortcut: 'ETH', type: 'ethereum', support: { T1B1: false } },
];
const customFeatures = {
major_version: 1,
minor_version: 1,
patch_version: 3,
capabilities: ['Capability_Bitcoin', 'Capability_Ethereum'],
internal_model: DeviceModelInternal.T1B1,
} as unknown as Features;

const result = getUnavailableCapabilities(customFeatures, customCoins as CoinInfo[]);

expect(result).toEqual({
eth: 'no-support',
amountUnit: 'update-required',
chunkify: 'no-support',
coinjoin: 'update-required',
decreaseOutput: 'update-required',
eip1559: 'update-required',
'eip712-domain-only': 'update-required',
replaceTransaction: 'update-required',
signMessageNoScriptType: 'update-required',
taproot: 'update-required',
});
});

it('handles duplicated shortcuts correctly, includes no-support because none is supported', () => {
const customCoins = [
{ shortcut: 'BNB', type: 'ethereum', support: { T1B1: false } },
{ shortcut: 'BNB', type: 'misc', support: { T1B1: false } },
{ shortcut: 'ETH', type: 'ethereum', support: { T1B1: false } },
];
const customFeatures = {
major_version: 1,
minor_version: 1,
patch_version: 3,
capabilities: ['Capability_Bitcoin', 'Capability_Ethereum'],
internal_model: DeviceModelInternal.T1B1,
} as unknown as Features;

const result = getUnavailableCapabilities(customFeatures, customCoins as CoinInfo[]);

expect(result).toEqual({
eth: 'no-support',
bnb: 'no-support',
amountUnit: 'update-required',
chunkify: 'no-support',
coinjoin: 'update-required',
decreaseOutput: 'update-required',
eip1559: 'update-required',
'eip712-domain-only': 'update-required',
replaceTransaction: 'update-required',
signMessageNoScriptType: 'update-required',
taproot: 'update-required',
});
});
});

describe('parseRevision', () => {
Expand Down
35 changes: 28 additions & 7 deletions packages/connect/src/utils/deviceFeaturesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,32 @@ export const getUnavailableCapabilities = (features: Features, coins: CoinInfo[]
const fw = [features.major_version, features.minor_version, features.patch_version].join('.');
const key = features.internal_model;

const duplicatedShortcuts = ['bnb']; // relevant duplicated shortcuts from duplicity_overrides.json from fw repo

// 1. check if firmware version is supported by CoinInfo.support
const supported = coins.filter(info => {
// info.support[key] possible types:
// - undefined for unknown models (specified in coins.json)
// - boolean for unsupported models (false)
// - string for supported models (version)
if (!info.support || info.support[key] === false) {
list[info.shortcut.toLowerCase()] = 'no-support';

return false;
const shortcut = info.shortcut.toLowerCase();
if (!duplicatedShortcuts.includes(shortcut)) {
list[shortcut] = 'no-support';

return false;
} else {
const occurrences = coins.filter(coin => shortcut == coin.shortcut.toLowerCase());
const allUnsupported = occurrences.every(
info => !info.support || info.support[key] === false,
);

if (allUnsupported) {
list[shortcut] = 'no-support';
}

return false;
}
}

return true;
Expand All @@ -77,13 +93,18 @@ export const getUnavailableCapabilities = (features: Features, coins: CoinInfo[]
return !capabilities.includes('Capability_NEM');
}
// misc
if (info.shortcut === 'BNB') return !capabilities.includes('Capability_Binance');
if (info.shortcut === 'ADA' || info.shortcut === 'tADA')
if (info.shortcut === 'BNB' && info.type === 'misc') {
return !capabilities.includes('Capability_Binance');
}
if (info.shortcut === 'ADA' || info.shortcut === 'tADA') {
return !capabilities.includes('Capability_Cardano');
if (info.shortcut === 'XRP' || info.shortcut === 'tXRP')
}
if (info.shortcut === 'XRP' || info.shortcut === 'tXRP') {
return !capabilities.includes('Capability_Ripple');
if (info.shortcut === 'SOL' || info.shortcut === 'DSOL')
}
if (info.shortcut === 'SOL' || info.shortcut === 'DSOL') {
return !capabilities.includes('Capability_Solana');
}

return !capabilities.includes(`Capability_${info.name}` as PROTO.Capability);
});
Expand Down

0 comments on commit fff8e5c

Please sign in to comment.