-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d56eb72
commit 82e8a91
Showing
17 changed files
with
229 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,5 @@ | |
"./packages/*/*" | ||
], | ||
"dependencies": { | ||
"assert-never": "^1.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ | |
"typescript": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"assert-never": "^1.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ | |
}, | ||
"author": "Paima Studios", | ||
"dependencies": { | ||
"assert-never": "^1.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,34 @@ | ||
import type { Result, Wallet } from '../types'; | ||
import type { LoginInfoMap, Result, Wallet } from '../types'; | ||
import { PaimaMiddlewareErrorCode, buildEndpointErrorFxn } from '../errors'; | ||
import { AlgorandConnector } from '@paima/providers'; | ||
import { getGameName } from '../state'; | ||
import { WalletMode } from './wallet-modes'; | ||
import type { WalletMode } from './wallet-modes'; | ||
import { connectWallet } from './wallet-modes'; | ||
|
||
// TODO: the whole concept of converting wallet mode to names should be removed | ||
function algorandWalletModeToName(walletMode: WalletMode): string { | ||
switch (walletMode) { | ||
case WalletMode.ALGORAND_PERA: | ||
return 'pera'; | ||
default: | ||
return ''; | ||
} | ||
} | ||
|
||
export async function algorandLoginWrapper(walletMode: WalletMode): Promise<Result<Wallet>> { | ||
export async function algorandLoginWrapper( | ||
loginInfo: LoginInfoMap[WalletMode.ALGORAND] | ||
): Promise<Result<Wallet>> { | ||
const errorFxn = buildEndpointErrorFxn('algorandLoginWrapper'); | ||
|
||
const walletName = algorandWalletModeToName(walletMode); | ||
try { | ||
const provider = | ||
walletMode === WalletMode.ALGORAND | ||
? await AlgorandConnector.instance().connectSimple({ | ||
gameName: getGameName(), | ||
gameChainId: undefined, // Not needed because of batcher | ||
}) | ||
: await AlgorandConnector.instance().connectNamed( | ||
{ | ||
gameName: getGameName(), | ||
gameChainId: undefined, // Not needed because of batcher | ||
}, | ||
walletName | ||
); | ||
return { | ||
success: true, | ||
result: { | ||
walletAddress: provider.getAddress(), | ||
}, | ||
}; | ||
} catch (err) { | ||
return errorFxn(PaimaMiddlewareErrorCode.ALGORAND_LOGIN, err); | ||
const gameInfo = { | ||
gameName: getGameName(), | ||
gameChainId: undefined, // Not needed because of batcher | ||
}; | ||
const loginResult = await connectWallet( | ||
'algorandLoginWrapper', | ||
errorFxn, | ||
PaimaMiddlewareErrorCode.ALGORAND_LOGIN, | ||
loginInfo, | ||
AlgorandConnector.instance(), | ||
gameInfo | ||
); | ||
if (loginResult.success === false) { | ||
return loginResult; | ||
} | ||
return { | ||
success: true, | ||
result: { | ||
walletAddress: loginResult.result.getAddress().toLocaleLowerCase(), | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.