-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved account and sdk to providers.ts
- Loading branch information
Showing
3 changed files
with
47 additions
and
34 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
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,38 @@ | ||
import { Inject, Provider } from '@nestjs/common'; | ||
import { IClient, Sdk } from '@unique-nft/sdk'; | ||
import { KeyringProvider } from '@unique-nft/accounts/keyring'; | ||
import { Account, SignatureType } from '@unique-nft/accounts'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
export const InjectAccount = Inject('Account'); | ||
export const InjectSdk = Inject('Sdk'); | ||
|
||
export const accountProvider: Provider = { | ||
provide: 'Account', | ||
inject: [ConfigService], | ||
useFactory: async (configService: ConfigService) => { | ||
const keyringProvider = new KeyringProvider({ | ||
type: SignatureType.Sr25519, | ||
}); | ||
|
||
await keyringProvider.init(); | ||
|
||
return keyringProvider.addSeed(configService.get<string>('seed')); | ||
}, | ||
}; | ||
|
||
export const sdkProvider: Provider = { | ||
provide: 'Sdk', | ||
inject: ['Account', ConfigService], | ||
useFactory: async ( | ||
account: Account, | ||
configService: ConfigService, | ||
): Promise<IClient> => { | ||
const restUrl = configService.get<string>('restUrl'); | ||
|
||
return new Sdk({ | ||
signer: account, | ||
baseUrl: restUrl, | ||
}); | ||
}, | ||
}; |
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