Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const startScanAccountsDevice = useCallback(() => {
const syncConfig = {
// TODO later we need to paginate only a few ops, not all (for add accounts)
// paginationConfig will come from redux
paginationConfig: {},
};
unsub();
scanSubscription.current = getCurrencyBridge(currency)
.scanAccounts({ currency, deviceId, syncConfig })
.pipe(
reduce(
(all: Account[], event: ScanAccountEvent) =>
all.concat(event.account),
[],
),
)
.subscribe({
next: scannedAccounts => {
setAccounts(
migrateAccounts({ scannedAccounts, existingAccounts: accounts }),
);
setStatus("done");
},
error: err => {
startScanAccountsDevice() {
this.unsub()
const { currency, device, setScanStatus, setScannedAccounts } = this.props
if (!currency || !device) return
const mainCurrency = currency.type === 'TokenCurrency' ? currency.parentCurrency : currency
try {
const bridge = getCurrencyBridge(mainCurrency)
// TODO: use the real device
const devicePath = device.path
// will be set to false if an existing account is found
let onlyNewAccounts = true
this.scanSubscription = bridge
.scanAccountsOnDevice(mainCurrency, devicePath)
.pipe(
filter(e => e.type === 'discovered'),
map(e => e.account),
)
.subscribe({
next: account => {
const { scannedAccounts, checkedAccountsIds, existingAccounts } = this.props
startSubscription = () => {
const { navigation } = this.props;
const currency = navigation.getParam("currency");
const deviceId = navigation.getParam("deviceId");
const bridge = getCurrencyBridge(currency);
const syncConfig = {
// TODO later we need to paginate only a few ops, not all (for add accounts)
// paginationConfig will come from redux
paginationConfig: {},
};
this.scanSubscription = concat(
from(prepareCurrency(currency)).pipe(ignoreElements()),
bridge.scanAccounts({ currency, deviceId, syncConfig }),
).subscribe({
next: ({ account }) =>
this.setState(
({ scannedAccounts, selectedIds }, { existingAccounts }) => {
const hasAlreadyBeenScanned = !!scannedAccounts.find(
a => account.id === a.id,
);
const hasAlreadyBeenImported = !!existingAccounts.find(
currenciesRelated.map(({ currencyData, currency, impl }) => {
const bridge = getCurrencyBridge(currency);
describe(impl + " " + currency.id + " currency bridge", () => {
test("functions are defined", () => {
expect(typeof bridge.scanAccounts).toBe("function");
expect(typeof bridge.preload).toBe("function");
expect(typeof bridge.hydrate).toBe("function");
});
test("preload and rehydrate", async () => {
const data1 = await bridge.preload();
const serialized = JSON.stringify(data1);
if (data1) {
expect(serialized).toBeDefined();
const data2 = await bridge.preload();
expect(data1).toMatchObject(data2);
expect(JSON.parse(serialized)).toMatchObject(data2);
bridge.hydrate(data1);
export async function hydrateCurrency(currency: CryptoCurrency) {
const value = await getCurrencyCache(currency);
const bridge = getCurrencyBridge(currency);
bridge.hydrate(value);
}
async currency => {
const bridge = getCurrencyBridge(currency)
const preloaded = await bridge.preload()
setCurrencyCache(currency, preloaded)
},
currency => currency.id,
async currency => {
log("bridge/cache", "prepareCurrency " + currency.id + "...");
const bridge = getCurrencyBridge(currency);
const preloaded = await bridge.preload();
await setCurrencyCache(currency, preloaded);
log("bridge/cache", "prepareCurrency " + currency.id + " DONE.");
},
currency => currency.id,
spendableBalance: new BigNumber(0),
operationsCount: 0,
operations: [],
pendingOperations: []
};
return account;
})
).pipe(
concatMap(account =>
getAccountBridge(account, null)
.sync(account, syncConfig)
.pipe(reduce((a: Account, f: *) => f(a), account))
)
);
}
return getCurrencyBridge(cur)
.scanAccounts({
currency: cur,
deviceId: device || "",
scheme: scheme && asDerivationMode(scheme),
syncConfig
})
.pipe(
filter(e => e.type === "discovered"),
map(e => e.account)
);
}),
skip(index || 0),