Skip to content

Commit b6e1e9f

Browse files
committed
chore: allow overriding tokenList through asset-picker prop
1 parent 28672fb commit b6e1e9f

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

ui/components/multichain/asset-picker-amount/asset-picker-modal/asset-picker-modal.tsx

+16-7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ import AssetList from './AssetList';
6464
import { Search } from './asset-picker-modal-search';
6565
import { AssetPickerModalNetwork } from './asset-picker-modal-network';
6666

67+
type TokenListGenerator = Generator<
68+
| AssetWithDisplayData<NativeAsset>
69+
| ((Token | TokenListToken) & {
70+
balance?: string;
71+
string?: string;
72+
})
73+
>;
74+
6775
type AssetPickerModalProps = {
6876
header: JSX.Element | string | null;
6977
isOpen: boolean;
@@ -77,6 +85,7 @@ type AssetPickerModalProps = {
7785
*/
7886
sendingAsset?: { image: string; symbol: string } | undefined;
7987
onNetworkPickerClick?: () => void;
88+
tokenListGenerator?: () => TokenListGenerator;
8089
} & Pick<
8190
React.ComponentProps<typeof AssetPickerModalTabs>,
8291
'visibleTabs' | 'defaultActiveTabKey'
@@ -94,6 +103,7 @@ export function AssetPickerModal({
94103
sendingAsset,
95104
network,
96105
onNetworkPickerClick,
106+
tokenListGenerator,
97107
...tabProps
98108
}: AssetPickerModalProps) {
99109
const t = useI18nContext();
@@ -164,6 +174,10 @@ export function AssetPickerModal({
164174
}, [tokensWithBalances, tokens]);
165175

166176
const tokenGenerator = useCallback(() => {
177+
if (tokenListGenerator) {
178+
return tokenListGenerator();
179+
}
180+
167181
const nativeToken: AssetWithDisplayData<NativeAsset> = {
168182
address: null,
169183
symbol: nativeCurrency,
@@ -174,13 +188,7 @@ export function AssetPickerModal({
174188
type: AssetType.native,
175189
};
176190

177-
return (function* (): Generator<
178-
| AssetWithDisplayData<NativeAsset>
179-
| ((Token | TokenListToken) & {
180-
balance?: string;
181-
string?: string;
182-
})
183-
> {
191+
return (function* (): TokenListGenerator {
184192
yield nativeToken;
185193

186194
const blockedTokens = [];
@@ -215,6 +223,7 @@ export function AssetPickerModal({
215223
nativeCurrencyImage,
216224
balanceValue,
217225
memoizedUsersTokens,
226+
tokenListGenerator,
218227
topTokens,
219228
tokenList,
220229
getIsDisabled,

ui/components/multichain/asset-picker-amount/asset-picker/asset-picker.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export type AssetPickerProps = {
6969
>;
7070
} & Pick<
7171
React.ComponentProps<typeof AssetPickerModal>,
72-
'visibleTabs' | 'header' | 'sendingAsset'
72+
'visibleTabs' | 'header' | 'sendingAsset' | 'tokenListGenerator'
7373
>;
7474

7575
// A component that lets the user pick from a list of assets.
@@ -82,6 +82,7 @@ export function AssetPicker({
8282
onClick,
8383
isDisabled = false,
8484
visibleTabs,
85+
tokenListGenerator,
8586
}: AssetPickerProps) {
8687
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
8788
const t = useI18nContext();
@@ -156,6 +157,7 @@ export function AssetPicker({
156157
defaultActiveTabKey={
157158
asset?.type === AssetType.NFT ? TabName.NFTS : TabName.TOKENS
158159
}
160+
tokenListGenerator={tokenListGenerator}
159161
/>
160162

161163
<Button

0 commit comments

Comments
 (0)