7
7
Web2Context ,
8
8
BlockchainContext
9
9
} from "@bandada/credentials"
10
+ import { blockchainCredentialSupportedNetworks } from "@bandada/utils"
10
11
import { id } from "@ethersproject/hash"
11
12
import {
12
13
BadRequestException ,
@@ -78,15 +79,12 @@ export class CredentialsService {
78
79
* @param OAuthState OAuth state to prevent forgery attacks.
79
80
* @param oAuthCode OAuth code to exchange for an access token.
80
81
* @param address Account address.
81
- * @param network Network name.
82
- * @param blockNumber Block number.
83
82
* @returns Redirect URI
84
83
*/
85
84
async addMember (
86
85
oAuthState : string ,
87
86
oAuthCode ?: string ,
88
- address ?: string ,
89
- network ?: string
87
+ address ?: string
90
88
) : Promise < string > {
91
89
if ( ! this . oAuthState . has ( oAuthState ) ) {
92
90
throw new BadRequestException ( `OAuth state does not exist` )
@@ -108,10 +106,19 @@ export class CredentialsService {
108
106
let context : Web2Context | BlockchainContext
109
107
110
108
if ( address ) {
109
+ const { network } = JSON . parse ( group . credentials ) . criteria
110
+
111
+ const supportedNetwork = blockchainCredentialSupportedNetworks . find (
112
+ ( n ) => n . name . toLowerCase ( ) === network . toLowerCase ( )
113
+ )
114
+
115
+ if ( supportedNetwork === undefined )
116
+ throw new BadRequestException ( `The network is not supported` )
117
+
118
+ const networkEnvVariableName = supportedNetwork . id . toUpperCase ( )
119
+
111
120
const web3providerRpcURL =
112
- process . env [
113
- `${ providerName . toUpperCase ( ) } _${ network . toUpperCase ( ) } _RPC_URL`
114
- ]
121
+ process . env [ `${ networkEnvVariableName } _RPC_URL` ]
115
122
116
123
const jsonRpcProvider = await (
117
124
provider as BlockchainProvider
0 commit comments