From a7d5a7d4d559cf1ad021a0fc4830f6b1b125285b Mon Sep 17 00:00:00 2001 From: Iuri Pereira <689440+iuricmp@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:06:49 +0000 Subject: [PATCH 1/2] chore: listing chain name on key --- mobile/app/(app)/home/home.tsx | 12 +++++-- mobile/app/(app)/tosignin/index.tsx | 3 +- .../list/vault-list/VaultListItem.tsx | 13 +++++-- mobile/redux/features/vaultEditSlice.ts | 35 ++++++++++++------- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/mobile/app/(app)/home/home.tsx b/mobile/app/(app)/home/home.tsx index a2a11de..9f6827c 100644 --- a/mobile/app/(app)/home/home.tsx +++ b/mobile/app/(app)/home/home.tsx @@ -3,7 +3,7 @@ import { FlatList, TouchableOpacity, View } from "react-native"; import { useNavigation, useRouter } from "expo-router"; import { Layout } from "@/components/index"; import Text from "@/components/text"; -import { checkForKeyOnChains, initSignUpState, selectMasterPassword, useAppDispatch, useAppSelector } from "@/redux"; +import { checkForKeyOnChains, initSignUpState, selectMasterPassword, useAppDispatch, useAppSelector, selectKeyInfoChains } from "@/redux"; import { KeyInfo, useGnoNativeContext } from "@gnolang/gnonative"; import Octicons from '@expo/vector-icons/Octicons'; import TextInput from "@/components/textinput"; @@ -24,6 +24,8 @@ export default function Page() { const dispatch = useAppDispatch(); const masterPassword = useAppSelector(selectMasterPassword) + const keyInfoChains = useAppSelector(selectKeyInfoChains) + useEffect(() => { const unsubscribe = navigation.addListener("focus", async () => { try { @@ -76,6 +78,12 @@ export default function Page() { route.push("/add-key"); } + const getChainNamePerKey = (keyInfo: KeyInfo): string[] | undefined => { + if (keyInfoChains instanceof Map && keyInfoChains?.has(keyInfo.address.toString())) { + return keyInfoChains.get(keyInfo.address.toString()) + } + } + if (loading) { return ( @@ -103,7 +111,7 @@ export default function Page() { ( - + )} keyExtractor={(item) => item.name} ListEmptyComponent={There are no items to list.} diff --git a/mobile/app/(app)/tosignin/index.tsx b/mobile/app/(app)/tosignin/index.tsx index 59255b6..2563ff9 100644 --- a/mobile/app/(app)/tosignin/index.tsx +++ b/mobile/app/(app)/tosignin/index.tsx @@ -3,7 +3,7 @@ import Button from "@/components/button"; import VaultListItem from "@/components/list/vault-list/VaultListItem"; import Spacer from "@/components/spacer"; import Text from "@/components/text"; -import { checkForKeyOnChains, clearLinking, selectCallback, selectClientName, sendAddressToSoliciting, useAppDispatch, useAppSelector } from "@/redux"; +import { clearLinking, selectCallback, selectClientName, sendAddressToSoliciting, useAppDispatch, useAppSelector } from "@/redux"; import { KeyInfo, useGnoNativeContext } from "@gnolang/gnonative"; import { router, useNavigation } from "expo-router"; import { useCallback, useEffect, useState } from "react"; @@ -45,7 +45,6 @@ export default function Page() { const onCancel = () => { dispatch(clearLinking()) - dispatch(checkForKeyOnChains()) Linking.openURL(`${callback}?status=cancelled`); router.replace("/home") } diff --git a/mobile/components/list/vault-list/VaultListItem.tsx b/mobile/components/list/vault-list/VaultListItem.tsx index 91cf53b..fb6f751 100644 --- a/mobile/components/list/vault-list/VaultListItem.tsx +++ b/mobile/components/list/vault-list/VaultListItem.tsx @@ -4,18 +4,25 @@ import { KeyInfo } from "@gnolang/gnonative"; import { TouchableOpacity, View } from "react-native"; import styled from "styled-components/native"; import AntDesign from '@expo/vector-icons/AntDesign'; +import Row from "@/components/row"; interface Props { vault: KeyInfo; + chains?: string[]; onVaultPress: (vault: KeyInfo) => void; } -const VaultListItem = ({ vault, onVaultPress }: Props) => { +const VaultListItem = ({ vault, onVaultPress, chains = [] }: Props) => { return ( onVaultPress(vault)}> - - {vault.name} + + + {vault.name} + + + {chains ? {chains.join(', ')} : null} + diff --git a/mobile/redux/features/vaultEditSlice.ts b/mobile/redux/features/vaultEditSlice.ts index c16befe..fac6bc7 100644 --- a/mobile/redux/features/vaultEditSlice.ts +++ b/mobile/redux/features/vaultEditSlice.ts @@ -1,11 +1,12 @@ import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; +import { selectChainsAvailable } from "@/redux"; import { GnoNativeApi, KeyInfo } from "@gnolang/gnonative"; import { ThunkExtra } from "@/providers/redux-provider"; import { RootState } from "../root-reducer"; export interface VaultState { vaultToEdit: KeyInfo | undefined; - keyinfosChains?: Map; + keyInfoChains?: Map; } const initialState: VaultState = { @@ -44,25 +45,29 @@ export const saveChanges = createAsyncThunk, void, ThunkExtra>("vault/checkForKeyOnChains", async (_, thunkAPI) => { const gnonative = thunkAPI.extra.gnonative as GnoNativeApi; - const keyinfos = await gnonative.listKeyInfo(); - const chains = (thunkAPI.getState() as RootState).signUp.chainsAvailable; + const chains = await selectChainsAvailable(thunkAPI.getState() as RootState); - const keyinfosChains = new Map(); + const keyInfoChains = new Map(); for (const chain of chains) { + console.log("checking keys on chain", chain.chainName); + await gnonative.setChainID(chain.chainId); await gnonative.setRemote(chain.gnoAddress); for (const key of keyinfos) { console.log(`Checking key ${key.name} on chain ${chain.chainName}`); - const queryResponse = await hasCoins(gnonative, key.address); - console.log(`Key ${key.name} on chain ${chain.chainName} has coins: ${queryResponse}`); + const keyHasCoins = await hasCoins(gnonative, key.address); + console.log(`Key ${key.name} on chain ${chain.chainName} has coins: ${keyHasCoins}`); - keyinfosChains.has(key.name) ? keyinfosChains.get(key.name)?.push(chain.chainId) : keyinfosChains.set(key.name, [chain.chainId]); + if (keyHasCoins) { + console.log(`Key ${key.name} on chain ${chain.chainName} has coins`, JSON.stringify(key)); + keyInfoChains.has(key.address.toString()) ? keyInfoChains.get(key.address.toString())?.push(chain.chainName) : keyInfoChains.set(key.address.toString(), [chain.chainName]); + } } } - return keyinfosChains; + return keyInfoChains; }); const hasCoins = async (gnonative: GnoNativeApi, address: Uint8Array) => { @@ -93,16 +98,20 @@ export const vaultSlice = createSlice({ } }, extraReducers: (builder) => { - builder.addCase(checkForKeyOnChains.fulfilled, (state, action) => { - console.log("checkForKeyOnChains.fulfilled", action.payload); - state.keyinfosChains = action.payload; - }) + builder.addCase(checkForKeyOnChains.rejected, (state, action) => { + console.error("checkForKeyOnChains.rejected", action.error); + }), + builder.addCase(checkForKeyOnChains.fulfilled, (state, action) => { + console.log("checkForKeyOnChains.fulfilled", action.payload); + state.keyInfoChains = action.payload; + }) }, selectors: { selectVaultToEdit: (state) => state.vaultToEdit, + selectKeyInfoChains: (state) => state.keyInfoChains, }, }); export const { setVaultToEdit } = vaultSlice.actions; -export const { selectVaultToEdit } = vaultSlice.selectors; +export const { selectVaultToEdit, selectKeyInfoChains } = vaultSlice.selectors; From 048ea67df190289fd82128cc1249ec5b4020db32 Mon Sep 17 00:00:00 2001 From: Iuri Pereira <689440+iuricmp@users.noreply.github.com> Date: Tue, 17 Dec 2024 05:45:16 -0300 Subject: [PATCH 2/2] feat: display chain info on key listing Signed-off-by: Iuri Pereira <689440+iuricmp@users.noreply.github.com> --- mobile/app/(app)/chain-selection/index.tsx | 1 - mobile/redux/features/vaultEditSlice.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mobile/app/(app)/chain-selection/index.tsx b/mobile/app/(app)/chain-selection/index.tsx index 9a5bc41..f003501 100644 --- a/mobile/app/(app)/chain-selection/index.tsx +++ b/mobile/app/(app)/chain-selection/index.tsx @@ -64,7 +64,6 @@ function Page() { await gnonative.getChainID(); const currentChain = await dispatch(getCurrentChain()).unwrap(); - console.log('xxxxx', currentChain); dispatch(setSelectedChain(currentChain)); setLoading(undefined); diff --git a/mobile/redux/features/vaultEditSlice.ts b/mobile/redux/features/vaultEditSlice.ts index fac6bc7..96f413e 100644 --- a/mobile/redux/features/vaultEditSlice.ts +++ b/mobile/redux/features/vaultEditSlice.ts @@ -1,5 +1,5 @@ import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; -import { selectChainsAvailable } from "@/redux"; +import { selectChainsAvailable } from "./signupSlice"; import { GnoNativeApi, KeyInfo } from "@gnolang/gnonative"; import { ThunkExtra } from "@/providers/redux-provider"; import { RootState } from "../root-reducer";