Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beasy-mobile
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
G
beasy-mobile
Commits
7d90e026
Commit
7d90e026
authored
Sep 06, 2024
by
G
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://barnoin.ldfgroupe.com:2017/gitlab/idouattara/beasy-mobile
into dev
parents
f29687c1
bc445c69
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
7 deletions
+43
-7
useOrangeMoney.tsx
src/hooks/useOrangeMoney.tsx
+43
-7
No files found.
src/hooks/useOrangeMoney.tsx
View file @
7d90e026
...
...
@@ -13,7 +13,9 @@ import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
import
{
useMutation
,
useQueryClient
}
from
"@tanstack/react-query"
;
import
{
AxiosError
}
from
"axios"
;
import
*
as
WebBrowser
from
"expo-web-browser"
;
import
{
useState
}
from
"react"
;
import
{
useRef
,
useState
}
from
"react"
;
import
{
AppState
,
Platform
}
from
"react-native"
;
const
log
=
LOG
.
extend
(
"useOrangeMoney"
);
...
...
@@ -37,6 +39,8 @@ const useOrangeMoney = (
const
[
isBrowserOpen
,
setIsBrowserOpen
]
=
useState
(
false
);
const
{
showModal
,
closeModal
}
=
useModalsManagerContext
();
const
appState
=
useRef
(
AppState
.
currentState
);
const
[
appStateVisible
,
setAppStateVisible
]
=
useState
(
appState
.
current
);
const
handlePaymentUsingBrowser
=
async
(
url
:
string
)
=>
{
setIsBrowserOpen
(
true
);
...
...
@@ -121,12 +125,44 @@ const useOrangeMoney = (
const
openBrowserThenCheckStatus
=
async
(
paymentUrl
:
string
,
orderId
:
string
)
=>
{
try
{
await
handlePaymentUsingBrowser
(
paymentUrl
);
log
.
info
(
"openBrowserThenCheckStatus | Verifying transaction status..."
);
showModal
(<
LoadingModal
message=
"Vérification du statut de la transaction..."
/>);
// await transactionsStatusMutation.mutateAsync(orderId);
const
message
=
await
checkStatus
(
orderId
);
if
(
message
)
{
showModal
(<
ErrorModal
message=
{
message
}
/>);
if
(
Platform
.
OS
===
"android"
)
{
log
.
debug
(
"useOrangeMoney | openBrowserThenCheckStatus | Android device. Setup listener for browser close event."
,
);
const
sub
=
AppState
.
addEventListener
(
"change"
,
async
(
nextAppState
)
=>
{
log
.
debug
(
"useOrangeMoney | openBrowserThenCheckStatus | Android device. Browser state :"
,
nextAppState
,
);
if
(
nextAppState
===
"active"
)
{
log
.
debug
(
"useOrangeMoney | openBrowserThenCheckStatus | Android device. Browser is closed. Removing listener. Checking for transaction State."
,
);
sub
.
remove
();
log
.
info
(
"openBrowserThenCheckStatus | Verifying transaction status..."
);
showModal
(
<
LoadingModal
message=
"Vérification du statut de la transaction..."
/>,
);
// await transactionsStatusMutation.mutateAsync(orderId);
const
message
=
await
checkStatus
(
orderId
);
if
(
message
)
{
showModal
(<
ErrorModal
message=
{
message
}
/>);
}
else
{
navigation
?.
getParent
()?.
navigate
(
"paymentResultScreen"
);
}
}
});
}
else
{
log
.
info
(
"openBrowserThenCheckStatus | Verifying transaction status..."
);
showModal
(<
LoadingModal
message=
"Vérification du statut de la transaction..."
/>);
// await transactionsStatusMutation.mutateAsync(orderId);
const
message
=
await
checkStatus
(
orderId
);
if
(
message
)
{
showModal
(<
ErrorModal
message=
{
message
}
/>);
}
else
{
navigation
?.
getParent
()?.
navigate
(
"paymentResultScreen"
);
}
}
// closeModal();
}
catch
(
error
:
unknown
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment