load mango accounts
This commit is contained in:
parent
5dd424c8da
commit
37135e35db
|
@ -28,7 +28,7 @@ const MangoAccountsList = ({
|
||||||
}: {
|
}: {
|
||||||
mangoAccount: MangoAccount
|
mangoAccount: MangoAccount
|
||||||
}) => {
|
}) => {
|
||||||
const mangoAccounts = mangoStore((s) => s.mangoAccounts)
|
const mangoAccounts = mangoStore((s) => s.mangoAccounts.accounts)
|
||||||
const [showNewAccountModal, setShowNewAccountModal] = useState(false)
|
const [showNewAccountModal, setShowNewAccountModal] = useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -45,7 +45,7 @@ const CreateAccountModal = ({
|
||||||
const handleNewAccount = async () => {
|
const handleNewAccount = async () => {
|
||||||
const client = mangoStore.getState().client
|
const client = mangoStore.getState().client
|
||||||
const group = mangoStore.getState().group
|
const group = mangoStore.getState().group
|
||||||
const mangoAccounts = mangoStore.getState().mangoAccounts
|
const mangoAccounts = mangoStore.getState().mangoAccounts.accounts
|
||||||
const actions = mangoStore.getState().actions
|
const actions = mangoStore.getState().actions
|
||||||
if (!group || !wallet) return
|
if (!group || !wallet) return
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
|
@ -4,12 +4,13 @@ import mangoStore from '../../store/state'
|
||||||
import { Wallet } from '@project-serum/anchor'
|
import { Wallet } from '@project-serum/anchor'
|
||||||
|
|
||||||
const WalletListener = () => {
|
const WalletListener = () => {
|
||||||
const set = mangoStore((s) => s.set)
|
|
||||||
const { wallet, connected, disconnecting } = useWallet()
|
const { wallet, connected, disconnecting } = useWallet()
|
||||||
const mangoAccounts = mangoStore((s) => s.mangoAccounts)
|
const loadingMangoAccounts = mangoStore((s) => s.mangoAccounts.loading)
|
||||||
|
const mangoAccounts = mangoStore((s) => s.mangoAccounts.accounts)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const actions = mangoStore.getState().actions
|
const actions = mangoStore.getState().actions
|
||||||
|
const set = mangoStore.getState().set
|
||||||
|
|
||||||
const onConnect = async () => {
|
const onConnect = async () => {
|
||||||
if (!wallet) return
|
if (!wallet) return
|
||||||
|
@ -20,9 +21,11 @@ const WalletListener = () => {
|
||||||
mangoAccounts[0].accountNum
|
mangoAccounts[0].accountNum
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
set((state) => {
|
if (!loadingMangoAccounts) {
|
||||||
state.mangoAccount.loading = false
|
set((s) => {
|
||||||
})
|
s.mangoAccount.loading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
actions.fetchProfilePicture(wallet.adapter as unknown as Wallet)
|
actions.fetchProfilePicture(wallet.adapter as unknown as Wallet)
|
||||||
actions.fetchWalletTokens(wallet.adapter as unknown as Wallet)
|
actions.fetchWalletTokens(wallet.adapter as unknown as Wallet)
|
||||||
|
@ -32,7 +35,7 @@ const WalletListener = () => {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
onConnect()
|
onConnect()
|
||||||
}
|
}
|
||||||
}, [wallet, connected, mangoAccounts.length])
|
}, [wallet, connected, loadingMangoAccounts, mangoAccounts.length])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const setStore = mangoStore.getState().set
|
const setStore = mangoStore.getState().set
|
||||||
|
|
|
@ -103,7 +103,7 @@ export type MangoStore = {
|
||||||
tradeHistory: { data: TradeHistoryItem[]; loading: boolean }
|
tradeHistory: { data: TradeHistoryItem[]; loading: boolean }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mangoAccounts: MangoAccount[]
|
mangoAccounts: { accounts: MangoAccount[]; loading: boolean }
|
||||||
markets: Serum3Market[] | undefined
|
markets: Serum3Market[] | undefined
|
||||||
notificationIdCounter: number
|
notificationIdCounter: number
|
||||||
notifications: Array<Notification>
|
notifications: Array<Notification>
|
||||||
|
@ -168,7 +168,7 @@ const mangoStore = create<MangoStore>(
|
||||||
tradeHistory: { data: [], loading: false },
|
tradeHistory: { data: [], loading: false },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mangoAccounts: [],
|
mangoAccounts: { accounts: [], loading: true },
|
||||||
markets: undefined,
|
markets: undefined,
|
||||||
notificationIdCounter: 0,
|
notificationIdCounter: 0,
|
||||||
notifications: [],
|
notifications: [],
|
||||||
|
@ -382,7 +382,8 @@ const mangoStore = create<MangoStore>(
|
||||||
)
|
)
|
||||||
if (mangoAccounts.length) {
|
if (mangoAccounts.length) {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.mangoAccounts = mangoAccounts
|
state.mangoAccounts.accounts = mangoAccounts
|
||||||
|
state.mangoAccounts.loading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue