Skip to content

Commit

Permalink
chore: draft batch account creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Nov 11, 2024
1 parent 1e14cc3 commit abb3176
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
8 changes: 4 additions & 4 deletions apps/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ PODS:
- ExpoModulesCore
- ExpoLocalAuthentication (14.0.1):
- ExpoModulesCore
- ExpoModulesCore (1.12.20):
- ExpoModulesCore (1.12.26):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1640,7 +1640,7 @@ DEPENDENCIES:
- "ExpoImage (from `../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@[email protected]_pqycbzooiimpwcftmzylw6b6ue/node_modules/expo-image/ios`)"
- "ExpoKeepAwake (from `../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@babel+core@7_w5fcokd4xqykouihhq65zfvhwu/node_modules/expo-keep-awake/ios`)"
- "ExpoLocalAuthentication (from `../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@ba_bcvjridgatxs26fiu2o33lgbby/node_modules/expo-local-authentication/ios`)"
- "ExpoModulesCore (from `../../../node_modules/.pnpm/[email protected].20/node_modules/expo-modules-core`)"
- "ExpoModulesCore (from `../../../node_modules/.pnpm/[email protected].26/node_modules/expo-modules-core`)"
- "ExpoSecureStore (from `../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]._qblhklgyytdrqryzqbjo45ylay/node_modules/expo-secure-store/ios`)"
- "ExpoSystemUI (from `../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@[email protected]_36opljfl2csscygkp6xjaz2hv4/node_modules/expo-system-ui/ios`)"
- "ExpoWebBrowser (from `../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@babel+core@_rn7tpmwskp4kjoe2dtluysnlry/node_modules/expo-web-browser/ios`)"
Expand Down Expand Up @@ -1773,7 +1773,7 @@ EXTERNAL SOURCES:
ExpoLocalAuthentication:
:path: "../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@ba_bcvjridgatxs26fiu2o33lgbby/node_modules/expo-local-authentication/ios"
ExpoModulesCore:
:path: "../../../node_modules/.pnpm/[email protected].20/node_modules/expo-modules-core"
:path: "../../../node_modules/.pnpm/[email protected].26/node_modules/expo-modules-core"
ExpoSecureStore:
:path: "../../../node_modules/.pnpm/[email protected][email protected]_@[email protected]._qblhklgyytdrqryzqbjo45ylay/node_modules/expo-secure-store/ios"
ExpoSystemUI:
Expand Down Expand Up @@ -1938,7 +1938,7 @@ SPEC CHECKSUMS:
ExpoImage: eab004b9363e388d3f6a118f18716de6dcfb8e8d
ExpoKeepAwake: 3b8815d9dd1d419ee474df004021c69fdd316d08
ExpoLocalAuthentication: 9e02a56a4cf9868f0052656a93d4c94101a42ed7
ExpoModulesCore: 5440e96a8ee014f4fd88e77264985fd0a65f5f8c
ExpoModulesCore: 831ece8311a489418746925820bbffdda587d6f4
ExpoSecureStore: 060cebcb956b80ddae09821610ac1aa9e1ac74cd
ExpoSystemUI: d4f065a016cae6721b324eb659cdee4d4cf0cb26
ExpoWebBrowser: 7595ccac6938eb65b076385fd23d035db9ecdc8e
Expand Down
22 changes: 22 additions & 0 deletions apps/mobile/src/store/accounts/accounts.write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ export const accountsSlice = createSlice({
})
);
})
.addCase(userAddsAccounts, (state, action) => {
// const thisWalletsAccounts = getWalletAccountsByAccountId(
// state,
// action.payload[0].account.id
// );
const accounts = action.payload.map((payload, index) =>
addAccountDefaults({
account: payload.account,
accountIdx: index + 1,
})
);
return accountsAdapter.addMany(state, accounts);
// return accountsAdapter.addOne(
// state,
// addAccountDefaults({
// account: action.payload.account,
// accountIdx: thisWalletsAccounts.length + 1,
// })
// );
})

.addCase(
userTogglesHideAccount,
Expand Down Expand Up @@ -127,6 +147,8 @@ interface AddAccountPayload {
};
}
export const userAddsAccount = createAction<AddAccountPayload>('accounts/userAddsAccount');
// check this as should each account have a keychains array? maybe they are single address arrays??
export const userAddsAccounts = createAction<AddAccountPayload[]>('accounts/userAddsAccounts');

interface ToggleHideAccountPayload {
accountId: string;
Expand Down
41 changes: 31 additions & 10 deletions apps/mobile/src/store/key-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
import { useBitcoinClient } from '@leather.io/query';
import { stacksRootKeychainToAccountDescriptor } from '@leather.io/stacks';

import { userAddsAccount, userTogglesHideAccount } from './accounts/accounts.write';
import {
userAddsAccount,
userAddsAccounts,
userTogglesHideAccount,
} from './accounts/accounts.write';
import { recurseAccountsForActivity } from './accounts/recurse-accounts';
import { useBitcoinAccounts } from './keychains/bitcoin/bitcoin-keychains.read';
import { findHighestAccountIndexOfFingerprint } from './keychains/keychains';
Expand Down Expand Up @@ -92,8 +96,21 @@ export function useKeyStore() {
withKeychains: { bitcoin: bitcoinKeychains, stacks: stacksKeychains },
});
},
async createNewAccountOfWallet(fingerprint: string) {
const { accountIndex, bitcoinKeychains, stacksKeychains } =
await this.deriveNextAccountKeychainsFrom(fingerprint);

async createNewAccountOfWallet(fingerprint: string, activeAccounts: number) {
dispatch(
userAddsAccount({
account: { id: makeAccountIdentifer(fingerprint, accountIndex) },
withKeychains: {
bitcoin: bitcoinKeychains,
stacks: stacksKeychains,
},
})
);
},
async createNewAccountsOfWallet(fingerprint: string, activeAccounts: number) {
const { accountIndex, bitcoinKeychains, stacksKeychains } =
await this.deriveNextAccountKeychainsFrom(fingerprint);

Expand All @@ -106,13 +123,17 @@ export function useKeyStore() {
// this works but just adds one new account with index = activeAccounts which is wrong
// that account is also showing the same STX balance as the first account
dispatch(
userAddsAccount({
account: { id: makeAccountIdentifer(fingerprint, accountId) },
withKeychains: {
bitcoin: bitcoinKeychains,
stacks: stacksKeychains,
},
})
userAddsAccounts(
Array.from({ length: activeAccounts }, (_, i) => ({
account: {
id: makeAccountIdentifer(fingerprint, i),
},
withKeychains: {
bitcoin: bitcoinKeychains,
stacks: stacksKeychains,
},
}))
)
);
},

Expand Down Expand Up @@ -231,7 +252,7 @@ export function useKeyStore() {
// if (recursiveActivityIndex <= 3) return;
// check why this was always 0 for my wallet?
console.log('Found accounts to restore', activeAccounts);

Check failure on line 254 in apps/mobile/src/store/key-store.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement

Check failure on line 254 in apps/mobile/src/store/key-store.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

disallow literal string
this.createNewAccountOfWallet(fingerprint, activeAccounts);
this.createNewAccountsOfWallet(fingerprint, activeAccounts);

Check warning on line 255 in apps/mobile/src/store/key-store.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
// PETE - the bug was here in that it was returning the most recent account not the highest index
// dispatch(some action to update active accounts)
// then in the reducer generate accounts based on that number
Expand Down
3 changes: 3 additions & 0 deletions apps/mobile/src/store/keychains/stacks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
import { deriveStxPrivateKey } from '@stacks/wallet-sdk';
import z from 'zod';

// todo fix this deprecated import
import { mnemonicToRootNode } from '@leather.io/bitcoin';

const stacksKeychainSchema = z.object({
// Stacks doesn't use the concept of BIP-380 Descriptors the same way Bitcoin
// does. However, we need to store the same data. Reusing this structure
Expand Down

0 comments on commit abb3176

Please sign in to comment.