Skip to content

Commit

Permalink
Merge branch 'master' into brody/mocking-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
BrodyHughes authored Oct 22, 2024
2 parents 236432a + be0487e commit a0678bf
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 283 deletions.
50 changes: 32 additions & 18 deletions lavamoat/build-webpack/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-module-imports": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-simple-access": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-split-export-declaration": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-validator-identifier": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/template": true,
"jest>@jest/core>jest-snapshot>@babel/traverse": true,
"jest>@jest/core>jest-snapshot>@babel/types": true
"jest>@jest/core>jest-snapshot>@babel/types": true,
"jest>@jest/core>jest-snapshot>@babel/types>@babel/helper-validator-identifier": true
}
},
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-module-imports": {
Expand Down Expand Up @@ -1141,16 +1141,9 @@
"console.warn": true,
"process.emitWarning": true
},
"packages": {
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>@babel/highlight": true,
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>chalk": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>@babel/highlight": {
"packages": {
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>chalk": true,
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/types>@babel/helper-validator-identifier": true,
"react>loose-envify>js-tokens": true
"lavamoat>@babel/highlight": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>chalk": {
Expand Down Expand Up @@ -1224,6 +1217,34 @@
"lavamoat>lavamoat-core>@babel/types>to-fast-properties": true
}
},
"lavamoat>@babel/highlight": {
"packages": {
"lavamoat>@babel/highlight>@babel/helper-validator-identifier": true,
"lavamoat>@babel/highlight>chalk": true,
"react>loose-envify>js-tokens": true
}
},
"lavamoat>@babel/highlight>chalk": {
"globals": {
"process.env.TERM": true,
"process.platform": true
},
"packages": {
"lavamoat>@babel/highlight>chalk>ansi-styles": true,
"lavamoat>@babel/highlight>chalk>escape-string-regexp": true,
"supports-color": true
}
},
"lavamoat>@babel/highlight>chalk>ansi-styles": {
"packages": {
"lavamoat>@babel/highlight>chalk>ansi-styles>color-convert": true
}
},
"lavamoat>@babel/highlight>chalk>ansi-styles>color-convert": {
"packages": {
"lavamoat>@babel/highlight>chalk>ansi-styles>color-convert>color-name": true
}
},
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name": {
"packages": {
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template": true,
Expand All @@ -1243,17 +1264,10 @@
"process.emitWarning": true
},
"packages": {
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>@babel/highlight": true,
"lavamoat>@babel/highlight": true,
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>chalk": true
}
},
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>@babel/highlight": {
"packages": {
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>chalk": true,
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/types>@babel/helper-validator-identifier": true,
"react>loose-envify>js-tokens": true
}
},
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>chalk": {
"globals": {
"process.env.TERM": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "browser-extension",
"license": "GPL-3.0-only",
"version": "1.5.50",
"version": "1.5.53",
"scripts": {
"//enable dev mode": "",
"devmode:on": "sed -i'' -e 's/IS_DEV.*/IS_DEV=true/g' .env",
Expand Down
3 changes: 2 additions & 1 deletion src/core/resources/search/parseTokenSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ export function parseTokenSearch(
chainId: ChainId,
): SearchAsset {
const networkInfo = asset.networks[chainId];
const mainnetInfo = asset.networks[ChainId.mainnet];

return {
...asset,
address: networkInfo ? networkInfo.address : asset.address,
chainId,
decimals: networkInfo ? networkInfo.decimals : asset.decimals,
isNativeAsset: isNativeAsset(asset.address, chainId),
mainnetAddress: asset.uniqueId as AddressOrEth,
mainnetAddress: mainnetInfo?.address as AddressOrEth,
uniqueId: `${networkInfo?.address || asset.uniqueId}_${chainId}`,
};
}
16 changes: 9 additions & 7 deletions src/core/resources/search/tokenDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ const tokenSearchDiscoveryHttp = createHttpClient({
timeout: 30000,
});

type TokenDiscoveryArgs = {
chainId: ChainId;
};

const tokenDiscoveryQueryKey = ({ chainId }: TokenDiscoveryArgs) =>
const tokenDiscoveryQueryKey = ({ chainId }: { chainId: ChainId }) =>
createQueryKey('TokenDiscovery', { chainId }, { persisterVersion: 1 });

async function tokenSearchQueryFunction({
Expand All @@ -36,12 +32,18 @@ async function tokenSearchQueryFunction({
}
}

export function useTokenDiscovery({ chainId }: TokenDiscoveryArgs) {
export function useTokenDiscovery<T = SearchAsset[]>({
chainId,
select,
}: {
chainId: ChainId;
select?: (data: SearchAsset[]) => T;
}) {
return useQuery({
queryKey: tokenDiscoveryQueryKey({ chainId }),
queryFn: tokenSearchQueryFunction,
staleTime: 15 * 60 * 1000, // 15 min
gcTime: 24 * 60 * 60 * 1000, // 1 day
select: (data) => data.slice(0, 3),
select,
});
}
39 changes: 6 additions & 33 deletions src/core/resources/search/tokenSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isAddress } from '@ethersproject/address';
import { useQueries, useQuery } from '@tanstack/react-query';
import qs from 'qs';

Expand Down Expand Up @@ -27,9 +26,7 @@ import { parseTokenSearch } from './parseTokenSearch';
export type TokenSearchArgs = {
chainId: ChainId;
fromChainId?: ChainId | '';
keys: TokenSearchAssetKey[];
list: TokenSearchListId;
threshold: TokenSearchThreshold;
query: string;
};

Expand All @@ -46,14 +43,12 @@ export type TokenSearchAllNetworksArgs = {
const tokenSearchQueryKey = ({
chainId,
fromChainId,
keys,
list,
threshold,
query,
}: TokenSearchArgs) =>
createQueryKey(
'TokenSearch',
{ chainId, fromChainId, keys, list, threshold, query },
{ chainId, fromChainId, list, query },
{ persisterVersion: 2 },
);

Expand All @@ -63,26 +58,19 @@ type TokenSearchQueryKey = ReturnType<typeof tokenSearchQueryKey>;
// Query Function

async function tokenSearchQueryFunction({
queryKey: [{ chainId, fromChainId, keys, list, threshold, query }],
queryKey: [{ chainId, fromChainId, list, query }],
}: QueryFunctionArgs<typeof tokenSearchQueryKey>) {
const queryParams: {
keys: string;
list: TokenSearchListId;
threshold: TokenSearchThreshold;
query?: string;
fromChainId?: number;
} = {
keys: keys.join(','),
list,
threshold,
query,
};
if (fromChainId) {
queryParams.fromChainId = fromChainId;
}
if (isAddress(query)) {
queryParams.keys = `networks.${chainId}.address`;
}
const url = `/${chainId}/?${qs.stringify(queryParams)}`;
try {
const tokenSearch = await tokenSearchHttp.get<{ data: SearchAsset[] }>(url);
Expand All @@ -100,7 +88,7 @@ type TokenSearchResult = QueryFunctionResult<typeof tokenSearchQueryFunction>;
// Query Fetcher

export async function fetchTokenSearch(
{ chainId, fromChainId, keys, list, threshold, query }: TokenSearchArgs,
{ chainId, fromChainId, list, query }: TokenSearchArgs,
config: QueryConfig<
TokenSearchResult,
Error,
Expand All @@ -112,9 +100,7 @@ export async function fetchTokenSearch(
queryKey: tokenSearchQueryKey({
chainId,
fromChainId,
keys,
list,
threshold,
query,
}),
queryFn: tokenSearchQueryFunction,
Expand All @@ -126,7 +112,7 @@ export async function fetchTokenSearch(
// Query Hook

export function useTokenSearch(
{ chainId, fromChainId, keys, list, threshold, query }: TokenSearchArgs,
{ chainId, fromChainId, list, query }: TokenSearchArgs,
config: QueryConfig<
TokenSearchResult,
Error,
Expand All @@ -138,9 +124,7 @@ export function useTokenSearch(
queryKey: tokenSearchQueryKey({
chainId,
fromChainId,
keys,
list,
threshold,
query,
}),
queryFn: tokenSearchQueryFunction,
Expand All @@ -152,12 +136,7 @@ export function useTokenSearch(
// Query Hook

export function useTokenSearchAllNetworks(
{
keys,
list,
threshold,
query,
}: Omit<TokenSearchArgs, 'chainId' | 'fromChainId'>,
{ list, query }: Omit<TokenSearchArgs, 'chainId' | 'fromChainId'>,
config: QueryConfig<
TokenSearchResult,
Error,
Expand All @@ -172,13 +151,7 @@ export function useTokenSearchAllNetworks(
const queries = useQueries({
queries: rainbowSupportedChains.map(({ id: chainId }) => {
return {
queryKey: tokenSearchQueryKey({
chainId,
keys,
list,
threshold,
query,
}),
queryKey: tokenSearchQueryKey({ chainId, list, query }),
queryFn: tokenSearchQueryFunction,
refetchOnWindowFocus: false,
...config,
Expand Down
58 changes: 38 additions & 20 deletions src/core/state/rainbowChains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const rainbowChainsStore = createStore<RainbowChainsState>(
{
persist: persistOptions({
name: 'rainbowChains',
version: 9,
version: 10,
migrations: [
// v1 didn't need a migration
function v1(s: RainbowChainsState) {
Expand All @@ -131,55 +131,73 @@ export const rainbowChainsStore = createStore<RainbowChainsState>(

// version 2 added support for Avalanche and Avalanche Fuji
function v2(state) {
return mergeNewOfficiallySupportedChainsState(state, [
const rnbwChainState = state as RainbowChainsState;
return mergeNewOfficiallySupportedChainsState(rnbwChainState, [
ChainId.avalanche,
ChainId.avalancheFuji,
]);
},

// version 3 added support for Blast
function v3(state) {
return mergeNewOfficiallySupportedChainsState(state, [ChainId.blast]);
function v3(state: unknown) {
const rnbwChainState = state as RainbowChainsState;
return mergeNewOfficiallySupportedChainsState(rnbwChainState, [
ChainId.blast,
]);
},

function v4(state) {
function v4(state: unknown) {
const rnbwChainState = state as RainbowChainsState;
return removeCustomRPC({
state,
state: rnbwChainState,
rpcUrl: 'https://rpc.zora.co',
rainbowChains: state.rainbowChains,
rainbowChains: rnbwChainState.rainbowChains,
});
},

// version 5 added support for Degen
function v5(state) {
return mergeNewOfficiallySupportedChainsState(state, [ChainId.degen]);
function v5(state: unknown) {
const rnbwChainState = state as RainbowChainsState;
return mergeNewOfficiallySupportedChainsState(rnbwChainState, [
ChainId.degen,
]);
},

function v6(state) {
function v6(state: unknown) {
const rnbwChainState = state as RainbowChainsState;
if (
!state.rainbowChains[zora.id] ||
state.rainbowChains[zora.id]?.chains.length === 0
!rnbwChainState.rainbowChains[zora.id] ||
rnbwChainState.rainbowChains[zora.id]?.chains.length === 0
) {
return addCustomRPC({ chain: zora, state });
return addCustomRPC({ chain: zora, state: rnbwChainState });
}
return state;
},

function v7(state) {
function v7(state: unknown) {
return state;
},

function v8(state) {
function v8(state: unknown) {
const rnbwChainState = state as RainbowChainsState;
if (
!state.rainbowChains[degen.id] ||
state.rainbowChains[degen.id]?.chains.length === 0
!rnbwChainState.rainbowChains[degen.id] ||
rnbwChainState.rainbowChains[degen.id]?.chains.length === 0
) {
return addCustomRPC({ chain: degen, state });
return addCustomRPC({
chain: degen,
state: state as RainbowChainsState,
});
}
return state;
},
function v9(state) {
return replaceChainsWithInitial(state);
function v9(state: unknown) {
return replaceChainsWithInitial(state as RainbowChainsState);
},
function v10(state: unknown) {
const rnbwState = state as RainbowChainsState;
rnbwState.rainbowChains = getInitialRainbowChains();
return rnbwState;
},
],
}),
Expand Down
2 changes: 1 addition & 1 deletion src/core/state/userChains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const userChainsStore = createStore<UserChainsState>(
{
persist: {
name: 'userChains',
version: 4,
version: 5,
},
},
);
Expand Down
Loading

0 comments on commit a0678bf

Please sign in to comment.