Skip to content

Commit

Permalink
fix(vault): fix default network id setting (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk authored Nov 6, 2024
1 parent 2f43e8d commit 2bc5d5c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VITE_APP_E2E=false
VITE_APP_DEFAULT_NETWORK=Devnet
VITE_APP_DEFAULT_NETWORK_ID=mina:devnet
VITE_APP_MINA_PROXY_MAINNET_URL=https://api.minascan.io/node/mainnet/v1/graphql
VITE_APP_MINA_PROXY_DEVNET_URL=https://api.minascan.io/node/devnet/v1/graphql
VITE_APP_DEV_MODE=false
16 changes: 8 additions & 8 deletions packages/vault/src/account/accountState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export type AccountState = {
}

export type AccountActions = {
ensureAccount: (network: string, address: ChainAddress) => void
ensureAccount: (networkId: string, address: ChainAddress) => void
setAccountInfo: (
network: string,
networkId: string,
address: ChainAddress,
accountInfo: Record<string, AccountInfo>,
) => void

setTransactions: (
network: string,
networkId: string,
address: ChainAddress,
transactions: Record<string, Tx[]>,
) => void
Expand All @@ -30,27 +30,27 @@ export type AccountActions = {
address: ChainAddress,
) => SingleAccountState
getAccountInfo: (
network: string,
networkId: string,
address: ChainAddress,
ticker: string,
) => AccountInfo

getTransactions: (
network: string,
networkId: string,
address: ChainAddress,
ticker: string,
) => Tx[]

getTransaction: (
network: string,
networkId: string,
address: ChainAddress,
hash: string,
ticker: string,
) => Tx | undefined

addAccount: (network: string, address: ChainAddress) => void
addAccount: (networkId: string, address: ChainAddress) => void

removeAccount: (network: string, address: ChainAddress) => void
removeAccount: (networkId: string, address: ChainAddress) => void

clear: () => void
}
Expand Down
36 changes: 18 additions & 18 deletions packages/vault/src/account/accountStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,57 +33,57 @@ export const accountSlice: StateCreator<AccountStore> = (set, get) => ({
}),
)
},
setAccountInfo: (network, address, accountInfo) => {
setAccountInfo: (networkId, address, accountInfo) => {
const { accounts } = get()
const account = accounts[network]?.[address] ?? {}
const account = accounts[networkId]?.[address] ?? {}
set(
produce((state) => {
state.accounts[network][address] = {
state.accounts[networkId][address] = {
...account,
accountInfo,
}
}),
)
},
setTransactions: (network, address, transactions) => {
setTransactions: (networkId, address, transactions) => {
const { accounts } = get()
const account = accounts[network]?.[address] ?? {}
const account = accounts[networkId]?.[address] ?? {}
set(
produce((state) => {
state.accounts[network][address] = {
state.accounts[networkId][address] = {
...account,
transactions,
}
}),
)
},
addAccount: (network, address) => {
addAccount: (networkId, address) => {
set(
produce((state) => {
if (!state.accounts?.[network]?.[address]) {
state.accounts[network] = state.accounts[network] || {}
state.accounts[network][address] = {
if (!state.accounts?.[networkId]?.[address]) {
state.accounts[networkId] = state.accounts[networkId] || {}
state.accounts[networkId][address] = {
...initialSingleAccountState,
}
}
}),
)
},
removeAccount: (network, address) => {
removeAccount: (networkId, address) => {
set(
produce((state) => {
delete state.accounts[network][address]
delete state.accounts[networkId][address]
}),
)
},
getAccountsInfo: (networkId, address) => {
const { accounts } = get()
return accounts[networkId]?.[address] || initialSingleAccountState
},
getAccountInfo: (network, address, ticker) => {
getAccountInfo: (networkId, address, ticker) => {
const { accounts } = get()
return (
accounts[network]?.[address]?.accountInfo[ticker] || {
accounts[networkId]?.[address]?.accountInfo[ticker] || {
balance: { total: 0 },
nonce: 0,
inferredNonce: 0,
Expand All @@ -92,14 +92,14 @@ export const accountSlice: StateCreator<AccountStore> = (set, get) => ({
}
)
},
getTransactions: (network, address, ticker) => {
getTransactions: (networkId, address, ticker) => {
const { accounts } = get()
return accounts[network]?.[address]?.transactions[ticker] || []
return accounts[networkId]?.[address]?.transactions[ticker] || []
},
getTransaction: (network, address, hash, ticker) => {
getTransaction: (networkId, address, hash, ticker) => {
const { accounts } = get()
const transactions =
accounts[network]?.[address]?.transactions[ticker] || []
accounts[networkId]?.[address]?.transactions[ticker] || []
return transactions.find((tx) => tx.hash === hash)
},
clear: () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vault/src/network-info/network-info-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { NetworkInfoStore } from "./network-info-state"

export const networkInfoSlice: StateCreator<NetworkInfoStore> = (set, get) => ({
networkInfoV2: DEFAULT_NETWORK_INFO,
currentNetworkId: "mina:mainnet",
currentNetworkId: process.env.VITE_APP_DEFAULT_NETWORK_ID ?? "mina:mainnet",
setCurrentNetworkId: (networkId) => {
return set({ currentNetworkId: networkId })
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vault/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type StoreInstance<T> = ReturnType<

interface ImportMetaEnv {
readonly VITE_APP_LADLE: string
readonly VITE_APP_DEFAULT_NETWORK: string
readonly VITE_APP_DEFAULT_NETWORK_ID: string
}

interface ImportMeta {
Expand Down
4 changes: 2 additions & 2 deletions packages/vault/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default defineConfig([
...baseTsupConfig,
name: packageJson.name,
env: {
VITE_APP_DEFAULT_NETWORK:
process.env.VITE_APP_DEFAULT_NETWORK ?? "Mainnet",
VITE_APP_DEFAULT_NETWORK_ID:
process.env.VITE_APP_DEFAULT_NETWORK_ID ?? "mina:mainnet",
},
},
])

0 comments on commit 2bc5d5c

Please sign in to comment.