Skip to main content

atomiq-storage-rn-async/src

@atomiqlabs/storage-rn-async

@atomiqlabs/storage-rn-async is the React Native storage adapter for the Atomiq SDK. The SDK uses browser IndexedDB by default. React Native does not have browser IndexedDB, so mobile apps need to provide storage explicitly. This package does that by using @react-native-async-storage/async-storage as the backend.

What this package provides

  • RNAsyncUnifiedStorage: persistent unified swap storage used by the SDK for swap records and indexed queries.
  • RNAsyncStorageManager: persistent storage manager used for chain-specific SDK stores.

Each constructor takes a key prefix so your app can namespace Atomiq data inside AsyncStorage.

When to use it

Use this package when you run the Atomiq SDK in:

  • React Native mobile apps
  • Expo / React Native runtimes with AsyncStorage available

If you run the SDK in the browser, you usually do not need this package because the SDK already uses IndexedDB there.

Installation

npm install @atomiqlabs/sdk @atomiqlabs/storage-rn-async

This adapter uses @react-native-async-storage/async-storage under the hood, so your React Native app must support that package.

SDK Usage

Pass RNAsyncUnifiedStorage as swapStorage and RNAsyncStorageManager as chainStorageCtor when creating the swapper.

import {BitcoinNetwork, SwapperFactory, TypedSwapper} from "@atomiqlabs/sdk";
import {RNAsyncStorageManager, RNAsyncUnifiedStorage} from "@atomiqlabs/storage-rn-async";

const chains = [SolanaInitializer, StarknetInitializer, CitreaInitializer] as const;
type SupportedChains = typeof chains;

const Factory = new SwapperFactory<SupportedChains>(chains);

const swapper: TypedSwapper<SupportedChains> = Factory.newSwapper({
chains: {
...
},
bitcoinNetwork: BitcoinNetwork.MAINNET,
// React Native does not provide the browser IndexedDB storage
// used by default in web environments, so provide AsyncStorage-backed adapters.
swapStorage: chainId => new RNAsyncUnifiedStorage(`atomiq_sdk_chain_${chainId}_`),
chainStorageCtor: name => new RNAsyncStorageManager(`atomiq_sdk_store_${name}_`)
});

await swapper.init();

Notes

  • Both storage adapters store data under the prefixes you pass in, so pick stable prefixes that do not collide with the rest of your app's AsyncStorage keys.
  • RNAsyncUnifiedStorage builds the SDK's indexed storage behavior on top of AsyncStorage, which is a plain key-value backend, hence the indexing is handled in-memory - this is therefore only suitable for single-client environments with <10,000 swaps saved.
  • Persistence depends on the durability of the app's AsyncStorage data on the device.

Classes