-
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
5ab6f42
commit ff80dd9
Showing
19 changed files
with
319 additions
and
3,399 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
60 changes: 60 additions & 0 deletions
60
packages/paima-sdk/paima-mw-core/src/wallets/evm/ethers.ts
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { buildEndpointErrorFxn, PaimaMiddlewareErrorCode } from '../../errors'; | ||
import { getChainId, getGameName } from '../../state'; | ||
import type { LoginInfoMap, Result, Wallet } from '../../types'; | ||
import { updateFee } from '../../helpers/posting'; | ||
|
||
import type { WalletMode } from '../wallet-modes'; | ||
import type { EthersApi, IProvider } from '@paima/providers'; | ||
import { EthersConnector } from '@paima/providers'; | ||
|
||
async function connectWallet( | ||
loginInfo: LoginInfoMap[WalletMode.EvmEthers] | ||
): Promise<Result<IProvider<EthersApi>>> { | ||
const errorFxn = buildEndpointErrorFxn('ethersLoginWrapper'); | ||
|
||
const gameInfo = { | ||
gameName: getGameName(), | ||
gameChainId: '0x' + getChainId().toString(16), | ||
}; | ||
const name = loginInfo.connection.metadata.name; | ||
try { | ||
console.log(`ethersLoginWrapper: Attempting to log into ${name}`); | ||
const provider = await EthersConnector.instance().connectExternal( | ||
gameInfo, | ||
loginInfo.connection.api | ||
); | ||
return { | ||
success: true, | ||
result: provider, | ||
}; | ||
} catch (err) { | ||
console.log(`ethersLoginWrapper: Error while logging into wallet name}`); | ||
|
||
return errorFxn(PaimaMiddlewareErrorCode.EVM_LOGIN, err); | ||
} | ||
} | ||
export async function ethersLoginWrapper( | ||
loginInfo: LoginInfoMap[WalletMode.EvmEthers] | ||
): Promise<Result<Wallet>> { | ||
const errorFxn = buildEndpointErrorFxn('ethersLoginWrapper'); | ||
|
||
const loginResult = await connectWallet(loginInfo); | ||
if (loginResult.success === false) { | ||
return loginResult; | ||
} | ||
|
||
try { | ||
await updateFee(); | ||
} catch (err) { | ||
errorFxn(PaimaMiddlewareErrorCode.ERROR_UPDATING_FEE, err); | ||
// The fee has a default value, so this is not fatal and we can continue. | ||
// If the fee has increased beyond the default value, posting won't work. | ||
} | ||
|
||
return { | ||
success: true, | ||
result: { | ||
walletAddress: EthersConnector.instance().getOrThrowProvider().getAddress(), | ||
}, | ||
}; | ||
} |
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
Oops, something went wrong.