diff --git a/modals/wallets/modals/SendModal.tsx b/modals/wallets/modals/SendModal.tsx index b734ac14..cdb5749d 100644 --- a/modals/wallets/modals/SendModal.tsx +++ b/modals/wallets/modals/SendModal.tsx @@ -14,13 +14,17 @@ import { toJS } from "mobx" type Props = { close(): void controller: SendController + onPressSend(): void onPressScanQRReciver(): void } -export default observer(function SendModal({ close, controller, onPressScanQRReciver }) { +export default observer(function SendModal({ + close, + controller, + onPressScanQRReciver, + onPressSend, +}) { const store = useStore() - const [backHandler, setBackHandler] = useState(null) - // console.log("store.coin.coins.length :>> ", store.coin.coins.length) const hasCoins = toJS(store.coin.coins).length > 0 @@ -38,30 +42,6 @@ export default observer(function SendModal({ close, controller, onPressSc [steps, close], ) - const send = () => { - const { coin, addressInput, balance } = creater - if (coin && addressInput && balance) { - backHandler?.remove() - navigate("Loader", { - // @ts-ignore - callback: async () => { - // await wait(2000); // for example - return await store.coin.sendCoin(coin.info.coin, addressInput.value, balance) - }, - }) - } - close() - } - - useEffect(() => { - const handler = BackHandler.addEventListener("hardwareBackPress", () => { - goBack() - return true - }) - setBackHandler(handler) - return () => handler.remove() - }, [goBack]) - // --------- Header -------------- const isShowHeader = steps.title !== "Select coin" && steps.title !== "No available assets" const title = useMemo(() => (steps.title === "Send Recap" ? steps.title : "Send"), [steps.title]) @@ -101,7 +81,7 @@ export default observer(function SendModal({ close, controller, onPressSc /> )} {steps.title === "Send Recap" && ( - + )} {steps.title === "Select coin" && } diff --git a/modals/wallets/openSend.tsx b/modals/wallets/openSend.tsx index 0012e0f1..db389ebd 100644 --- a/modals/wallets/openSend.tsx +++ b/modals/wallets/openSend.tsx @@ -5,11 +5,14 @@ import { StyleProp, ViewStyle } from "react-native" import { SendController } from "./controllers" import { SendModal } from "./modals" import { store } from "stores/Store" +import { toJS } from "mobx" +import { wait } from "utils" export default function openSendModal(style: StyleProp) { const { coin } = store const controller = new SendController() - controller.creater.setCoin(coin.findAssetWithCoin(SupportedCoins.BITSONG) ?? coin.coins[0]) + const { creater } = controller + creater.setCoin(coin.findAssetWithCoin(SupportedCoins.BITSONG) ?? coin.coins[0]) const scanReciver = async () => { await gbs.close() @@ -19,6 +22,21 @@ export default function openSendModal(style: StyleProp) { }) } + const send = () => { + const { coin, addressInput, balance } = creater + if (store.coin.hasCoins && coin && addressInput && balance) { + navigate("Loader", { + // @ts-ignore + callback: async () => { + await wait(2000) // for example + return true + // return await store.coin.sendCoin(coin.info.coin, addressInput.value, balance) + }, + }) + } + close() + } + const close = () => { gbs.close() controller.clear() @@ -30,7 +48,12 @@ export default function openSendModal(style: StyleProp) { $modal: true, keyboardBehavior: "fillParent", children: () => ( - + ), }) gbs.expand() diff --git a/stores/CoinStore.ts b/stores/CoinStore.ts index f426e3d5..14ede539 100644 --- a/stores/CoinStore.ts +++ b/stores/CoinStore.ts @@ -160,6 +160,10 @@ export default class CoinStore { ) } + get hasCoins() { + return this.coins.length > 0 + } + get CanSend() { return this.walletStore.activeProfile?.type != WalletTypes.WATCH