Getting Started
Installβ
npx i --save @kiroboio/web3-react-native-safe-transfer
# or
yarn add @kiroboio/web3-react-native-safe-transfer
Contextβ
Kirobo Providerβ
KiroboProvider wrap all children with AccountContext and implement all actions related to web3 like deposit ,retrieve, collect, swap transaction after invoking appropriate action from AccountProvider
Use Accountβ
To use account store wrap application components with KiroboProvider context
KiroboProvider Application Wrapper
import { KiroboProvider } from "./kirobo";
import { Connect } from "./Connect";
import { INFURA_KEY, API_KEY, API_SECRET } from "react-native-dotenv";
export const App = () => {
return (
<KiroboProvider
infuraKey={INFURA_KEY}
apiKey={API_KEY}
apiSecret={API_SECRET}
>
<Connect />
</KiroboProvider>
);
};
Account store use mobx-state-tree lib for reactive state management . To re-render react component on account state change use observer
Each observer declaration will enable the React component to only re-render if any of it's observed data changes.
Connect with metamask
export const App = observer(() => {
const { connect } = useAccount();
const handleLogin = ({ chainId, privateKey }) => {
connect.run({ chainId, key: privateKey });
};
return <Wallet onLogin={handleLogin} />;
});
Account Store States
import React from "react";
import { Wallet } from "./Wallet";
import {
useAccount,
observer,
} from "@kiroboio/web3-react-native-safe-transfer";
export const Wallet = observer(() => {
const { address, balance } = useAccount();
return (
<div className="wallet">
address: {address}
balance: {balance}
</div>
);
});
Account Store States & Deposit Action
import React from "react";
import { Button } from "./Button";
import {
useAccount,
observer,
Connectors,
currencyValueToWei,
} from "@kiroboio/web3-react-native-safe-transfer";
export const DepositButton = observer(() => {
const { address, deposit, currency } = useAccount();
const handleDeposit = ({ to, value, passcode, message }: DepositParams) => {
deposit.run({
to,
value: currencyValueToWei(value, currency.decimals),
passcode,
message,
});
};
return <Button title="Send" onClick={handleDeposit} />;
});
Main conceptsβ
Stateβ
Get Safe Transfer current state with useAccount hook
const {
address,
balance,
} = useAccount()
Methodsβ
const {
address,
deposit,
currency,
} = useAccount()
const setDeposit = ({
to,
value,
passcode,
message,
}: DepositParams) => {
deposit({
from: address,
to,
value: currencyValueToWei(value, currency.decimals),
passcode,
message,
})
}
Commandsβ
Viewsβ
Listsβ
Get all Safe Transfers related to current address (limit 40)
const { transfers } = useAccount()
Get next limit transfers
const limit = 100
transfers.fetch(limit)
transfers.list
Get outgoing, incoming and swap Transfers
const { incoming, outgoing, swaps } = useAccount()
Observerβ
Use observer for enabling the React component to re-render if any of it's observed data changes.
import { observer } from '@kiroboio/web3-react-native-safe-transfer'
export const Address = observer(() => {
const {
address,
} = useAccount()
return address
})
Transactionsβ
Depositβ
DepositTo create a retrievable transfer that can be collected use:
const { deposit } = useAccount()
import { useAccount, currencyValueToWei } from '@kiroboio/web3-react-native-safe-transfer
const {
address,
deposit,
currency,
} = useAccount()
const setDeposit = ({
to,
value,
passcode,
message,
}: DepositParams) => {
deposit.set({
from: address,
to,
value: currencyValueToWei(value, currency.decimals),
passcode,
message,
})
}
Statusβ
const {
deposit,
} = useAccount()
Retrieveβ
RetrieveTo retrieve transfer use:
const { retrieve } = useAccount()
import { useAccount } from '@kiroboio/web3-react-native-safe-transfer
const {
retrieve,
} = useAccount()
const { transfer } = props;
const setCollect = ({
id,
}: RetrieveParams) => {
retrieve({ id: transfer.id })
}
Statusβ
const {
retrieve,
} = useAccount()
Collectβ
CollectTo collect transfer use:
const { collect } = useAccount()
import { useAccount } from '@kiroboio/web3-react-native-safe-transfer'
const {
collect,
} = useAccount()
const { transfer } = props;
const setCollect = ({
id,
passcode,
}: CollectParams) => {
collect({ id: transfer.id, passcode })
}
Statusβ
const {
collect,
} = useAccount()
Utils
Web3 Methodsβ
Helpers for convert & format currency values