Skip to content

Commit

Permalink
feat: wallet history module core components (#1151)
Browse files Browse the repository at this point in the history
Signed-off-by: Mostafa Gamal <[email protected]>
  • Loading branch information
MosCD3 authored Jul 23, 2024
1 parent c0c4ffa commit 6da353c
Show file tree
Hide file tree
Showing 33 changed files with 2,339 additions and 30 deletions.
7 changes: 6 additions & 1 deletion packages/legacy/core/App/container-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseLogger } from '@credo-ts/core'
import { Agent, BaseLogger } from '@credo-ts/core'
import { IndyVdrPoolConfig } from '@credo-ts/indy-vdr'
import { ProofRequestTemplate } from '@hyperledger/aries-bifold-verifier'
import { OCABundleResolverType } from '@hyperledger/aries-oca/build/legacy'
Expand All @@ -8,6 +8,7 @@ import { DependencyContainer } from 'tsyringe'

import { Button } from './components/buttons/Button-api'
import { ReducerAction } from './contexts/reducers/store'
import { IHistoryManager } from './modules/history'
import Onboarding from './screens/Onboarding'
import { GenericFn } from './types/fn'
import { AuthenticateStackParams, ScreenOptionsType } from './types/navigators'
Expand Down Expand Up @@ -40,6 +41,7 @@ export const STACK_TOKENS = {

export const FN_TOKENS = {
FN_ONBOARDING_DONE: 'fn.onboardingDone',
FN_LOAD_HISTORY: 'fn.loadHistory',
} as const

export const COMP_TOKENS = {
Expand Down Expand Up @@ -83,6 +85,8 @@ export const TOKENS = {
...UTILITY_TOKENS,
} as const

export type FN_HISTORY_MANAGER = (agent: Agent<any>) => IHistoryManager

export type TokenMapping = {
[TOKENS.CRED_HELP_ACTION_OVERRIDES]: {
credDefIds: string[]
Expand All @@ -105,6 +109,7 @@ export type TokenMapping = {
[TOKENS.UTIL_OCA_RESOLVER]: OCABundleResolverType
[TOKENS.UTIL_LEDGERS]: IndyVdrPoolConfig[]
[TOKENS.UTIL_PROOF_TEMPLATE]: ProofRequestTemplateFn | undefined
[TOKENS.FN_LOAD_HISTORY]: FN_HISTORY_MANAGER
}

export interface Container {
Expand Down
6 changes: 6 additions & 0 deletions packages/legacy/core/App/container-impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BaseLogger } from '@credo-ts/core'
import { Agent } from '@credo-ts/core'
import { useProofRequestTemplates } from '@hyperledger/aries-bifold-verifier'
import { DefaultOCABundleResolver } from '@hyperledger/aries-oca/build/legacy'
import AsyncStorage from '@react-native-async-storage/async-storage'
Expand All @@ -13,6 +14,8 @@ import { LocalStorageKeys } from './constants'
import { TOKENS, Container, TokenMapping } from './container-api'
import { DispatchAction, ReducerAction } from './contexts/reducers/store'
import { defaultState } from './contexts/store'
import { IHistoryManager } from './modules/history'
import HistoryManager from './modules/history/context/historyManager'
import OnboardingStack from './navigators/OnboardingStack'
import { DefaultScreenOptionsDictionary } from './navigators/defaultStackOptions'
import Developer from './screens/Developer'
Expand Down Expand Up @@ -73,6 +76,9 @@ export class MainContainer implements Container {
}
}
)
this._container.registerInstance(TOKENS.FN_LOAD_HISTORY, (agent: Agent<any>): IHistoryManager => {
return new HistoryManager(agent)
})
this._container.registerInstance(TOKENS.LOAD_STATE, async (dispatch: React.Dispatch<ReducerAction<unknown>>) => {
const loadState = async <Type>(key: LocalStorageKeys, updateVal: (newVal: Type) => void) => {
const data = await AsyncStorage.getItem(key)
Expand Down
16 changes: 16 additions & 0 deletions packages/legacy/core/App/contexts/reducers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum PreferencesDispatchAction {
PREFERENCES_UPDATED = 'preferences/preferencesStateLoaded',
USE_VERIFIER_CAPABILITY = 'preferences/useVerifierCapability',
USE_CONNECTION_INVITER_CAPABILITY = 'preferences/useConnectionInviterCapability',
HISTORY_CAPABILITY = 'preferences/historyCapability',
USE_DEV_VERIFIER_TEMPLATES = 'preferences/useDevVerifierTemplates',
ENABLE_WALLET_NAMING = 'preferences/enableWalletNaming',
UPDATE_WALLET_NAME = 'preferences/updateWalletName',
Expand Down Expand Up @@ -199,6 +200,21 @@ export const reducer = <S extends State>(state: S, action: ReducerAction<Dispatc

return newState
}
case PreferencesDispatchAction.HISTORY_CAPABILITY: {
const choice = (action?.payload ?? []).pop() ?? false
const preferences = {
...state.preferences,
useHistoryCapability: choice,
}
const newState = {
...state,
preferences,
}

AsyncStorage.setItem(LocalStorageKeys.Preferences, JSON.stringify(preferences))

return newState
}
case PreferencesDispatchAction.USE_DEV_VERIFIER_TEMPLATES: {
const choice = (action?.payload ?? []).pop() ?? false
const preferences = {
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/core/App/contexts/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const defaultState: State = {
usePushNotifications: false,
useVerifierCapability: false,
useConnectionInviterCapability: false,
useHistoryCapability: false,
useDevVerifierTemplates: false,
acceptDevCredentials: false,
useDataRetention: true,
Expand Down
135 changes: 135 additions & 0 deletions packages/legacy/core/App/localization/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ const translation = {
"Biometrics": "Biometrics",
"On": "On",
"Off": "Off",
"History": "History",
"SaveSettings": "Save Settings",
"organization": "Organization",
"Issuer": "Issuer",
"RevokedByIssuer": "Revoked by this issuer",
"Verifier": "Verifier",
"Expired": "Expired",
"Revoked": "Revoked",
"Issued": "Issued",
"Requested": "Requested",
"Updated": "Updated",
"Close": "Close",
"Remove": "Remove",
},
Expand Down Expand Up @@ -129,6 +140,10 @@ const translation = {
"Title1046": "Unable to fetch contacts.",
"Message1046": "There was a problem while fetching contacts.",
},
"SelectionAxs": {
"RadioChecked": "checked",
"RadioUnchecked": "unchecked"
},
"ActivityLog": {
"Your": "Your",
"Activity": "activity log",
Expand Down Expand Up @@ -256,6 +271,123 @@ const translation = {
"UnlockPromptTitle": "Wallet Unlock",
"UnlockPromptDescription": "Use biometrics to unlock your wallet"
},
"ActivityHistory": {
"Header": "Activity history",
"Title": "Manage activity history",
"Description": "Set how long you want to keep your activity history before it is deleted from your device (it is not stored anywhere else).",
"DeleteActivity": "Delete activity history after:",
"DeleteActivityAfter": {
"1month":"1 month",
"6month":"6 month",
"1year":"1 year",
"Always":"Always",
},
"WarningDisclaimerAlert": {
"Title": "Past activity will be deleted",
"Description": "Any activity before the period you've just selected will be deleted as soon as you save."
},
"SettingsSaved": "History settings saved",
"NoOptionSelectedError": "No option selected",
"StopKeepingHistory": "Stop keeping activity history",
"StoppedLoggingAlert": "You are not logging your activity history.",
"StoppedLoggingAlertYes": "Turn on activity history",
"DeleteActivityHistory": {
"Title": "Delete activity history",
"Description": "Individual history can be deleted in the history tab or you can delete all activity history. This action cannot be undone.",
"Link": "Delete all activity history"
},
"StopActivityHistoryScreen": {
"Header": "Turn off activity history?",
"Title": "Are you sure you want to turn off history?",
"Description": "No further activity history will be kept in the Ontario Wallet. All previous history will remain.",
"Yes": "Yes turn off activity history",
"No": "No, go back"
},
"StopActivityHistoryScreenConfirmed": {
"Header": "Activity history turned off",
"Title": "History turned off",
"Description": "The Ontario Wallet is no longer storing your activity history",
"Back": "Back to settings",
},
"DeleteActivityHistoryScreen": {
"Header": "Delete all activity history?",
"Title": "Are you sure you want to delete all history?",
"Description": "You will not be able to get your activity history back after you delete it.",
"Yes": "Yes, delete all activity history",
"No": "No, go back"
},
"DeleteActivityHistoryScreenConfirmed": {
"Header": "History activty deleted",
"Title": "All history activity deleted",
"Description": "The Ontario Wallet deleted all your activity history.",
"Continue": "Continue",
},
"NoHistory": "No History",
},
"History": {
"SortFilterButton":"Sort/Filter",
"SortBy": "Sort by",
"Sort": {
"Newest": "Newest to oldest",
"Oldest": "Oldest to Newest"
},
"Filter": {
"FilterByDate": "Filter by date range",
"Select": "Select",
"Today": "Today",
"Week": "Last week",
"Month": "Last 30 days",
"TwoMonth": "Last 60 days",
"ThreeMonth": "Last 90 days",
"Year": "This year",
"AllTime": "All time",
"FilterByActivity": "Filter by activity type",
"CardUpdates": "Card updates",
"InformationRequests": "Information requests",
"WalletPinUpdates": "Wallet PIN updates",
"Buttons": {
"Apply": "Apply filters",
"Close": "Close"
}
},
"Initial":{
"Title": "Do you want to log your wallet activity?",
"Description": {
"Header": "This History section can list when:\n",
"PointA": "You have <b>shared information</b> with a verifier",
"PointAAxs": "You have shared information with a verifier",
"PointB": "A card is <b>accepted, revoked or expired</b>",
"PointBAxs": "A card is accepted, revoked or expired",
"PointC": "You have updated your <b>PIN</b>",
"PointCAxs": "You have updated your PIN",
"Footer": "\nYour wallet activity will <b>only be stored on your device</b>, and you can choose how often it is automatically deleted.",
"FooterAxs": "Your wallet activity will only be stored on your device, and you can choose how often it is automatically deleted."
},
"Button": {
"SetUpHistoryLog": "Set up your History log",
"StartLoggingWalletActivity": "Start logging wallet activity",
"DoNotLogWalletActivity": "Do not log any wallet activity"
}
},
"Button":"Sort/Filter",
"NoHistory": "You haven't used any cards yet.\n\nEach time you add or use a card, that activity will be saved here.",
"CardTitle":{
"CardAccepted": "Card accepted:",
"CardDeclined": "Card declined:",
"CardExpired": "Card expired",
"CardRevoked": "Card revoked",
"InformationSent": "Information sent to:",
"WalletPinUpdated": "Wallet PIN updated",
},
"CardDescription":{
"CardExpired": "{{cardName}} expired",
"CardRevoked": "{{cardName}} revoked",
"WalletPinUpdated": "New PIN set",
},
"Today": "Today",
"UseHistoryCapability": "Enable history",
"UseHistoryCapabilityToggle": "Toggle Enable history",
},
"Contacts": {
"EmptyList": "Your Contacts is empty!",
"TypeHere": "Message this contact...",
Expand Down Expand Up @@ -600,6 +732,9 @@ const translation = {
"ProofRequesting": 'Proof Requesting',
"NameWallet": "Name your wallet",
"RenameContact": "Edit Contact Name",
"HistorySettings": "History Settings",
"History": "History",
"HistoryDetails": "History Details",
},
"Loading": {
"TakingTooLong": "This is taking longer than usual. You can return to home or continue waiting.",
Expand Down
Loading

0 comments on commit 6da353c

Please sign in to comment.