-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from nabla-studio/DavideSegullo/feat-terra_sta…
…tion Davide segullo/feat terra station
- Loading branch information
Showing
6 changed files
with
226 additions
and
8 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
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,167 @@ | ||
import type { | ||
OfflineAminoSigner, | ||
StdSignDoc, | ||
AminoSignResponse, | ||
StdSignature, | ||
} from '@cosmjs/amino'; | ||
import type { | ||
OfflineDirectSigner, | ||
DirectSignResponse, | ||
} from '@cosmjs/proto-signing'; | ||
import type { | ||
Key, | ||
SignOptions, | ||
SuggestChain, | ||
SuggestToken, | ||
WalletOptions, | ||
} from '@quirks/core'; | ||
import { ExtensionWallet, assertIsDefined } from '@quirks/core'; | ||
import type { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; | ||
import type { Keplr } from '@keplr-wallet/types'; | ||
import Long from 'long'; | ||
import { chainRegistryChainToKeplr } from '../keplr/utils'; | ||
|
||
export class StationWalletExtension extends ExtensionWallet<Keplr> { | ||
constructor(options: WalletOptions) { | ||
super(options); | ||
} | ||
|
||
override enable(chainIds: string[]): Promise<void> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.enable(chainIds); | ||
} | ||
|
||
override disable(chainIds: string[]): Promise<void> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.disable(chainIds); | ||
} | ||
|
||
override async getAccount(chainId: string) { | ||
assertIsDefined(this.client); | ||
|
||
return await this.client.getKey(chainId); | ||
} | ||
|
||
override async getAccounts(chainIds: string[]) { | ||
assertIsDefined(this.client); | ||
|
||
const keys = await this.client.getKeysSettled(chainIds); | ||
|
||
return keys | ||
.map((key) => { | ||
if (key.status === 'fulfilled') { | ||
return key.value; | ||
} | ||
|
||
return undefined; | ||
}) | ||
.filter((key) => key !== undefined) as Key[]; | ||
} | ||
|
||
override async getOfflineSigner( | ||
chainId: string, | ||
options?: SignOptions | undefined, | ||
): Promise<OfflineAminoSigner & OfflineDirectSigner> { | ||
assertIsDefined(this.client); | ||
|
||
return await this.client.getOfflineSigner(chainId, options); | ||
} | ||
|
||
override async getOfflineSignerOnlyAmino( | ||
chainId: string, | ||
options?: SignOptions | undefined, | ||
): Promise<OfflineAminoSigner> { | ||
assertIsDefined(this.client); | ||
|
||
return await this.client.getOfflineSignerOnlyAmino(chainId, options); | ||
} | ||
|
||
override getOfflineSignerAuto( | ||
chainId: string, | ||
options?: SignOptions | undefined, | ||
): Promise<OfflineAminoSigner | OfflineDirectSigner> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.getOfflineSignerAuto(chainId, options); | ||
} | ||
|
||
override signAmino( | ||
chainId: string, | ||
signer: string, | ||
signDoc: StdSignDoc, | ||
signOptions?: SignOptions | undefined, | ||
): Promise<AminoSignResponse> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.signAmino(chainId, signer, signDoc, signOptions); | ||
} | ||
|
||
override signDirect( | ||
chainId: string, | ||
signer: string, | ||
signDoc: SignDoc, | ||
signOptions?: SignOptions | undefined, | ||
): Promise<DirectSignResponse> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.signDirect( | ||
chainId, | ||
signer, | ||
{ | ||
...signDoc, | ||
accountNumber: Long.fromString(signDoc.accountNumber.toString(10)), | ||
}, | ||
signOptions, | ||
); | ||
} | ||
|
||
override signArbitrary( | ||
chainId: string, | ||
signer: string, | ||
data: string | Uint8Array, | ||
): Promise<StdSignature> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.signArbitrary(chainId, signer, data); | ||
} | ||
|
||
override verifyArbitrary( | ||
chainId: string, | ||
signer: string, | ||
data: string | Uint8Array, | ||
signature: StdSignature, | ||
): Promise<boolean> { | ||
assertIsDefined(this.client); | ||
|
||
return this.client.verifyArbitrary(chainId, signer, data, signature); | ||
} | ||
|
||
override async suggestTokens(suggestions: SuggestToken[]): Promise<void> { | ||
assertIsDefined(this.client); | ||
|
||
for (const suggestion of suggestions) { | ||
for (const token of suggestion.tokens) { | ||
await this.client.suggestToken( | ||
suggestion.chainId, | ||
token.contractAddress, | ||
token.viewingKey, | ||
); | ||
} | ||
} | ||
} | ||
|
||
override async suggestChains(suggestions: SuggestChain[]): Promise<void> { | ||
assertIsDefined(this.client); | ||
|
||
for (const suggestion of suggestions) { | ||
const suggestChain = chainRegistryChainToKeplr( | ||
suggestion.chain, | ||
suggestion.assetList ? [suggestion.assetList] : [], | ||
); | ||
|
||
await this.client.experimentalSuggestChain(suggestChain); | ||
} | ||
} | ||
} |
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,6 @@ | ||
import { StationWalletExtension } from './extension'; | ||
import { stationExtensionOptions } from './registry'; | ||
|
||
const stationExtension = new StationWalletExtension(stationExtensionOptions); | ||
|
||
export { stationExtension }; |
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 { WalletConnectionTypes, type WalletOptions } from '@quirks/core'; | ||
|
||
export const stationExtensionOptions: WalletOptions = { | ||
name: 'station-extension', | ||
prettyName: 'Station', | ||
connectionType: WalletConnectionTypes.EXTENSION, | ||
windowKey: 'station.keplr', | ||
downloads: [ | ||
{ | ||
device: 'desktop', | ||
browser: 'chrome', | ||
link: 'https://chrome.google.com/webstore/detail/station-wallet/aiifbnbfobpmeekipheeijimdpnlpgpp', | ||
}, | ||
{ | ||
device: 'desktop', | ||
browser: 'firefox', | ||
link: 'https://addons.mozilla.org/en-US/firefox/addon/terra-station-wallet/', | ||
}, | ||
{ | ||
device: 'desktop', | ||
browser: 'edge', | ||
link: 'https://microsoftedge.microsoft.com/addons/detail/station-wallet/ajkhoeiiokighlmdnlakpjfoobnjinie', | ||
}, | ||
], | ||
logoUrls: { | ||
light: { | ||
svg: 'https://assets.website-files.com/611153e7af981472d8da199c/62d8d4463816d7f427a7600b_01_Tarra_icon.svg', | ||
png: 'https://assets.website-files.com/611153e7af981472d8da199c/62d8b6af5e23fd010628b529_01_Tarra_icon.png', | ||
}, | ||
dark: { | ||
svg: 'https://assets.website-files.com/611153e7af981472d8da199c/62d8d4463816d7f427a7600b_01_Tarra_icon.svg', | ||
png: 'https://assets.website-files.com/611153e7af981472d8da199c/62d8b6af5e23fd010628b529_01_Tarra_icon.png', | ||
}, | ||
}, | ||
events: { | ||
keystorechange: 'station_wallet_change', | ||
}, | ||
}; |