Skip to content

Commit

Permalink
Split up fio address and domain sdk call
Browse files Browse the repository at this point in the history
Not all endpoints support the older getFioNames action
  • Loading branch information
Jon-edge committed Jul 16, 2024
1 parent 798d421 commit f748a10
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- changed: FIO SDK upgraded to v1.9.2
- changed: `getFioNames` call changed to separate `getFioAddresses` and `getFioDomains` calls

## 4.12.2 (2024-07-15)

- fixed: FIO payment wallet connection error, using a temporary workaround while FIO resolves the issue with their network
Expand Down
48 changes: 29 additions & 19 deletions src/fio/FioEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ import {
import { fioApiErrorCodes, FioError } from './fioError'
import {
asFioHistoryNodeAction,
asGetFioAddress,
asGetFioBalanceResponse,
asGetFioName,
asGetFioDomains,
asHistoryResponse,
FioHistoryNodeAction,
FioTxName
Expand Down Expand Up @@ -958,18 +959,14 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
}

// Fio Addresses
let isChanged = false
try {
// NOTE: 'getFioNames' is not universally supported among apiUrls.
// TODO: Split up the request
const result = asGetFioName(
await this.multicastServers('getFioNames', {
const result = asGetFioAddress(
await this.multicastServers('getFioAddresses', {
fioPublicKey: this.walletInfo.keys.publicKey
})
)

let isChanged = false
let areAddressesChanged = false
let areDomainsChanged = false

// check addresses
if (result.fio_addresses.length !== this.otherData.fioAddresses.length) {
Expand Down Expand Up @@ -1006,9 +1003,30 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
}
}
}

if (areAddressesChanged) {
isChanged = true
this.otherData.fioAddresses = result.fio_addresses.map(
fioAddress => ({
name: fioAddress.fio_address,
bundledTxs: fioAddress.remaining_bundled_tx
})
)
}
}
} catch (e: any) {
this.warn('checkAccountInnerLoop getFioAddresses error: ', e)
}

try {
// Check domains
const result = asGetFioDomains(
await this.multicastServers('getFioDomains', {
fioPublicKey: this.walletInfo.keys.publicKey
})
)
let areDomainsChanged = false

// check domains
if (result.fio_domains.length !== this.otherData.fioDomains.length) {
areDomainsChanged = true
} else {
Expand Down Expand Up @@ -1046,14 +1064,6 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
}
}

if (areAddressesChanged) {
isChanged = true
this.otherData.fioAddresses = result.fio_addresses.map(fioAddress => ({
name: fioAddress.fio_address,
bundledTxs: fioAddress.remaining_bundled_tx
}))
}

if (areDomainsChanged) {
isChanged = true
this.otherData.fioDomains = result.fio_domains.map(fioDomain => ({
Expand All @@ -1062,11 +1072,11 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
isPublic: fioDomain.is_public === 1
}))
}

if (isChanged) this.localDataDirty()
} catch (e: any) {
this.warn('checkAccountInnerLoop getFioNames error: ', e)
}

if (isChanged) this.localDataDirty()
}

async fetchEncryptedFioRequests(
Expand Down
17 changes: 10 additions & 7 deletions src/fio/fioSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import {
asValue
} from 'cleaners'

export const asGetFioName = asObject({
export const asGetFioAddress = asObject({
fio_addresses: asArray(
asObject({
fio_address: asString,
remaining_bundled_tx: asNumber
})
)
})

export const asGetFioDomains = asObject({
fio_domains: asArray(
asObject({
fio_domain: asString,
expiration: asString,
is_public: asNumber
})
),
fio_addresses: asArray(
asObject({
fio_address: asString,
remaining_bundled_tx: asNumber
})
)
})

Expand Down

0 comments on commit f748a10

Please sign in to comment.