Skip to content

Commit

Permalink
Merge pull request #34 from Web3Auth/feat/wallet-services
Browse files Browse the repository at this point in the history
Feat/wallet services and setupMFA
  • Loading branch information
chaitanyapotti authored May 23, 2024
2 parents 6e42680 + 6cc364a commit 4e87c91
Show file tree
Hide file tree
Showing 10 changed files with 738 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class Web3AuthApi
{
static Web3AuthApi instance;
static string baseAddress = "https://broadcast-server.tor.us";
static string baseAddress = "https://session.web3auth.io";

public static Web3AuthApi getInstance()
{
Expand Down
69 changes: 65 additions & 4 deletions Assets/Plugins/Web3AuthSDK/Samples/Web3AuthSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Web3AuthSample : MonoBehaviour
List<LoginVerifier> verifierList = new List<LoginVerifier> {
new LoginVerifier("Google", Provider.GOOGLE),
new LoginVerifier("Facebook", Provider.FACEBOOK),
new LoginVerifier("CUSTOM_VERIFIER", Provider.CUSTOM_VERIFIER),
// new LoginVerifier("CUSTOM_VERIFIER", Provider.CUSTOM_VERIFIER),
new LoginVerifier("Twitch", Provider.TWITCH),
new LoginVerifier("Discord", Provider.DISCORD),
new LoginVerifier("Reddit", Provider.REDDIT),
Expand All @@ -20,7 +20,9 @@ public class Web3AuthSample : MonoBehaviour
new LoginVerifier("LinkedIn", Provider.LINKEDIN),
new LoginVerifier("Twitter", Provider.TWITTER),
new LoginVerifier("Line", Provider.LINE),
new LoginVerifier("Hosted Email Passwordless", Provider.EMAIL_PASSWORDLESS),
new LoginVerifier("Email Passwordless", Provider.EMAIL_PASSWORDLESS),
new LoginVerifier("SMS Passwordless", Provider.SMS_PASSWORDLESS),
new LoginVerifier("Farcaster", Provider.FARCASTER),
};

Web3Auth web3Auth;
Expand All @@ -40,6 +42,12 @@ public class Web3AuthSample : MonoBehaviour
[SerializeField]
Button logoutButton;

[SerializeField]
Button mfaSetupButton;

[SerializeField]
Button launchWalletServicesButton;

void Start()
{
var loginConfigItem = new LoginConfigItem()
Expand All @@ -61,7 +69,7 @@ void Start()
mode = ThemeModes.dark,
theme = new Dictionary<string, string>
{
{ "primary", "#123456" }
{ "primary", "#FFBF00" }
}
},
// If using your own custom verifier, uncomment this code.
Expand All @@ -73,19 +81,24 @@ void Start()
}
*/
clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ",
buildEnv = BuildEnv.TESTING,
buildEnv = BuildEnv.PRODUCTION,
redirectUrl = new Uri("torusapp://com.torus.Web3AuthUnity/auth"),
network = Web3Auth.Network.SAPPHIRE_MAINNET,
sessionTime = 86400
});
web3Auth.onLogin += onLogin;
web3Auth.onLogout += onLogout;
web3Auth.onMFASetup += onMFASetup;

emailAddressField.gameObject.SetActive(false);
logoutButton.gameObject.SetActive(false);
mfaSetupButton.gameObject.SetActive(false);
launchWalletServicesButton.gameObject.SetActive(false);

loginButton.onClick.AddListener(login);
logoutButton.onClick.AddListener(logout);
mfaSetupButton.onClick.AddListener(enableMFA);
launchWalletServicesButton.onClick.AddListener(launchWalletServices);

verifierDropdown.AddOptions(verifierList.Select(x => x.name).ToList());
verifierDropdown.onValueChanged.AddListener(onVerifierDropDownChange);
Expand All @@ -101,17 +114,25 @@ private void onLogin(Web3AuthResponse response)
verifierDropdown.gameObject.SetActive(false);
emailAddressField.gameObject.SetActive(false);
logoutButton.gameObject.SetActive(true);
mfaSetupButton.gameObject.SetActive(true);
launchWalletServicesButton.gameObject.SetActive(true);
}

private void onLogout()
{
loginButton.gameObject.SetActive(true);
verifierDropdown.gameObject.SetActive(true);
logoutButton.gameObject.SetActive(false);
mfaSetupButton.gameObject.SetActive(false);
launchWalletServicesButton.gameObject.SetActive(false);

loginResponseText.text = "";
}

private void onMFASetup(bool response) {
Debug.Log("MFA Setup: " + response);
}


private void onVerifierDropDownChange(int selectedIndex)
{
Expand All @@ -137,6 +158,13 @@ private void login()
login_hint = emailAddressField.text
};
}
if (selectedProvider == Provider.SMS_PASSWORDLESS)
{
options.extraLoginOptions = new ExtraLoginOptions()
{
login_hint = "+XX-XXXXXXXXXX"
};
}

web3Auth.login(options);
}
Expand All @@ -145,4 +173,37 @@ private void logout()
{
web3Auth.logout();
}

private void enableMFA()
{
var selectedProvider = verifierList[verifierDropdown.value].loginProvider;

var options = new LoginParams()
{
loginProvider = selectedProvider,
mfaLevel = MFALevel.MANDATORY
};

if (selectedProvider == Provider.EMAIL_PASSWORDLESS)
{
options.extraLoginOptions = new ExtraLoginOptions()
{
login_hint = emailAddressField.text
};
}
web3Auth.enableMFA(options);
}

private void launchWalletServices() {
var selectedProvider = verifierList[verifierDropdown.value].loginProvider;

var chainConfig = new ChainConfig()
{
chainId = "0x1",
rpcTarget = "https://mainnet.infura.io/v3/daeee53504be4cd3a997d4f2718d33e0",
ticker = "ETH",
chainNamespace = Web3Auth.ChainNamespace.EIP155
};
web3Auth.launchWalletServices(chainConfig);
}
}
Loading

0 comments on commit 4e87c91

Please sign in to comment.