Skip to content

Commit c5868f0

Browse files
niksad8waa-test
andauthored
add support for temporary accounts in wharfkit (#13)
Co-authored-by: nikhil <nikhil.sadalkar@opskins.com>
1 parent dec35b7 commit c5868f0

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface WalletPluginCloudWalletOptions {
3434
url?: string
3535
autoUrl?: string
3636
loginTimeout?: number
37+
allowTemp?: boolean
3738
}
3839

3940
export class WalletPluginCloudWallet extends AbstractWalletPlugin implements WalletPlugin {
@@ -79,7 +80,7 @@ export class WalletPluginCloudWallet extends AbstractWalletPlugin implements Wal
7980
public url = 'https://www.mycloudwallet.com'
8081
public autoUrl = 'https://idm-api.mycloudwallet.com/v1/accounts/auto-accept'
8182
public loginTimeout = 300000 // 5 minutes
82-
83+
public allowTemp = false
8384
/**
8485
* Constructor to allow overriding of plugin configuration.
8586
*/
@@ -97,6 +98,9 @@ export class WalletPluginCloudWallet extends AbstractWalletPlugin implements Wal
9798
if (options?.loginTimeout) {
9899
this.loginTimeout = options.loginTimeout
99100
}
101+
if (options?.allowTemp) {
102+
this.allowTemp = options.allowTemp
103+
}
100104
}
101105

102106
/**
@@ -125,10 +129,16 @@ export class WalletPluginCloudWallet extends AbstractWalletPlugin implements Wal
125129
let response: WAXCloudWalletLoginResponse
126130
try {
127131
// Attempt automatic login
128-
response = await autoLogin(t, `${this.autoUrl}/login?n=${base64Nonce}`)
132+
response = await autoLogin(
133+
t,
134+
`${this.autoUrl}/login?n=${base64Nonce}&returnTemp=${this.allowTemp}`
135+
)
129136
} catch (e) {
130137
// Fallback to popup login
131-
response = await popupLogin(t, `${this.url}/cloud-wallet/login?n=${base64Nonce}`)
138+
response = await popupLogin(
139+
t,
140+
`${this.url}/cloud-wallet/login?n=${base64Nonce}&returnTemp=${this.allowTemp}`
141+
)
132142
}
133143

134144
// If failed due to no response or no verified response, throw error
@@ -146,6 +156,7 @@ export class WalletPluginCloudWallet extends AbstractWalletPlugin implements Wal
146156

147157
// Save our whitelisted contracts
148158
this.data.whitelist = response.whitelistedContracts
159+
this.data.isTempAccount = response.isTemp
149160
const signature = (response as any)?.proof?.data?.signature
150161
return new Promise((resolve) => {
151162
if (!context.chain) {

0 commit comments

Comments
 (0)