ensure wallet id is in sync before saving the config
This commit is contained in:
parent
a6665bca6a
commit
1beac3a405
|
@ -117,7 +117,7 @@ export function useVaultMigration () {
|
||||||
migratedCount++
|
migratedCount++
|
||||||
console.log('migrated to vault:', entryName)
|
console.log('migrated to vault:', entryName)
|
||||||
} else {
|
} else {
|
||||||
throw new Error('could not set vault entry')
|
console.log('could not set vault entry:', entryName)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('failed migrate to vault:', entryName, e)
|
console.error('failed migrate to vault:', entryName, e)
|
||||||
|
|
|
@ -185,6 +185,15 @@ function useConfig (walletDef) {
|
||||||
const canSend = !!walletDef?.sendPayment
|
const canSend = !!walletDef?.sendPayment
|
||||||
const canReceive = !walletDef?.clientOnly
|
const canReceive = !walletDef?.clientOnly
|
||||||
|
|
||||||
|
const queryServerWallet = useCallback(async () => {
|
||||||
|
const wallet = await client.query({
|
||||||
|
query: WALLET_BY_TYPE,
|
||||||
|
variables: { type: walletDef.walletType },
|
||||||
|
fetchPolicy: 'network-only'
|
||||||
|
})
|
||||||
|
return wallet?.data?.walletByType
|
||||||
|
}, [walletDef, client])
|
||||||
|
|
||||||
const refreshConfig = useCallback(async () => {
|
const refreshConfig = useCallback(async () => {
|
||||||
if (walletDef) {
|
if (walletDef) {
|
||||||
let newConfig = {}
|
let newConfig = {}
|
||||||
|
@ -193,32 +202,28 @@ function useConfig (walletDef) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch server config
|
// fetch server config
|
||||||
const serverConfig = await client.query({
|
const serverConfig = await queryServerWallet()
|
||||||
query: WALLET_BY_TYPE,
|
|
||||||
variables: { type: walletDef.walletType },
|
|
||||||
fetchPolicy: 'network-only'
|
|
||||||
})
|
|
||||||
|
|
||||||
if (serverConfig?.data?.walletByType) {
|
if (serverConfig) {
|
||||||
newConfig = {
|
newConfig = {
|
||||||
...newConfig,
|
...newConfig,
|
||||||
id: serverConfig.data.walletByType.id,
|
id: serverConfig.id,
|
||||||
priority: serverConfig.data.walletByType.priority,
|
priority: serverConfig.priority,
|
||||||
enabled: serverConfig.data.walletByType.enabled
|
enabled: serverConfig.enabled
|
||||||
}
|
}
|
||||||
if (serverConfig.data.walletByType.wallet) {
|
if (serverConfig.wallet) {
|
||||||
newConfig = {
|
newConfig = {
|
||||||
...newConfig,
|
...newConfig,
|
||||||
...serverConfig.data.walletByType.wallet
|
...serverConfig.wallet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch client config
|
// fetch client config
|
||||||
let clientConfig = {}
|
let clientConfig = {}
|
||||||
if (serverConfig?.data?.walletByType) {
|
if (serverConfig) {
|
||||||
if (clientVault.current) clientVault.current.close()
|
if (clientVault.current) clientVault.current.close()
|
||||||
const newClientVault = openVault(client, me, serverConfig.data.walletByType)
|
const newClientVault = openVault(client, me, serverConfig)
|
||||||
clientVault.current = newClientVault
|
clientVault.current = newClientVault
|
||||||
clientConfig = await newClientVault.get(walletDef.name, {})
|
clientConfig = await newClientVault.get(walletDef.name, {})
|
||||||
if (clientConfig) {
|
if (clientConfig) {
|
||||||
|
@ -248,7 +253,7 @@ function useConfig (walletDef) {
|
||||||
innerSetConfig(newConfig)
|
innerSetConfig(newConfig)
|
||||||
|
|
||||||
// set wallet ref
|
// set wallet ref
|
||||||
innerSetCurrentWallet(serverConfig.data.walletByType)
|
innerSetCurrentWallet(serverConfig)
|
||||||
}
|
}
|
||||||
}, [walletDef, me])
|
}, [walletDef, me])
|
||||||
|
|
||||||
|
@ -257,6 +262,7 @@ function useConfig (walletDef) {
|
||||||
}, [walletDef, me])
|
}, [walletDef, me])
|
||||||
|
|
||||||
const saveConfig = useCallback(async (newConfig, { logger, skipTests }) => {
|
const saveConfig = useCallback(async (newConfig, { logger, skipTests }) => {
|
||||||
|
const serverConfig = await queryServerWallet()
|
||||||
const priorityOnly = skipTests
|
const priorityOnly = skipTests
|
||||||
try {
|
try {
|
||||||
// gather configs
|
// gather configs
|
||||||
|
@ -308,7 +314,7 @@ function useConfig (walletDef) {
|
||||||
const mutation = generateMutation(walletDef)
|
const mutation = generateMutation(walletDef)
|
||||||
const variables = {
|
const variables = {
|
||||||
...newServerConfig,
|
...newServerConfig,
|
||||||
id: currentWallet?.id,
|
id: serverConfig?.id,
|
||||||
settings: {
|
settings: {
|
||||||
autoWithdrawThreshold: Number(autoWithdrawThreshold == null ? autowithdrawSettings.autoWithdrawThreshold : autoWithdrawThreshold),
|
autoWithdrawThreshold: Number(autoWithdrawThreshold == null ? autowithdrawSettings.autoWithdrawThreshold : autoWithdrawThreshold),
|
||||||
autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent == null ? autowithdrawSettings.autoWithdrawMaxFeePercent : autoWithdrawMaxFeePercent),
|
autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent == null ? autowithdrawSettings.autoWithdrawMaxFeePercent : autoWithdrawMaxFeePercent),
|
||||||
|
|
Loading…
Reference in New Issue