{t("sidebar.totalBalance")}
diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx
index 06670b1..c6dfa7e 100644
--- a/src/pages/DashboardPage.tsx
+++ b/src/pages/DashboardPage.tsx
@@ -1,20 +1,28 @@
import React from "react";
import { Button, message } from "antd";
-import { useSelector, shallowEqual } from "react-redux";
+import { useDispatch, useSelector, shallowEqual } from "react-redux";
import { RootState } from "../store";
+import { syncWallets } from "../krist/wallets/Wallet";
+
import { PageLayout } from "../layout/PageLayout";
import { AuthorisedAction } from "../components/auth/AuthorisedAction";
export function DashboardPage(): JSX.Element {
const { isAuthed, hasMasterPassword }
= useSelector((s: RootState) => s.walletManager, shallowEqual);
+ const { wallets } = useSelector((s: RootState) => s.wallets, shallowEqual);
+ const dispatch = useDispatch();
return
{/* TODO */}
Is authed: {isAuthed ? "yes" : "no"}
Has master password: {hasMasterPassword ? "yes" : "no"}
+
+
+
+
;
}
diff --git a/src/pages/wallets/WalletsTable.tsx b/src/pages/wallets/WalletsTable.tsx
new file mode 100644
index 0000000..245d9d6
--- /dev/null
+++ b/src/pages/wallets/WalletsTable.tsx
@@ -0,0 +1,54 @@
+import React from "react";
+import { Table } from "antd";
+
+import { useDispatch, useSelector, shallowEqual } from "react-redux";
+import { RootState } from "../../store";
+import { useTranslation } from "react-i18next";
+
+import { KristValue } from "../../components/KristValue";
+
+export function WalletsTable(): JSX.Element {
+ const { t } = useTranslation();
+
+ const { wallets } = useSelector((s: RootState) => s.wallets, shallowEqual);
+ const dispatch = useDispatch();
+
+ return
+ },
+ {
+ title: t("myWallets.columnNames"),
+ dataIndex: "names",
+ key: "names"
+ },
+ {
+ title: t("myWallets.columnCategory"),
+ dataIndex: "category",
+ key: "category"
+ },
+ {
+ title: t("myWallets.columnFirstSeen"),
+ dataIndex: "firstSeen",
+ key: "firstSeen"
+ }
+ ]}
+ />;
+}
diff --git a/src/store/actions/WalletsActions.ts b/src/store/actions/WalletsActions.ts
index ddf1df7..93e8676 100644
--- a/src/store/actions/WalletsActions.ts
+++ b/src/store/actions/WalletsActions.ts
@@ -24,3 +24,7 @@
export interface SyncWalletPayload { id: string; wallet: WalletSyncable };
export const syncWallet = createAction(constants.SYNC_WALLET,
(id, wallet): SyncWalletPayload => ({ id, wallet }))();
+
+export interface SyncWalletsPayload { wallets: Record };
+export const syncWallets = createAction(constants.SYNC_WALLETS,
+ (wallets): SyncWalletsPayload => ({ wallets }))();
diff --git a/src/store/constants.ts b/src/store/constants.ts
index d814e49..3cac3b6 100644
--- a/src/store/constants.ts
+++ b/src/store/constants.ts
@@ -10,6 +10,7 @@
export const REMOVE_WALLET = "REMOVE_WALLET";
export const UPDATE_WALLET = "UPDATE_WALLET";
export const SYNC_WALLET = "SYNC_WALLET";
+export const SYNC_WALLETS = "SYNC_WALLETS";
// Settings
// ---
diff --git a/src/store/reducers/WalletsReducer.ts b/src/store/reducers/WalletsReducer.ts
index 8513558..3e21880 100644
--- a/src/store/reducers/WalletsReducer.ts
+++ b/src/store/reducers/WalletsReducer.ts
@@ -1,16 +1,17 @@
-import { addWallet, loadWallets, removeWallet, syncWallet, updateWallet } from "../actions/WalletsActions";
+import * as actions from "../actions/WalletsActions";
import { createReducer, ActionType } from "typesafe-actions";
-import { Wallet } from "../../krist/wallets/Wallet";
+import { Wallet, loadWallets } from "../../krist/wallets/Wallet";
export interface WalletMap { [key: string]: Wallet }
export interface State {
readonly wallets: WalletMap;
}
-const initialState: State = {
- wallets: {}
-};
+export function getInitialWalletsState(): State {
+ const wallets = loadWallets();
+ return { wallets };
+}
function assignNewWalletProperties(state: State, id: string, partialWallet: Partial) {
// Fetch the old wallet and assign the new properties
@@ -25,9 +26,9 @@
};
}
-export const WalletsReducer = createReducer(initialState)
+export const WalletsReducer = createReducer({ wallets: {} } as State)
// Load wallets
- .handleAction(loadWallets, (state: State, { payload }: ActionType) => ({
+ .handleAction(actions.loadWallets, (state: State, { payload }: ActionType) => ({
...state,
wallets: {
...state.wallets,
@@ -35,7 +36,7 @@
}
}))
// Add wallet
- .handleAction(addWallet, (state: State, { payload }: ActionType) => ({
+ .handleAction(actions.addWallet, (state: State, { payload }: ActionType) => ({
...state,
wallets: {
...state.wallets,
@@ -43,14 +44,30 @@
}
}))
// Remove wallet
- .handleAction(removeWallet, (state: State, { payload }: ActionType) => {
+ .handleAction(actions.removeWallet, (state: State, { payload }: ActionType) => {
// Get the wallets without the one we want to remove
const { [payload.id]: _, ...wallets } = state.wallets;
return { ...state, wallets };
})
// Update wallet
- .handleAction(updateWallet, (state: State, { payload }: ActionType) =>
+ .handleAction(actions.updateWallet, (state: State, { payload }: ActionType) =>
assignNewWalletProperties(state, payload.id, payload.wallet))
// Sync wallet
- .handleAction(syncWallet, (state: State, { payload }: ActionType) =>
- assignNewWalletProperties(state, payload.id, payload.wallet));
+ .handleAction(actions.syncWallet, (state: State, { payload }: ActionType) =>
+ assignNewWalletProperties(state, payload.id, payload.wallet))
+ // Sync wallets
+ .handleAction(actions.syncWallets, (state: State, { payload }: ActionType) => {
+ const updatedWallets = Object.entries(payload.wallets)
+ .map(([id, newData]) => ({ // merge in the new data
+ ...(state.wallets[id]), // old data
+
+ // only pull the relevant keys, in case this is a full Wallet object
+ balance: newData.balance,
+ names: newData.names,
+ firstSeen: newData.firstSeen,
+ lastSynced: newData.lastSynced
+ })) // convert back to a WalletMap
+ .reduce((o, wallet) => ({ ...o, [wallet.id]: wallet }), {});
+
+ return { ...state, wallets: { ...state.wallets, ...updatedWallets }};
+ });
diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts
index fa889c7..cf62e80 100644
--- a/src/utils/i18n.ts
+++ b/src/utils/i18n.ts
@@ -48,7 +48,8 @@
},
backend: {
- queryStringParams: { v: packageJson.version }
+ queryStringParams: { v: packageJson.version },
+ loadPath: "/locales/{{lng}}.json"
}
});