Skip to content

Commit

Permalink
Merge branch 'Thunnini/hideInUI' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunnini committed Apr 8, 2024
2 parents 7aac415 + 6cfce1e commit 0e95861
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 74 deletions.
24 changes: 24 additions & 0 deletions packages/background/src/keyring-cosmos/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export class KeyRingCosmosService {
signOptions: KeplrSignOptions
): Promise<AminoSignResponse> {
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);

const keyInfo = this.keyRingService.getKeyInfo(vaultId);
Expand Down Expand Up @@ -346,6 +349,9 @@ export class KeyRingCosmosService {
}

const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}

const vaultId = this.keyRingService.selectedVaultId;

Expand Down Expand Up @@ -443,6 +449,9 @@ export class KeyRingCosmosService {
}

const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}

const vaultId = this.keyRingService.selectedVaultId;

Expand Down Expand Up @@ -561,6 +570,9 @@ export class KeyRingCosmosService {
}
): Promise<AminoSignResponse> {
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);

const keyInfo = this.keyRingService.getKeyInfo(vaultId);
Expand Down Expand Up @@ -654,6 +666,9 @@ export class KeyRingCosmosService {
signOptions: KeplrSignOptions
): Promise<DirectSignResponse> {
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);

const keyInfo = this.keyRingService.getKeyInfo(vaultId);
Expand Down Expand Up @@ -769,6 +784,9 @@ export class KeyRingCosmosService {
>
): Promise<DirectAuxSignResponse> {
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);

const keyInfo = this.keyRingService.getKeyInfo(vaultId);
Expand Down Expand Up @@ -972,6 +990,9 @@ export class KeyRingCosmosService {
signOptions: KeplrSignOptions
): Promise<AminoSignResponse> {
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);

if (!isEthermintLike) {
Expand Down Expand Up @@ -1129,6 +1150,9 @@ export class KeyRingCosmosService {
{
// Do this on other code block to avoid variable conflict.
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}

Bech32Address.validate(
contractAddress,
Expand Down
3 changes: 3 additions & 0 deletions packages/background/src/keyring-ethereum/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export class KeyRingEthereumService {
signType: EthSignType
): Promise<Uint8Array> {
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
throw new Error("Can't sign for hidden chain");
}
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);
const evmInfo = KeyRingEthereumService.evmInfo(chainInfo);

Expand Down
13 changes: 13 additions & 0 deletions packages/background/src/token-scan/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export class TokenScanService {
return;
}

const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
return;
}

const vaultIds = this.keyRingService
.getKeyInfos()
.map((keyInfo) => keyInfo.id)
Expand Down Expand Up @@ -126,6 +131,11 @@ export class TokenScanService {
return;
}

const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
return;
}

const tokenScan = await this.calculateTokenScan(vaultId, chainId);

if (tokenScan) {
Expand Down Expand Up @@ -221,6 +231,9 @@ export class TokenScanService {
}

const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
if (chainInfo.hideInUI) {
return;
}

if (this.chainsUIService.isEnabled(vaultId, chainId)) {
return;
Expand Down
1 change: 1 addition & 0 deletions packages/chain-validator/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export const ChainInfoSchema = Joi.object<ChainInfo>({
return value;
}),
chainSymbolImageUrl: Joi.string().uri(),
hideInUI: Joi.boolean(),
}).custom((value: ChainInfo) => {
if (
value.alternativeBIP44s?.find(
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/pages/main/available.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const AvailableTabView: FunctionComponent<{
: _allBalancesSearchFiltered;

const lookingForChains = (() => {
return chainStore.chainInfos.filter((chainInfo) => {
return chainStore.chainInfosInListUI.filter((chainInfo) => {
if (chainStore.isEnabledChain(chainInfo.chainId)) {
return false;
}
Expand Down
16 changes: 14 additions & 2 deletions packages/extension/src/pages/register/enable-chains/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ export const EnableChainsScene: FunctionComponent<{
const queries = queriesStore.get(candidateAddress.chainId);
const chainInfo = chainStore.getChain(candidateAddress.chainId);

// hideInUI인 chain은 UI 상에서 enable이 되지 않아야한다.
// 정말 만약의 수로 왜인지 그 체인에 유저가 자산등을 가지고 있을수도 있으니
// 여기서도 막아야한다
if (!chainStore.isInChainInfosInListUI(chainInfo.chainId)) {
continue;
}

// If the chain is already enabled, skip.
if (chainStore.isEnabledChain(candidateAddress.chainId)) {
continue;
Expand Down Expand Up @@ -417,7 +424,7 @@ export const EnableChainsScene: FunctionComponent<{
// 그래서 이를 위한 변수로 따로 둔다.
// 실제로는 chainInfos를 사용하면 된다.
const preSortChainInfos = useMemo(() => {
let chainInfos = chainStore.chainInfos.slice();
let chainInfos = chainStore.chainInfosInListUI.slice();

if (keyType === "ledger") {
chainInfos = chainInfos.filter((chainInfo) => {
Expand Down Expand Up @@ -470,7 +477,12 @@ export const EnableChainsScene: FunctionComponent<{
);
});
}
}, [chainStore.chainInfos, fallbackEthereumLedgerApp, keyType, search]);
}, [
chainStore.chainInfosInListUI,
fallbackEthereumLedgerApp,
keyType,
search,
]);
const chainInfos = preSortChainInfos.sort((a, b) => {
const aHasPriority = sortPriorityChainIdentifierMap.has(
a.chainIdentifier
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/pages/setting/token/add/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export const SettingTokenAddPage: FunctionComponent = observer(() => {
});

const supportedChainInfos = useMemo(() => {
return chainStore.chainInfos.filter((chainInfo) => {
return chainStore.chainInfosInListUI.filter((chainInfo) => {
return (
chainInfo.features?.includes("cosmwasm") ||
chainInfo.features?.includes("secretwasm") ||
chainInfo.evm !== undefined
);
});
}, [chainStore.chainInfos]);
}, [chainStore.chainInfosInListUI]);

const [chainId, setChainId] = useState<string>(() => {
if (paramChainId) {
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/pages/setting/token/manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export const SettingTokenListPage: FunctionComponent = observer(() => {
const navigate = useNavigate();

const supportedChainInfos = useMemo(() => {
return chainStore.chainInfos.filter((chainInfo) => {
return chainStore.chainInfosInListUI.filter((chainInfo) => {
return (
chainInfo.features?.includes("cosmwasm") ||
chainInfo.features?.includes("secretwasm") ||
chainInfo.evm !== undefined
);
});
}, [chainStore.chainInfos]);
}, [chainStore.chainInfosInListUI]);

const [chainId, setChainId] = useState<string>(() => {
if (supportedChainInfos.length > 0) {
Expand Down
29 changes: 29 additions & 0 deletions packages/extension/src/stores/chain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,45 @@ export class ChainStore extends BaseChainStore<ChainInfoWithCoreTypes> {
@computed
get chainInfosInUI() {
return this.chainInfos.filter((chainInfo) => {
if (chainInfo.hideInUI) {
return false;
}
const chainIdentifier = ChainIdHelper.parse(chainInfo.chainId).identifier;
return this.enabledChainIdentifiesMap.get(chainIdentifier);
});
}

// chain info들을 list로 보여줄때 hideInUI인 얘들은 빼고 보여줘야한다
// property 이름이 얘매해서 일단 이렇게 지었다.
@computed
get chainInfosInListUI() {
return this.chainInfos.filter((chainInfo) => {
return !chainInfo.hideInUI;
});
}

isEnabledChain(chainId: string): boolean {
const chainIdentifier = ChainIdHelper.parse(chainId).identifier;
return this.enabledChainIdentifiesMap.get(chainIdentifier) === true;
}

@computed
protected get chainInfosInListUIMap(): Map<string, true> {
const map = new Map<string, true>();
for (const chainInfo of this.chainInfosInListUI) {
map.set(chainInfo.chainIdentifier, true);
}
return map;
}

isInChainInfosInListUI(chainId: string): boolean {
return (
this.chainInfosInListUIMap.get(
ChainIdHelper.parse(chainId).identifier
) === true
);
}

@flow
*toggleChainInfoInUI(...chainIds: string[]) {
if (!this.keyRingStore.selectedKeyInfo) {
Expand Down
21 changes: 13 additions & 8 deletions packages/extension/src/stores/skip/assets-from-source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ChainGetter,
HasMapStore,
ObservableQuery,
QuerySharedContext,
Expand All @@ -9,6 +8,7 @@ import { simpleFetch } from "@keplr-wallet/simple-fetch";
import { computed, makeObservable } from "mobx";
import { ChainIdHelper } from "@keplr-wallet/cosmos";
import Joi from "joi";
import { ChainStore } from "../chain";

const Schema = Joi.object<AssetsFromSourceResponse>({
dest_assets: Joi.object()
Expand All @@ -31,7 +31,7 @@ const Schema = Joi.object<AssetsFromSourceResponse>({
export class ObservableQueryAssetsFromSourceInner extends ObservableQuery<AssetsFromSourceResponse> {
constructor(
sharedContext: QuerySharedContext,
protected readonly chainGetter: ChainGetter,
protected readonly chainStore: ChainStore,
skipURL: string,
public readonly chainId: string,
public readonly denom: string
Expand Down Expand Up @@ -74,9 +74,14 @@ export class ObservableQueryAssetsFromSourceInner extends ObservableQuery<Assets
} = {};

for (const key of Object.keys(this.response.data.dest_assets)) {
if (this.chainGetter.hasChain(key)) {
if (this.chainStore.hasChain(key)) {
const chainInfo = this.chainStore.getChain(key);
if (!this.chainStore.isInChainInfosInListUI(chainInfo.chainId)) {
continue;
}

if (
this.chainGetter.getChain(key).chainIdentifier ===
this.chainStore.getChain(key).chainIdentifier ===
ChainIdHelper.parse(this.chainId).identifier
) {
continue;
Expand All @@ -87,8 +92,8 @@ export class ObservableQueryAssetsFromSourceInner extends ObservableQuery<Assets
const assets = d.assets
.filter((asset) => {
return (
this.chainGetter.hasChain(asset.chain_id) &&
this.chainGetter.hasChain(asset.origin_chain_id)
this.chainStore.hasChain(asset.chain_id) &&
this.chainStore.hasChain(asset.origin_chain_id)
);
})
.map((asset) => {
Expand Down Expand Up @@ -154,14 +159,14 @@ export class ObservableQueryAssetsFromSourceInner extends ObservableQuery<Assets
export class ObservableQueryAssetsFromSource extends HasMapStore<ObservableQueryAssetsFromSourceInner> {
constructor(
protected readonly sharedContext: QuerySharedContext,
protected readonly chainGetter: ChainGetter,
protected readonly chainStore: ChainStore,
protected readonly skipURL: string
) {
super((str) => {
const parsed = JSON.parse(str);
return new ObservableQueryAssetsFromSourceInner(
this.sharedContext,
this.chainGetter,
this.chainStore,
this.skipURL,
parsed.chainId,
parsed.denom
Expand Down
19 changes: 11 additions & 8 deletions packages/extension/src/stores/skip/assets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
ChainGetter,
HasMapStore,
ObservableQuery,
QuerySharedContext,
} from "@keplr-wallet/stores";
import { AssetsResponse } from "./types";
import { computed, makeObservable } from "mobx";
import Joi from "joi";
import { ChainStore } from "../chain";

const Schema = Joi.object<AssetsResponse>({
chain_to_assets_map: Joi.object().pattern(
Expand All @@ -27,7 +27,7 @@ const Schema = Joi.object<AssetsResponse>({
export class ObservableQueryAssetsInner extends ObservableQuery<AssetsResponse> {
constructor(
sharedContext: QuerySharedContext,
protected readonly chainGetter: ChainGetter,
protected readonly chainStore: ChainStore,
skipURL: string,
public readonly chainId: string
) {
Expand Down Expand Up @@ -55,11 +55,14 @@ export class ObservableQueryAssetsInner extends ObservableQuery<AssetsResponse>
return [];
}

if (!this.chainGetter.hasChain(this.chainId)) {
if (!this.chainStore.hasChain(this.chainId)) {
return [];
}

const chainInfo = this.chainGetter.getChain(this.chainId);
const chainInfo = this.chainStore.getChain(this.chainId);
if (!this.chainStore.isInChainInfosInListUI(chainInfo.chainId)) {
return [];
}

const assetsInResponse =
this.response.data.chain_to_assets_map[chainInfo.chainId];
Expand All @@ -73,8 +76,8 @@ export class ObservableQueryAssetsInner extends ObservableQuery<AssetsResponse>

for (const asset of assetsInResponse.assets) {
if (
this.chainGetter.hasChain(asset.chain_id) &&
this.chainGetter.hasChain(asset.origin_chain_id)
this.chainStore.hasChain(asset.chain_id) &&
this.chainStore.hasChain(asset.origin_chain_id)
) {
// IBC asset일 경우 그냥 넣는다.
if (asset.denom.startsWith("ibc/")) {
Expand Down Expand Up @@ -126,13 +129,13 @@ export class ObservableQueryAssetsInner extends ObservableQuery<AssetsResponse>
export class ObservableQueryAssets extends HasMapStore<ObservableQueryAssetsInner> {
constructor(
protected readonly sharedContext: QuerySharedContext,
protected readonly chainGetter: ChainGetter,
protected readonly chainStore: ChainStore,
protected readonly skipURL: string
) {
super((chainId) => {
return new ObservableQueryAssetsInner(
this.sharedContext,
this.chainGetter,
this.chainStore,
this.skipURL,
chainId
);
Expand Down
Loading

0 comments on commit 0e95861

Please sign in to comment.