Skip to content

Commit

Permalink
refactor: ✨ upd. SendModal. reorder call sendCoin
Browse files Browse the repository at this point in the history
  • Loading branch information
zheleznov163 committed Sep 9, 2022
1 parent 52f29f2 commit acf5e7c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
36 changes: 8 additions & 28 deletions modals/wallets/modals/SendModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ import { toJS } from "mobx"
type Props = {
close(): void
controller: SendController
onPressSend(): void
onPressScanQRReciver(): void
}

export default observer<Props>(function SendModal({ close, controller, onPressScanQRReciver }) {
export default observer<Props>(function SendModal({
close,
controller,
onPressScanQRReciver,
onPressSend,
}) {
const store = useStore()
const [backHandler, setBackHandler] = useState<NativeEventSubscription | null>(null)

// console.log("store.coin.coins.length :>> ", store.coin.coins.length)

const hasCoins = toJS(store.coin.coins).length > 0
Expand All @@ -38,30 +42,6 @@ export default observer<Props>(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])
Expand Down Expand Up @@ -101,7 +81,7 @@ export default observer<Props>(function SendModal({ close, controller, onPressSc
/>
)}
{steps.title === "Send Recap" && (
<SendRecap controller={controller} onPressBack={goBack} onPressSend={send} />
<SendRecap controller={controller} onPressBack={goBack} onPressSend={onPressSend} />
)}
{steps.title === "Select coin" && <SelectCoin controller={controller} onBack={goBack} />}
</>
Expand Down
27 changes: 25 additions & 2 deletions modals/wallets/openSend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewStyle>) {
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()
Expand All @@ -19,6 +22,21 @@ export default function openSendModal(style: StyleProp<ViewStyle>) {
})
}

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()
Expand All @@ -30,7 +48,12 @@ export default function openSendModal(style: StyleProp<ViewStyle>) {
$modal: true,
keyboardBehavior: "fillParent",
children: () => (
<SendModal close={close} controller={controller} onPressScanQRReciver={scanReciver} />
<SendModal
close={close}
controller={controller}
onPressScanQRReciver={scanReciver}
onPressSend={send}
/>
),
})
gbs.expand()
Expand Down
4 changes: 4 additions & 0 deletions stores/CoinStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export default class CoinStore {
)
}

get hasCoins() {
return this.coins.length > 0
}

get CanSend()
{
return this.walletStore.activeProfile?.type != WalletTypes.WATCH
Expand Down

0 comments on commit acf5e7c

Please sign in to comment.