pokt-network / wallet

A simple web wallet to handle your Pocket Network accounts.
wallet-three-orpin.vercel.app
MIT License
8 stars 14 forks source link

useContext for passing around address/pubKey/ppk state #318

Closed blockjoe closed 2 years ago

blockjoe commented 2 years ago

We're currently using local storage to pass the addressHex, pubKeyHex, and ppk as state to a few places of the App. We could pass this around instead with useContext for state.

Here is everywhere that we're reading from local storage into state:

src/views/send/index.js
314:        const {addressHex, publicKeyHex, ppk} = PocketService.getUserInfo();

src/views/connect-ledger/index.js
16:    const { addressHex, publicKeyHex, ppk } = pocketService.getUserInfo();

src/views/send/send.jsx
417:    const { addressHex, publicKeyHex, ppk } = pocketService.getUserInfo();

src/views/account-detail/index.js
704:      const {addressHex, publicKeyHex, ppk} = PocketService.getUserInfo();

src/views/account-detail/accountDetail.jsx
269:    const { addressHex, publicKeyHex, ppk } = pocketService.getUserInfo();

src/components/header/index.js
48:    const { addressHex, publicKeyHex, ppk } = PocketService.getUserInfo();

and everywhere we're persisting the address, pubKey, and ppk into storage

src/components/modals/unjail-unstake/unjailUnstake.jsx
55:        pocketService.saveUserInCache(account.addressHex, publicKeyHex, ppk);
107:        pocketService.saveUserInCache(account.addressHex, publicKeyHex, ppk);

src/views/import-pocket/importPocket.jsx
104:      PocketService.saveUserInCache(
157:      PocketService.saveUserInCache(

src/views/account-detail/index.js
287:                PocketService.saveUserInCache(account.addressHex, publicKeyHex, ppk);
377:                PocketService.saveUserInCache(account.addressHex, publicKeyHex, ppk);

src/views/import-pocket/index.js
269:            PocketService.saveUserInCache(account.addressHex, account.publicKey.toString("hex"), ppk.toString());
310:            PocketService.saveUserInCache(account.addressHex, account.publicKey.toString("hex"), ppk.toString());

src/views/create/createWallet.jsx
82:        pocketService.saveUserInCache(

src/views/create/index.js
173:                PocketService.saveUserInCache(account.addressHex, account.publicKey.toString("hex"), ppkOrError.toString());

src/views/send/index.js
159:            PocketService.saveUserInCache(addressHex, publicKeyHex, ppk);

src/views/send/send.jsx
334:      pocketService.saveUserInCache(addressHex, publicKeyHex, ppk);
blockjoe commented 2 years ago

finally anywhere that we're removing a user from the cache:

src/components/header/index.js
34:    PocketService.removeUserFromCached();

src/views/create/createWallet.jsx
230:    pocketService.removeUserFromCached();