|
9 | 9 | #include "Kismet/GameplayStatics.h" |
10 | 10 | #include "ThirdwebLog.h" |
11 | 11 |
|
12 | | -void UAsyncTaskThirdwebLoginWithSiwe::Activate() { |
13 | | - Browser->OnSiweComplete.AddDynamic(this, &ThisClass::HandleSiweComplete); |
14 | | - Browser->OnError.AddDynamic(this, &ThisClass::HandleFailed); |
15 | | - Browser->AddToViewport(10000); |
16 | | - Browser->Authenticate(Wallet); |
| 12 | +void UAsyncTaskThirdwebLoginWithSiwe::Activate() |
| 13 | +{ |
| 14 | + Browser->OnSiweComplete.AddDynamic(this, &ThisClass::HandleSiweComplete); |
| 15 | + Browser->OnError.AddDynamic(this, &ThisClass::HandleFailed); |
| 16 | + Browser->AddToViewport(10000); |
| 17 | + Browser->Authenticate(Wallet); |
17 | 18 | } |
18 | 19 |
|
19 | | -UAsyncTaskThirdwebLoginWithSiwe *UAsyncTaskThirdwebLoginWithSiwe::LoginWithSiwe( |
20 | | - UObject *WorldContextObject, const FInAppWalletHandle &Wallet) { |
21 | | - if (!WorldContextObject) { |
22 | | - return nullptr; |
23 | | - } |
24 | | - NEW_TASK |
25 | | - Task->Wallet = Wallet; |
26 | | - Task->Browser = CreateWidget<UThirdwebOAuthBrowserUserWidget>( |
27 | | - UGameplayStatics::GetGameInstance(WorldContextObject), |
28 | | - UThirdwebOAuthBrowserUserWidget::StaticClass()); |
29 | | - Task->RegisterWithGameInstance(WorldContextObject); |
30 | | - return Task; |
| 20 | +UAsyncTaskThirdwebLoginWithSiwe* UAsyncTaskThirdwebLoginWithSiwe::LoginWithSiwe(UObject* WorldContextObject, const FInAppWalletHandle& Wallet) |
| 21 | +{ |
| 22 | + if (!WorldContextObject) |
| 23 | + { |
| 24 | + return nullptr; |
| 25 | + } |
| 26 | + NEW_TASK |
| 27 | + Task->Wallet = Wallet; |
| 28 | + Task->Browser = CreateWidget<UThirdwebOAuthBrowserUserWidget>(UGameplayStatics::GetGameInstance(WorldContextObject), |
| 29 | + UThirdwebOAuthBrowserUserWidget::StaticClass()); |
| 30 | + Task->RegisterWithGameInstance(WorldContextObject); |
| 31 | + return Task; |
31 | 32 | } |
32 | 33 |
|
33 | | -void UAsyncTaskThirdwebLoginWithSiwe::HandleSiweComplete( |
34 | | - const FString &Payload, const FString &Signature) { |
35 | | - if (IsInGameThread()) { |
36 | | - Success.Broadcast(Payload, Signature); |
37 | | - Browser->RemoveFromParent(); |
38 | | - SetReadyToDestroy(); |
39 | | - } else { |
40 | | - // Retry on the GameThread. |
41 | | - TWeakObjectPtr<UAsyncTaskThirdwebLoginWithSiwe> WeakThis = this; |
42 | | - FFunctionGraphTask::CreateAndDispatchWhenReady( |
43 | | - [WeakThis, Payload, Signature]() { |
44 | | - if (WeakThis.IsValid()) { |
45 | | - WeakThis->HandleSiweComplete(Payload, Signature); |
46 | | - } |
47 | | - }, |
48 | | - TStatId(), nullptr, ENamedThreads::GameThread); |
49 | | - } |
| 34 | +void UAsyncTaskThirdwebLoginWithSiwe::HandleSiweComplete(const FString& Payload, const FString& Signature) |
| 35 | +{ |
| 36 | + if (IsInGameThread()) |
| 37 | + { |
| 38 | + Success.Broadcast(Payload, Signature); |
| 39 | + Browser->RemoveFromParent(); |
| 40 | + SetReadyToDestroy(); |
| 41 | + } |
| 42 | + else |
| 43 | + { |
| 44 | + // Retry on the GameThread. |
| 45 | + TWeakObjectPtr<UAsyncTaskThirdwebLoginWithSiwe> WeakThis = this; |
| 46 | + FFunctionGraphTask::CreateAndDispatchWhenReady([WeakThis, Payload, Signature]() |
| 47 | + { |
| 48 | + if (WeakThis.IsValid()) |
| 49 | + { |
| 50 | + WeakThis->HandleSiweComplete(Payload, Signature); |
| 51 | + } |
| 52 | + }, |
| 53 | + TStatId(), |
| 54 | + nullptr, |
| 55 | + ENamedThreads::GameThread); |
| 56 | + } |
50 | 57 | } |
51 | 58 |
|
52 | | -void UAsyncTaskThirdwebLoginWithSiwe::HandleFailed(const FString &Error) { |
53 | | - if (IsInGameThread()) { |
54 | | - Browser->RemoveFromParent(); |
55 | | - Failed.Broadcast(Error); |
56 | | - SetReadyToDestroy(); |
57 | | - } else { |
58 | | - // Retry on the GameThread. |
59 | | - TWeakObjectPtr<UAsyncTaskThirdwebLoginWithSiwe> WeakThis = this; |
60 | | - FFunctionGraphTask::CreateAndDispatchWhenReady( |
61 | | - [WeakThis, Error]() { |
62 | | - if (WeakThis.IsValid()) { |
63 | | - WeakThis->HandleFailed(Error); |
64 | | - } |
65 | | - }, |
66 | | - TStatId(), nullptr, ENamedThreads::GameThread); |
67 | | - } |
| 59 | +void UAsyncTaskThirdwebLoginWithSiwe::HandleFailed(const FString& Error) |
| 60 | +{ |
| 61 | + if (IsInGameThread()) |
| 62 | + { |
| 63 | + Browser->RemoveFromParent(); |
| 64 | + Failed.Broadcast(Error); |
| 65 | + SetReadyToDestroy(); |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + // Retry on the GameThread. |
| 70 | + TWeakObjectPtr<UAsyncTaskThirdwebLoginWithSiwe> WeakThis = this; |
| 71 | + FFunctionGraphTask::CreateAndDispatchWhenReady([WeakThis, Error]() |
| 72 | + { |
| 73 | + if (WeakThis.IsValid()) |
| 74 | + { |
| 75 | + WeakThis->HandleFailed(Error); |
| 76 | + } |
| 77 | + }, |
| 78 | + TStatId(), |
| 79 | + nullptr, |
| 80 | + ENamedThreads::GameThread); |
| 81 | + } |
68 | 82 | } |
0 commit comments