Skip to content

Commit

Permalink
retain lev stake accounts and use for calculating next account num (#448
Browse files Browse the repository at this point in the history
)
  • Loading branch information
riordanp authored Oct 1, 2024
1 parent 50969d6 commit 8fef0d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion components/account/CreateAccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const CreateAccountForm = ({
const handleNewAccount = useCallback(async () => {
const client = mangoStore.getState().client
const group = mangoStore.getState().group
const existingMangoAccts = mangoStore.getState().mangoAccounts
const existingMangoAccts = [
...mangoStore.getState().mangoAccounts,
...mangoStore.getState().mangoAccountsLevStake,
]
const set = mangoStore.getState().set
const connection = mangoStore.getState().connection

Expand Down
12 changes: 10 additions & 2 deletions store/mangoStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export type MangoStore = {
}
}
mangoAccounts: MangoAccount[]
mangoAccountsLevStake: MangoAccount[]
markets: Serum3Market[] | undefined
transactionNotificationIdCounter: number
transactionNotifications: Array<TransactionNotification>
Expand Down Expand Up @@ -416,6 +417,7 @@ const mangoStore = create<MangoStore>()(
tradeHistory: { data: [], loading: true },
},
mangoAccounts: [],
mangoAccountsLevStake: [],
markets: undefined,
transactionNotificationIdCounter: 0,
transactionNotifications: [],
Expand Down Expand Up @@ -683,12 +685,17 @@ const mangoStore = create<MangoStore>()(
client.getMangoAccountsForDelegate(group, ownerPk),
])

const mangoAccounts = [
const allMangoAccounts = [
...ownerMangoAccounts,
...delegateAccounts,
].filter(
]

const mangoAccounts = allMangoAccounts.filter(
(acc) => hasLevCloseInUrl || !acc.name.includes('Leverage Stake'),
)
const mangoAccountsLevStake = allMangoAccounts.filter(
(acc) => !hasLevCloseInUrl && acc.name.includes('Leverage Stake'),
)
const selectedAccountIsNotInAccountsList = mangoAccounts.find(
(x) =>
x.publicKey.toBase58() ===
Expand Down Expand Up @@ -734,6 +741,7 @@ const mangoStore = create<MangoStore>()(

set((state) => {
state.mangoAccounts = mangoAccounts
state.mangoAccountsLevStake = mangoAccountsLevStake
})
} catch (e) {
console.error('Error fetching mango accts', e)
Expand Down

0 comments on commit 8fef0d2

Please sign in to comment.