Skip to content

Commit

Permalink
remove old contact context
Browse files Browse the repository at this point in the history
  • Loading branch information
KKA11010 committed Aug 3, 2023
1 parent a72425a commit c0d2a0c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 83 deletions.
88 changes: 35 additions & 53 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import Button from '@comps/Button'
import usePrompt from '@comps/hooks/Prompt'
import { env } from '@consts'
import { FiveMins } from '@consts/time'
import { addAllMintIds, getBalance, getContacts, getMintsBalances, getMintsUrls, getPreferences, initDb, setPreferences } from '@db'
import { addAllMintIds, getBalance, getMintsBalances, getMintsUrls, getPreferences, initDb, setPreferences } from '@db'
import { fsInfo } from '@db/fs'
import { l } from '@log'
import MyModal from '@modal'
import type { IPreferences, ITokenInfo } from '@model'
import type { INavigatorProps } from '@model/nav'
import Navigator from '@nav/Navigator'
import { NavigationContainer, NavigationContainerRef } from '@react-navigation/native'
import { ContactsContext, type IContact } from '@src/context/Contacts'
import { FocusClaimCtx } from '@src/context/FocusClaim'
import { KeyboardProvider } from '@src/context/Keyboard'
import { PinCtx } from '@src/context/Pin'
Expand Down Expand Up @@ -125,12 +124,6 @@ function _App() {
const [highlight, setHighlight] = useState('Default')
// eslint-disable-next-line react-hooks/exhaustive-deps
const themeData = useMemo(() => ({ pref, theme, setTheme, color, highlight, setHighlight }), [pref])
// address book
const [contacts, setContacts] = useState<IContact[]>([])
const hasOwnAddress = () => contacts.some(c => c.isOwner)
const getPersonalInfo = () => contacts.find(c => c.isOwner)
// eslint-disable-next-line react-hooks/exhaustive-deps
const contactData = useMemo(() => ({ contacts, setContacts, hasOwnAddress, getPersonalInfo }), [contacts])
// app foregorund, background
const appState = useRef(AppState.currentState)
const [tokenInfo, setTokenInfo] = useState<ITokenInfo | undefined>()
Expand Down Expand Up @@ -267,14 +260,6 @@ function _App() {
await SplashScreen.hideAsync()
}
}
async function initContacts() {
try {
const contactsDB = await getContacts()
setContacts(contactsDB)
} catch (e) {
l('Error while initializing contacts from DB')
}
}
async function initAuth() {
const data = await Promise.all([
secureStore.get('auth_pin'),
Expand All @@ -295,7 +280,6 @@ function _App() {
store.get(STORE_KEYS.lang),
getMintsBalances(),
getBalance(),
initContacts(),
initPreferences(),
initAuth(),
])
Expand Down Expand Up @@ -356,43 +340,41 @@ function _App() {
>
<PinCtx.Provider value={pinData}>
<FocusClaimCtx.Provider value={claimData}>
<ContactsContext.Provider value={contactData}>
<KeyboardProvider>
<Navigator
shouldSetup={auth.shouldSetup}
pinHash={auth.pinHash}
bgAuth={bgAuth}
setBgAuth={setBgAuth}
/>
<StatusBar style="auto" />
{/* claim token if app comes to foreground and clipboard has valid cashu token */}
<MyModal type='question' visible={claimOpen} close={() => setClaimOpen(false)}>
<Text style={globals(color, highlight).modalHeader}>
{t('foundCashuClipboard')}
</Text>
<Text style={globals(color, highlight).modalTxt}>
{t('memo', { ns: 'history' })}: {tokenInfo?.decoded.memo}{'\n'}
<Txt
txt={formatInt(tokenInfo?.value ?? 0)}
styles={[{ fontWeight: '500' }]}
/>
{' '}Satoshi {t('fromMint')}:{' '}
{tokenInfo?.mints.join(', ')}
</Text>
<Button
txt={t('accept')}
onPress={() => void handleRedeem()}
/>
<View style={{ marginVertical: 10 }} />
<Button
txt={t('cancel')}
outlined
onPress={() => setClaimOpen(false)}
<KeyboardProvider>
<Navigator
shouldSetup={auth.shouldSetup}
pinHash={auth.pinHash}
bgAuth={bgAuth}
setBgAuth={setBgAuth}
/>
<StatusBar style="auto" />
{/* claim token if app comes to foreground and clipboard has valid cashu token */}
<MyModal type='question' visible={claimOpen} close={() => setClaimOpen(false)}>
<Text style={globals(color, highlight).modalHeader}>
{t('foundCashuClipboard')}
</Text>
<Text style={globals(color, highlight).modalTxt}>
{t('memo', { ns: 'history' })}: {tokenInfo?.decoded.memo}{'\n'}
<Txt
txt={formatInt(tokenInfo?.value ?? 0)}
styles={[{ fontWeight: '500' }]}
/>
</MyModal>
{prompt.open && <Toaster success={prompt.success} txt={prompt.msg} />}
</KeyboardProvider>
</ContactsContext.Provider>
{' '}Satoshi {t('fromMint')}:{' '}
{tokenInfo?.mints.join(', ')}
</Text>
<Button
txt={t('accept')}
onPress={() => void handleRedeem()}
/>
<View style={{ marginVertical: 10 }} />
<Button
txt={t('cancel')}
outlined
onPress={() => setClaimOpen(false)}
/>
</MyModal>
{prompt.open && <Toaster success={prompt.success} txt={prompt.msg} />}
</KeyboardProvider>
</FocusClaimCtx.Provider>
</PinCtx.Provider>
</NavigationContainer>
Expand Down
28 changes: 0 additions & 28 deletions src/context/Contacts.tsx

This file was deleted.

7 changes: 7 additions & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,11 @@ export interface ITx<T = unknown> {
export interface IKeyValuePair<T> {
key: string,
value: T
}

export interface IContact {
id?: number
name: string,
ln: string,
isOwner: boolean
}
3 changes: 1 addition & 2 deletions src/storage/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Proof, Token } from '@cashu/cashu-ts'
import { CashuMint, deriveKeysetId, getDecodedToken } from '@cashu/cashu-ts'
import { l } from '@log'
import type { IInvoice, IMint, IMintWithBalance, IPreferences, IPreferencesResp, ITx } from '@model'
import type { IContact } from '@src/context/Contacts'
import type { IContact, IInvoice, IMint, IMintWithBalance, IPreferences, IPreferencesResp, ITx } from '@model'
import { arrToChunks, isObj } from '@util'
import * as SQLite from 'expo-sqlite'

Expand Down

0 comments on commit c0d2a0c

Please sign in to comment.