Skip to content

Commit

Permalink
feat: Update expo to use any activated account (#173)
Browse files Browse the repository at this point in the history
PR #172 update the API to
support using any activated account. We need to update the expo provider
to the same API. This PR has 3 commits:

1. Update go.mod to use the latest gnokey-mobile following changes in PR
gnolang/gnokey-mobile#9
2. In expo, npm install the latest gnolang_gnonative.bufbuild_es and
connectrpc_es to access the new API
3. Update expo/src/api/GnoNativeApi.ts to match the new API to use any
activated account, specified by address. Note that the address
parameters are optional for temporary backwards compatibility. When
dSocial and Gnokey Mobile are updated to use the new API and specify the
address, we will do a PR to require the address parameter, and to remove
the deprecated `selectAccount` and `getActiveAccount`.

---------

Signed-off-by: Jeff Thompson <[email protected]>
  • Loading branch information
jefft0 authored Sep 4, 2024
1 parent 1a678ad commit ff1fda7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
14 changes: 7 additions & 7 deletions expo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 28 additions & 4 deletions expo/src/api/GnoNativeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
GenerateRecoveryPhraseRequest,
GetActiveAccountRequest,
GetActiveAccountResponse,
GetActivatedAccountRequest,
GetActivatedAccountResponse,
GetChainIDRequest,
GetKeyInfoByAddressRequest,
GetKeyInfoByNameOrAddressRequest,
Expand All @@ -32,6 +34,8 @@ import {
RenderRequest,
SelectAccountRequest,
SelectAccountResponse,
ActivateAccountRequest,
ActivateAccountResponse,
SendRequest,
SendResponse,
SetChainIDRequest,
Expand Down Expand Up @@ -213,6 +217,16 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
return response;
}

async activateAccount(nameOrBech32: string): Promise<ActivateAccountResponse> {
const client = await this.#getClient();
const response = await client.activateAccount(
new ActivateAccountRequest({
nameOrBech32,
}),
);
return response;
}

async getClient(): Promise<PromiseClient<typeof GnoNativeService>> {
if (!this.clientInstance) {
throw new Error('GoBridge client instance not initialized.');
Expand All @@ -224,15 +238,15 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
return this.clientInstance !== undefined;
}

async setPassword(password: string): Promise<SetPasswordResponse> {
async setPassword(password: string, address?: Uint8Array): Promise<SetPasswordResponse> {
const client = await this.#getClient();
const response = await client.setPassword(new SetPasswordRequest({ password }));
const response = await client.setPassword(new SetPasswordRequest({ password, address }));
return response;
}

async updatePassword(newPassword: string): Promise<UpdatePasswordResponse> {
async updatePassword(newPassword: string, address?: Uint8Array): Promise<UpdatePasswordResponse> {
const client = await this.#getClient();
const response = await client.updatePassword(new UpdatePasswordRequest({ newPassword }));
const response = await client.updatePassword(new UpdatePasswordRequest({ newPassword, address }));
return response;
}

Expand All @@ -242,6 +256,12 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
return response;
}

async getActivatedAccount(): Promise<GetActivatedAccountResponse> {
const client = await this.#getClient();
const response = await client.getActivatedAccount(new GetActivatedAccountRequest());
return response;
}

async queryAccount(address: Uint8Array): Promise<QueryAccountResponse> {
const client = await this.#getClient();
const reponse = await client.queryAccount(new QueryAccountRequest({ address }));
Expand Down Expand Up @@ -303,6 +323,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
args: string[],
gasFee: string,
gasWanted: number,
callerAddress?: Uint8Array,
send?: string,
memo?: string,
): Promise<AsyncIterable<CallResponse>> {
Expand All @@ -312,6 +333,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
gasFee,
gasWanted: BigInt(gasWanted),
memo,
callerAddress,
msgs: [
new MsgCall({
packagePath,
Expand All @@ -330,6 +352,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
send: string,
gasFee: string,
gasWanted: number,
callerAddress?: Uint8Array,
memo?: string,
): Promise<AsyncIterable<SendResponse>> {
const client = await this.#getClient();
Expand All @@ -338,6 +361,7 @@ export class GnoNativeApi implements GnoKeyApi, GoBridgeInterface {
gasFee,
gasWanted: BigInt(gasWanted),
memo,
callerAddress,
msgs: [
new MsgSend({
toAddress,
Expand Down
10 changes: 8 additions & 2 deletions expo/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {
CallResponse,
DeleteAccountResponse,
GetActiveAccountResponse,
GetActivatedAccountResponse,
HelloStreamResponse,
QueryAccountResponse,
QueryResponse,
SelectAccountResponse,
ActivateAccountResponse,
SendResponse,
SetChainIDResponse,
SetPasswordResponse,
Expand Down Expand Up @@ -46,9 +48,11 @@ export interface GnoKeyApi {
getKeyInfoByAddress: (address: Uint8Array) => Promise<KeyInfo | undefined>;
getKeyInfoByNameOrAddress: (nameOrBech32: string) => Promise<KeyInfo | undefined>;
selectAccount: (nameOrBech32: string) => Promise<SelectAccountResponse>;
setPassword: (password: string) => Promise<SetPasswordResponse>;
updatePassword: (password: string) => Promise<UpdatePasswordResponse>;
activateAccount: (nameOrBech32: string) => Promise<ActivateAccountResponse>;
setPassword: (password: string, address?: Uint8Array) => Promise<SetPasswordResponse>;
updatePassword: (password: string, address?: Uint8Array) => Promise<UpdatePasswordResponse>;
getActiveAccount: () => Promise<GetActiveAccountResponse>;
getActivatedAccount: () => Promise<GetActivatedAccountResponse>;
queryAccount: (address: Uint8Array) => Promise<QueryAccountResponse>;
deleteAccount: (
nameOrBech32: string,
Expand All @@ -64,6 +68,7 @@ export interface GnoKeyApi {
args: string[],
gasFee: string,
gasWanted: number,
callerAddress?: Uint8Array,
send?: string,
memo?: string,
) => Promise<AsyncIterable<CallResponse>>;
Expand All @@ -72,6 +77,7 @@ export interface GnoKeyApi {
send: string,
gasFee: string,
gasWanted: number,
callerAddress?: Uint8Array,
memo?: string,
) => Promise<AsyncIterable<SendResponse>>;
addressToBech32: (address: Uint8Array) => Promise<string>;
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
connectrpc.com/grpchealth v1.3.0
connectrpc.com/grpcreflect v1.2.0
github.com/gnolang/gno v0.1.2-0.20240826090356-651f5aac3706
github.com/gnolang/gnokey-mobile v0.0.0-20240814140149-eb333b936c7c
github.com/gnolang/gnokey-mobile v0.0.0-20240903152400-9942eff89ef6
github.com/oklog/run v1.1.0
github.com/peterbourgon/ff/v3 v3.4.0
github.com/peterbourgon/unixtransport v0.0.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ github.com/gnolang/gno v0.1.2-0.20240826090356-651f5aac3706 h1:0kpoNeuErRec3JOt3
github.com/gnolang/gno v0.1.2-0.20240826090356-651f5aac3706/go.mod h1:dBaL1Au2MNLol+3FXdCv+IKLJnMKtTmIt778zsKjVu0=
github.com/gnolang/gnokey-mobile v0.0.0-20240814140149-eb333b936c7c h1:rL7dVjWOpdQxmbsh69HrgAklolhydTZmPvgo6BpgdhE=
github.com/gnolang/gnokey-mobile v0.0.0-20240814140149-eb333b936c7c/go.mod h1:2NrHp15t6QXGNDruOpw6/xN6z50kquVvZs6uxvUNhsQ=
github.com/gnolang/gnokey-mobile v0.0.0-20240903152400-9942eff89ef6 h1:D4dctoTOCk30fbMebwgDYRhcemXrcK7vqjl6MFPUIfc=
github.com/gnolang/gnokey-mobile v0.0.0-20240903152400-9942eff89ef6/go.mod h1:fD0uCByVS8JKxQbSPOvJxO0s7vdfh1BBXBcv8d+ApDk=
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 h1:GKvsK3oLWG9B1GL7WP/VqwM6C92j5tIvB844oggL9Lk=
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216/go.mod h1:xJhtEL7ahjM1WJipt89gel8tHzfIl/LyMY+lCYh38d8=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down

0 comments on commit ff1fda7

Please sign in to comment.