@rango-dev/provider-gemwallet 0.1.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import type { ProviderMetadata } from '@rango-dev/wallets-core';
2
+ export declare const XRPL_PUBLIC_SERVER = "wss://xrplcluster.com/";
3
+ export declare const WALLET_ID = "gemwallet";
4
+ export declare const info: ProviderMetadata;
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOhE,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,SAAS,cAAc,CAAC;AAErC,eAAO,MAAM,IAAI,EAAE,gBA6BlB,CAAC"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const versions: () => import("@rango-dev/wallets-core/utils").VersionedProviders;
2
+ export { versions };
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,QAAQ,kEAC8C,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,CAAC"}
package/dist/mod.js ADDED
@@ -0,0 +1,2 @@
1
+ var p=Object.defineProperty;var r=(e,t)=>p(e,"name",{value:t,configurable:!0});var o=(e,t)=>()=>(e&&(t=e(e=0)),t);var v=(e,t)=>{for(var n in t)p(e,n,{get:t[n],enumerable:!0})};import{on as D}from"@gemwallet/api";import{ChangeAccountSubscriberBuilder as M}from"@rango-dev/wallets-core/namespaces/common";import{utils as C}from"@rango-dev/wallets-core/namespaces/xrpl";function d(){return new M().getInstance(()=>!0).format(async(e,t)=>[C.formatAddressToCAIP(t.wallet.publicAddress)]).addEventListener((e,t)=>{D("walletChanged",t)}).removeEventListener((e,t)=>{}).build()}var f=o(()=>{"use strict";r(d,"changeAccountSubscriberBuilder")});import{getAddress as I}from"@gemwallet/api";import{ActionBuilder as _,NamespaceBuilder as q}from"@rango-dev/wallets-core";import{builders as B,standardizeAndThrowError as W}from"@rango-dev/wallets-core/namespaces/common";import{builders as U,utils as j}from"@rango-dev/wallets-core/namespaces/xrpl";import{Client as k}from"xrpl";var G,g,F,V,O,s,y=o(()=>{"use strict";m();f();[G,g]=d(),F=U.connect().action(async function(){let e=await I();if(e.type==="reject")throw new Error("User has rejected the request.");if(!e.result?.address)throw new Error("Couldn't access to your wallet address.");return[j.formatAddressToCAIP(e.result.address)]}).before(G).or(g).or(W).build(),V=new _("accountLines").action(async(e,t,n)=>{let a=new k(h);await a.connect();let E=await a.request({command:"account_lines",ledger_index:"current",account:t,peer:n?.peer});return await a.disconnect(),E.result.lines}).build(),O=B.disconnect().after(g).build(),s=new q("XRPL",i).action(F).action(V).action(O).build()});function z(e){return typeof e=="object"&&typeof e.currency=="string"&&typeof e.issuer=="string"&&typeof e.value=="string"}function N(e){return typeof e=="object"&&typeof e.mpt_issuance_id=="string"&&typeof e.value=="string"}function T(e){return e?e.map(t=>({memo:{memoType:t.Memo.MemoType,memoData:t.Memo.MemoData,memoFormat:t.Memo.MemoFormat}})):[]}function w(e){return{limitAmount:e.LimitAmount,memos:T(e.Memos),flags:e.Flags}}function P(e){let t;if(N(e.Amount))throw new Error("Current implemented signer doesn't have support for MPT");if(z(e.Amount))t=e.Amount;else if(typeof e.Amount=="string")t=e.Amount;else throw new Error("There is an unexpected type for Amount. current signer doesn't have support for that.");return{amount:t,destination:e.Destination,destinationTag:e.DestinationTag,memos:T(e.Memos),flags:e.Flags}}var A=o(()=>{"use strict";r(z,"isIssuedCurrencyAmount");r(N,"isMPTokenAmount");r(T,"fromPaymentTransactionMemoToGemWalletMemo");r(w,"fromTrustSetTransactionDataToGemWalletRequest");r(P,"fromPaymentTransactionDataToGemWalletRequest")});import{sendPayment as H,setTrustline as J}from"@gemwallet/api";import{SignerError as K}from"rango-types";var c,b=o(()=>{"use strict";A();c=class{static{r(this,"Signer")}async signMessage(){throw K.UnimplementedError("signMessage")}async signAndSendTx(t){if(t.data.TransactionType==="TrustSet"){let n=await J(w(t.data));if(n.type==="reject")throw new Error("The request has been rejected",{cause:n});if(!n.result)throw new Error("Unexpected error where the result is not returned. (type: UnreachableCode)");return{hash:n.result.hash}}else if(t.data.TransactionType==="Payment"){let n=await H(P(t.data));if(n.type==="reject")throw new Error("The request has been rejected",{cause:n});if(!n.result)throw new Error("Unexpected error where the result is not returned. (type: UnreachableCode)");return{hash:n.result.hash}}throw new Error("Unsupported transaction type")}}});var S={};v(S,{Signer:()=>c,namespace:()=>s});var l=o(()=>{"use strict";y();b()});import{DefaultSignerFactory as Q,TransactionType as Y}from"rango-types";async function u(){let{Signer:e}=await Promise.resolve().then(()=>(l(),S)),t=new Q;return t.registerSigner(Y.XRPL,new e),t}var L=o(()=>{"use strict";r(u,"getSigners")});import{xrplBlockchain as Z}from"rango-types";var h,i,X,m=o(()=>{"use strict";L();h="wss://xrplcluster.com/",i="gemwallet",X={name:"GemWallet",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/gemwallet/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/gemwallet/egebedonbdapoieedfcfkofloclfghab",homepage:"https://gemwallet.app/"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"XRPL",value:"XRPL",id:"XRPL",getSupportedChains:e=>Z(e)}]}},{name:"signers",value:{getSigners:async()=>u()}}]}});import{defineVersions as te}from"@rango-dev/wallets-core/utils";m();l();import{ProviderBuilder as ee}from"@rango-dev/wallets-core";import{isInstalled as $}from"@gemwallet/api";async function R(){return new Promise((e,t)=>{window.addEventListener("load",()=>{$().then(n=>{n.result.isInstalled?e(!0):e(!1)}).catch(t)})})}r(R,"checkInstallationOnLoad");var x=r(()=>new ee(i).init(function(e){let[,t]=e.state(),n=r(a=>t("installed",a),"setInstallState");R().then(n).catch(console.error)}).config("metadata",X).add("xrpl",s).build(),"buildProvider");var Fe=r(()=>te().version("1.0.0",x()).build(),"versions");export{Fe as versions};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/namespaces/xrpl/hooks.ts", "../src/namespaces/xrpl/namespace.ts", "../src/namespaces/xrpl/helpers.ts", "../src/namespaces/xrpl/singer.ts", "../src/namespaces/xrpl/mod.ts", "../src/signer.ts", "../src/constants.ts", "../src/mod.ts", "../src/provider.ts", "../src/utils.ts"],
4
+ "sourcesContent": ["import type { XRPLActions } from '@rango-dev/wallets-core/namespaces/xrpl';\n\nimport { on } from '@gemwallet/api';\nimport { ChangeAccountSubscriberBuilder } from '@rango-dev/wallets-core/namespaces/common';\nimport { utils } from '@rango-dev/wallets-core/namespaces/xrpl';\n\ntype WalletChangedEventPayload = {\n wallet: {\n publicAddress: string;\n };\n};\n\nexport function changeAccountSubscriberBuilder() {\n // `true` instead of ProviderAPI is just a workaround. we don't need to have instance here.\n return new ChangeAccountSubscriberBuilder<\n WalletChangedEventPayload,\n true,\n XRPLActions\n >()\n .getInstance(() => true)\n .format(async (_, payload) => [\n utils.formatAddressToCAIP(payload.wallet.publicAddress),\n ])\n .addEventListener((_, callback) => {\n on('walletChanged', callback);\n })\n .removeEventListener((_instance, _callback) => {\n /*\n * TODO: gem wallet doesn't have support for unsubscribing.\n * Making a variable and keep the callback refrence then here make it `undefined` is a quick fix\n * but it makes new bugs, where if two subscribers added at once, we will loose the track of the first one and it will be staled.\n */\n })\n .build();\n}\n", "import type { XRPLActions } from '@rango-dev/wallets-core/namespaces/xrpl';\n\nimport { getAddress } from '@gemwallet/api';\nimport { ActionBuilder, NamespaceBuilder } from '@rango-dev/wallets-core';\nimport {\n builders as commonBuilders,\n standardizeAndThrowError,\n} from '@rango-dev/wallets-core/namespaces/common';\nimport { builders, utils } from '@rango-dev/wallets-core/namespaces/xrpl';\nimport { Client } from 'xrpl';\n\nimport { WALLET_ID, XRPL_PUBLIC_SERVER } from '../../constants.js';\n\nimport { changeAccountSubscriberBuilder } from './hooks.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n changeAccountSubscriberBuilder();\n\nconst connect = builders\n .connect()\n .action(async function () {\n const response = await getAddress();\n\n if (response.type === 'reject') {\n throw new Error('User has rejected the request.');\n }\n if (!response.result?.address) {\n throw new Error(`Couldn't access to your wallet address.`);\n }\n\n return [utils.formatAddressToCAIP(response.result.address)];\n })\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst accountLines = new ActionBuilder<XRPLActions, 'accountLines'>(\n 'accountLines'\n)\n .action(async (_, account, options) => {\n const client = new Client(XRPL_PUBLIC_SERVER);\n await client.connect();\n\n const response = await client.request({\n command: 'account_lines',\n ledger_index: 'current',\n account: account,\n peer: options?.peer,\n });\n\n await client.disconnect();\n return response.result.lines;\n })\n .build();\nconst disconnect = commonBuilders\n .disconnect<XRPLActions>()\n .after(changeAccountCleanup)\n .build();\nexport const namespace = new NamespaceBuilder<XRPLActions>('XRPL', WALLET_ID)\n .action(connect)\n .action(accountLines)\n .action(disconnect)\n .build();\n", "import type {\n Memo,\n SendPaymentRequest,\n SetTrustlineRequest,\n} from '@gemwallet/api';\nimport type {\n XrplPaymentTransactionData,\n XrplTransactionDataIssuedCurrencyAmount,\n XrplTransactionDataMPTAmount,\n XrplTrustSetTransactionData,\n} from 'rango-types/mainApi';\n\nfunction isIssuedCurrencyAmount(\n amount: XrplPaymentTransactionData['Amount']\n): amount is XrplTransactionDataIssuedCurrencyAmount {\n return (\n typeof amount === 'object' &&\n // @ts-expect-error it never throw an runtime error, since we are checking it should be an object first\n typeof amount.currency === 'string' &&\n // @ts-expect-error it never throw an runtime error, since we are checking it should be an object first\n typeof amount.issuer === 'string' &&\n typeof amount.value === 'string'\n );\n}\n\nfunction isMPTokenAmount(\n amount: XrplPaymentTransactionData['Amount']\n): amount is XrplTransactionDataMPTAmount {\n return (\n typeof amount === 'object' &&\n // @ts-expect-error it never throw an runtime error, since we are checking it should be an object first\n typeof amount.mpt_issuance_id === 'string' &&\n typeof amount.value === 'string'\n );\n}\n\nfunction fromPaymentTransactionMemoToGemWalletMemo(\n memos: XrplPaymentTransactionData['Memos']\n): Memo[] {\n if (!memos) {\n return [];\n }\n\n return memos.map((memo) => {\n return {\n memo: {\n memoType: memo.Memo.MemoType,\n memoData: memo.Memo.MemoData,\n memoFormat: memo.Memo.MemoFormat,\n },\n };\n });\n}\n\nexport function fromTrustSetTransactionDataToGemWalletRequest(\n data: XrplTrustSetTransactionData\n): SetTrustlineRequest {\n return {\n limitAmount: data.LimitAmount,\n memos: fromPaymentTransactionMemoToGemWalletMemo(data.Memos),\n flags: data.Flags,\n };\n}\n\nexport function fromPaymentTransactionDataToGemWalletRequest(\n data: XrplPaymentTransactionData\n): SendPaymentRequest {\n let amount: SendPaymentRequest['amount'];\n if (isMPTokenAmount(data.Amount)) {\n throw new Error(\"Current implemented signer doesn't have support for MPT\");\n } else if (isIssuedCurrencyAmount(data.Amount)) {\n amount = data.Amount;\n } else if (typeof data.Amount === 'string') {\n amount = data.Amount;\n } else {\n throw new Error(\n \"There is an unexpected type for Amount. current signer doesn't have support for that.\"\n );\n }\n\n return {\n amount,\n destination: data.Destination,\n destinationTag: data.DestinationTag,\n memos: fromPaymentTransactionMemoToGemWalletMemo(data.Memos),\n flags: data.Flags,\n };\n}\n", "import type { XrplTransaction } from 'rango-types/mainApi';\n\nimport { sendPayment, setTrustline } from '@gemwallet/api';\nimport { type GenericSigner, SignerError } from 'rango-types';\n\nimport {\n fromPaymentTransactionDataToGemWalletRequest,\n fromTrustSetTransactionDataToGemWalletRequest,\n} from './helpers.js';\n\nexport class Signer implements GenericSigner<XrplTransaction> {\n async signMessage(): Promise<string> {\n throw SignerError.UnimplementedError('signMessage');\n }\n\n async signAndSendTx(tx: XrplTransaction): Promise<{ hash: string }> {\n if (tx.data.TransactionType === 'TrustSet') {\n const result = await setTrustline(\n fromTrustSetTransactionDataToGemWalletRequest(tx.data)\n );\n\n if (result.type === 'reject') {\n throw new Error('The request has been rejected', {\n cause: result,\n });\n }\n\n if (!result.result) {\n throw new Error(\n 'Unexpected error where the result is not returned. (type: UnreachableCode)'\n );\n }\n\n return {\n hash: result.result.hash,\n };\n } else if (tx.data.TransactionType === 'Payment') {\n const result = await sendPayment(\n fromPaymentTransactionDataToGemWalletRequest(tx.data)\n );\n\n if (result.type === 'reject') {\n throw new Error('The request has been rejected', {\n cause: result,\n });\n }\n\n if (!result.result) {\n throw new Error(\n 'Unexpected error where the result is not returned. (type: UnreachableCode)'\n );\n }\n\n return {\n hash: result.result.hash,\n };\n }\n\n throw new Error('Unsupported transaction type');\n }\n}\n", "export { namespace } from './namespace.js';\nexport { Signer } from './singer.js';\n", "import type { SignerFactory } from 'rango-types';\n\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(): Promise<SignerFactory> {\n const { Signer: XrplSigner } = await import('./namespaces/xrpl/mod.js');\n const signers = new DefaultSignerFactory();\n signers.registerSigner(TxType.XRPL, new XrplSigner());\n return signers;\n}\n", "import type { ProviderMetadata } from '@rango-dev/wallets-core';\nimport type { BlockchainMeta } from 'rango-types';\n\nimport { xrplBlockchain } from 'rango-types';\n\nimport getSigners from './signer.js';\n\nexport const XRPL_PUBLIC_SERVER = 'wss://xrplcluster.com/';\nexport const WALLET_ID = 'gemwallet';\n\nexport const info: ProviderMetadata = {\n name: 'GemWallet',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/gemwallet/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/gemwallet/egebedonbdapoieedfcfkofloclfghab',\n homepage: 'https://gemwallet.app/',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'multiple',\n data: [\n {\n label: 'XRPL',\n value: 'XRPL',\n id: 'XRPL',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n xrplBlockchain(allBlockchains),\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners() },\n },\n ],\n};\n", "import { defineVersions } from '@rango-dev/wallets-core/utils';\n\nimport { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions().version('1.0.0', buildProvider()).build();\n\nexport { versions };\n", "import { ProviderBuilder } from '@rango-dev/wallets-core';\n\nimport { info, WALLET_ID } from './constants.js';\nimport { namespace as xrpl } from './namespaces/xrpl/mod.js';\nimport { checkInstallationOnLoad } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n const setInstallState = (result: boolean) =>\n setState('installed', result);\n\n checkInstallationOnLoad().then(setInstallState).catch(console.error);\n })\n .config('metadata', info)\n .add('xrpl', xrpl)\n .build();\n\nexport { buildProvider };\n", "import { isInstalled } from '@gemwallet/api';\n\nexport async function checkInstallationOnLoad(): Promise<boolean> {\n return new Promise((resolve, reject) => {\n window.addEventListener('load', () => {\n isInstalled()\n .then((response) => {\n if (response.result.isInstalled) {\n resolve(true);\n } else {\n resolve(false);\n }\n })\n .catch(reject);\n });\n });\n}\n"],
5
+ "mappings": "gLAEA,OAAS,MAAAA,MAAU,iBACnB,OAAS,kCAAAC,MAAsC,4CAC/C,OAAS,SAAAC,MAAa,0CAQf,SAASC,GAAiC,CAE/C,OAAO,IAAIF,EAIT,EACC,YAAY,IAAM,EAAI,EACtB,OAAO,MAAOG,EAAGC,IAAY,CAC5BH,EAAM,oBAAoBG,EAAQ,OAAO,aAAa,CACxD,CAAC,EACA,iBAAiB,CAACD,EAAGE,IAAa,CACjCN,EAAG,gBAAiBM,CAAQ,CAC9B,CAAC,EACA,oBAAoB,CAACC,EAAWC,IAAc,CAM/C,CAAC,EACA,MAAM,CACX,CAlCA,IAAAC,EAAAC,EAAA,kBAYgBC,EAAAR,EAAA,oCCVhB,OAAS,cAAAS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,CACF,CACF,EACA,CACE,KAAM,UACN,MAAO,CAAE,WAAY,SAAYC,EAAW,CAAE,CAChD,CACF,CACF,ICvCA,OAAS,kBAAAC,OAAsB,gCCE/BC,IACAC,IAHA,OAAS,mBAAAC,OAAuB,0BCAhC,OAAS,eAAAC,MAAmB,iBAE5B,eAAsBC,GAA4C,CAChE,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CACtC,OAAO,iBAAiB,OAAQ,IAAM,CACpCC,EAAY,EACT,KAAMC,GAAa,CACdA,EAAS,OAAO,YAClBH,EAAQ,EAAI,EAEZA,EAAQ,EAAK,CAEjB,CAAC,EACA,MAAMC,CAAM,CACjB,CAAC,CACH,CAAC,CACH,CAdsBG,EAAAL,EAAA,2BDItB,IAAMM,EAAgBC,EAAA,IACpB,IAAIC,GAAgBC,CAAS,EAC1B,KAAK,SAAUC,EAAS,CACvB,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EAC7BE,EAAkBL,EAACM,GACvBF,EAAS,YAAaE,CAAM,EADN,mBAGxBC,EAAwB,EAAE,KAAKF,CAAe,EAAE,MAAM,QAAQ,KAAK,CACrE,CAAC,EACA,OAAO,WAAYG,CAAI,EACvB,IAAI,OAAQC,CAAI,EAChB,MAAM,EAXW,iBDFtB,IAAMC,GAAWC,EAAA,IACfC,GAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
6
+ "names": ["on", "ChangeAccountSubscriberBuilder", "utils", "changeAccountSubscriberBuilder", "_", "payload", "callback", "_instance", "_callback", "init_hooks", "__esmMin", "__name", "getAddress", "ActionBuilder", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "builders", "utils", "Client", "changeAccountSubscriber", "changeAccountCleanup", "connect", "accountLines", "disconnect", "namespace", "init_namespace", "__esmMin", "init_constants", "init_hooks", "changeAccountSubscriberBuilder", "response", "_", "account", "options", "client", "XRPL_PUBLIC_SERVER", "WALLET_ID", "isIssuedCurrencyAmount", "amount", "isMPTokenAmount", "fromPaymentTransactionMemoToGemWalletMemo", "memos", "memo", "fromTrustSetTransactionDataToGemWalletRequest", "data", "fromPaymentTransactionDataToGemWalletRequest", "init_helpers", "__esmMin", "__name", "sendPayment", "setTrustline", "SignerError", "Signer", "init_singer", "__esmMin", "init_helpers", "__name", "tx", "result", "fromTrustSetTransactionDataToGemWalletRequest", "fromPaymentTransactionDataToGemWalletRequest", "mod_exports", "__export", "Signer", "namespace", "init_mod", "__esmMin", "init_namespace", "init_singer", "DefaultSignerFactory", "TxType", "getSigners", "XrplSigner", "signers", "init_signer", "__esmMin", "__name", "xrplBlockchain", "XRPL_PUBLIC_SERVER", "WALLET_ID", "info", "init_constants", "__esmMin", "init_signer", "allBlockchains", "getSigners", "defineVersions", "init_constants", "init_mod", "ProviderBuilder", "isInstalled", "checkInstallationOnLoad", "resolve", "reject", "isInstalled", "response", "__name", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "setInstallState", "result", "checkInstallationOnLoad", "info", "namespace", "versions", "__name", "defineVersions", "buildProvider"]
7
+ }
@@ -0,0 +1,5 @@
1
+ import type { SendPaymentRequest, SetTrustlineRequest } from '@gemwallet/api';
2
+ import type { XrplPaymentTransactionData, XrplTrustSetTransactionData } from 'rango-types/mainApi';
3
+ export declare function fromTrustSetTransactionDataToGemWalletRequest(data: XrplTrustSetTransactionData): SetTrustlineRequest;
4
+ export declare function fromPaymentTransactionDataToGemWalletRequest(data: XrplPaymentTransactionData): SendPaymentRequest;
5
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/namespaces/xrpl/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,0BAA0B,EAG1B,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AA4C7B,wBAAgB,6CAA6C,CAC3D,IAAI,EAAE,2BAA2B,GAChC,mBAAmB,CAMrB;AAED,wBAAgB,4CAA4C,CAC1D,IAAI,EAAE,0BAA0B,GAC/B,kBAAkB,CAqBpB"}
@@ -0,0 +1,3 @@
1
+ import type { XRPLActions } from '@rango-dev/wallets-core/namespaces/xrpl';
2
+ export declare function changeAccountSubscriberBuilder(): [import("@rango-dev/wallets-core").Subscriber<XRPLActions>, import("@rango-dev/wallets-core").SubscriberCleanUp<XRPLActions>];
3
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/namespaces/xrpl/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAY3E,wBAAgB,8BAA8B,kIAsB7C"}
@@ -0,0 +1,3 @@
1
+ export { namespace } from './namespace.js';
2
+ export { Signer } from './singer.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/xrpl/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { XRPLActions } from '@rango-dev/wallets-core/namespaces/xrpl';
2
+ export declare const namespace: import("@rango-dev/wallets-core").ProxiedNamespace<XRPLActions>;
3
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../src/namespaces/xrpl/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AA2D3E,eAAO,MAAM,SAAS,iEAIZ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { XrplTransaction } from 'rango-types/mainApi';
2
+ import { type GenericSigner } from 'rango-types';
3
+ export declare class Signer implements GenericSigner<XrplTransaction> {
4
+ signMessage(): Promise<string>;
5
+ signAndSendTx(tx: XrplTransaction): Promise<{
6
+ hash: string;
7
+ }>;
8
+ }
9
+ //# sourceMappingURL=singer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singer.d.ts","sourceRoot":"","sources":["../../../src/namespaces/xrpl/singer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,KAAK,aAAa,EAAe,MAAM,aAAa,CAAC;AAO9D,qBAAa,MAAO,YAAW,aAAa,CAAC,eAAe,CAAC;IACrD,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,aAAa,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CA6CpE"}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/namespaces/xrpl/hooks.ts":{"bytes":1228,"imports":[{"path":"@gemwallet/api","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/xrpl","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/xrpl/namespace.ts":{"bytes":1867,"imports":[{"path":"@gemwallet/api","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/xrpl","kind":"import-statement","external":true},{"path":"xrpl","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../../constants.js"},{"path":"src/namespaces/xrpl/hooks.ts","kind":"import-statement","original":"./hooks.js"}],"format":"esm"},"src/namespaces/xrpl/helpers.ts":{"bytes":2544,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/xrpl/singer.ts":{"bytes":1674,"imports":[{"path":"@gemwallet/api","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/namespaces/xrpl/helpers.ts","kind":"import-statement","original":"./helpers.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/xrpl/mod.ts":{"bytes":82,"imports":[{"path":"src/namespaces/xrpl/namespace.ts","kind":"import-statement","original":"./namespace.js"},{"path":"src/namespaces/xrpl/singer.ts","kind":"import-statement","original":"./singer.js"}],"format":"esm"},"src/signer.ts":{"bytes":398,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/namespaces/xrpl/mod.ts","kind":"dynamic-import","original":"./namespaces/xrpl/mod.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/constants.ts":{"bytes":1083,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"}],"format":"esm"},"src/utils.ts":{"bytes":435,"imports":[{"path":"@gemwallet/api","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/provider.ts":{"bytes":631,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"src/namespaces/xrpl/mod.ts","kind":"import-statement","original":"./namespaces/xrpl/mod.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mod.ts":{"bytes":220,"imports":[{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"src/provider.ts","kind":"import-statement","original":"./provider.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/mod.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":17069},"dist/mod.js":{"imports":[{"path":"@gemwallet/api","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/xrpl","kind":"import-statement","external":true},{"path":"@gemwallet/api","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/xrpl","kind":"import-statement","external":true},{"path":"xrpl","kind":"import-statement","external":true},{"path":"@gemwallet/api","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@gemwallet/api","kind":"import-statement","external":true}],"exports":["versions"],"entryPoint":"src/mod.ts","inputs":{"src/namespaces/xrpl/hooks.ts":{"bytesInOutput":460},"src/namespaces/xrpl/namespace.ts":{"bytesInOutput":990},"src/namespaces/xrpl/helpers.ts":{"bytesInOutput":1061},"src/namespaces/xrpl/singer.ts":{"bytesInOutput":868},"src/namespaces/xrpl/mod.ts":{"bytesInOutput":81},"src/signer.ts":{"bytesInOutput":241},"src/constants.ts":{"bytesInOutput":563},"src/mod.ts":{"bytesInOutput":123},"src/provider.ts":{"bytesInOutput":262},"src/utils.ts":{"bytesInOutput":219}},"bytes":5100}}}
@@ -0,0 +1,3 @@
1
+ declare const buildProvider: () => import("@rango-dev/wallets-core").Provider;
2
+ export { buildProvider };
3
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,aAAa,kDAWP,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SignerFactory } from 'rango-types';
2
+ export default function getSigners(): Promise<SignerFactory>;
3
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,wBAA8B,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAKjE"}
@@ -0,0 +1,2 @@
1
+ export declare function checkInstallationOnLoad(): Promise<boolean>;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC,CAchE"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@rango-dev/provider-gemwallet",
3
+ "version": "0.1.1-next.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "source": "./src/mod.ts",
7
+ "main": "./dist/mod.js",
8
+ "exports": {
9
+ ".": "./dist/mod.js"
10
+ },
11
+ "typings": "dist/mod.d.ts",
12
+ "files": [
13
+ "dist",
14
+ "src"
15
+ ],
16
+ "scripts": {
17
+ "build": "node ../../scripts/build/command.mjs --path wallets/provider-gemwallet --inputs src/mod.ts",
18
+ "ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
19
+ "clean": "rimraf dist",
20
+ "format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
21
+ "lint": "eslint \"**/*.{ts,tsx}\""
22
+ },
23
+ "dependencies": {
24
+ "@gemwallet/api": "^3.8.0",
25
+ "@rango-dev/wallets-shared": "^0.58.1-next.3",
26
+ "rango-types": "^0.1.95",
27
+ "xrpl": "^4.2.0"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
32
+ }
package/readme.md ADDED
@@ -0,0 +1,18 @@
1
+ # GemWallet Provider
2
+ GemWallet integration for hub.
3
+ [Homepage](https://gemwallet.app/) | [Docs](https://gemwallet.app/docs/user-guide/introduction)
4
+
5
+ More about implementation status can be found [here](../readme.md).
6
+
7
+ ## Implementation notes/limitation
8
+
9
+ ### Feature
10
+
11
+ #### ⚠️ Auto Connect
12
+
13
+ It doesn't have the feature to silently connect to wallet, it shows a popup and a loading for a few seconds.
14
+
15
+
16
+ ---
17
+
18
+ More wallet information can be found in [readme.md](../readme.md).
@@ -0,0 +1,40 @@
1
+ import type { ProviderMetadata } from '@rango-dev/wallets-core';
2
+ import type { BlockchainMeta } from 'rango-types';
3
+
4
+ import { xrplBlockchain } from 'rango-types';
5
+
6
+ import getSigners from './signer.js';
7
+
8
+ export const XRPL_PUBLIC_SERVER = 'wss://xrplcluster.com/';
9
+ export const WALLET_ID = 'gemwallet';
10
+
11
+ export const info: ProviderMetadata = {
12
+ name: 'GemWallet',
13
+ icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/gemwallet/icon.svg',
14
+ extensions: {
15
+ chrome:
16
+ 'https://chromewebstore.google.com/detail/gemwallet/egebedonbdapoieedfcfkofloclfghab',
17
+ homepage: 'https://gemwallet.app/',
18
+ },
19
+ properties: [
20
+ {
21
+ name: 'namespaces',
22
+ value: {
23
+ selection: 'multiple',
24
+ data: [
25
+ {
26
+ label: 'XRPL',
27
+ value: 'XRPL',
28
+ id: 'XRPL',
29
+ getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
30
+ xrplBlockchain(allBlockchains),
31
+ },
32
+ ],
33
+ },
34
+ },
35
+ {
36
+ name: 'signers',
37
+ value: { getSigners: async () => getSigners() },
38
+ },
39
+ ],
40
+ };
package/src/mod.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { defineVersions } from '@rango-dev/wallets-core/utils';
2
+
3
+ import { buildProvider } from './provider.js';
4
+
5
+ const versions = () =>
6
+ defineVersions().version('1.0.0', buildProvider()).build();
7
+
8
+ export { versions };
@@ -0,0 +1,88 @@
1
+ import type {
2
+ Memo,
3
+ SendPaymentRequest,
4
+ SetTrustlineRequest,
5
+ } from '@gemwallet/api';
6
+ import type {
7
+ XrplPaymentTransactionData,
8
+ XrplTransactionDataIssuedCurrencyAmount,
9
+ XrplTransactionDataMPTAmount,
10
+ XrplTrustSetTransactionData,
11
+ } from 'rango-types/mainApi';
12
+
13
+ function isIssuedCurrencyAmount(
14
+ amount: XrplPaymentTransactionData['Amount']
15
+ ): amount is XrplTransactionDataIssuedCurrencyAmount {
16
+ return (
17
+ typeof amount === 'object' &&
18
+ // @ts-expect-error it never throw an runtime error, since we are checking it should be an object first
19
+ typeof amount.currency === 'string' &&
20
+ // @ts-expect-error it never throw an runtime error, since we are checking it should be an object first
21
+ typeof amount.issuer === 'string' &&
22
+ typeof amount.value === 'string'
23
+ );
24
+ }
25
+
26
+ function isMPTokenAmount(
27
+ amount: XrplPaymentTransactionData['Amount']
28
+ ): amount is XrplTransactionDataMPTAmount {
29
+ return (
30
+ typeof amount === 'object' &&
31
+ // @ts-expect-error it never throw an runtime error, since we are checking it should be an object first
32
+ typeof amount.mpt_issuance_id === 'string' &&
33
+ typeof amount.value === 'string'
34
+ );
35
+ }
36
+
37
+ function fromPaymentTransactionMemoToGemWalletMemo(
38
+ memos: XrplPaymentTransactionData['Memos']
39
+ ): Memo[] {
40
+ if (!memos) {
41
+ return [];
42
+ }
43
+
44
+ return memos.map((memo) => {
45
+ return {
46
+ memo: {
47
+ memoType: memo.Memo.MemoType,
48
+ memoData: memo.Memo.MemoData,
49
+ memoFormat: memo.Memo.MemoFormat,
50
+ },
51
+ };
52
+ });
53
+ }
54
+
55
+ export function fromTrustSetTransactionDataToGemWalletRequest(
56
+ data: XrplTrustSetTransactionData
57
+ ): SetTrustlineRequest {
58
+ return {
59
+ limitAmount: data.LimitAmount,
60
+ memos: fromPaymentTransactionMemoToGemWalletMemo(data.Memos),
61
+ flags: data.Flags,
62
+ };
63
+ }
64
+
65
+ export function fromPaymentTransactionDataToGemWalletRequest(
66
+ data: XrplPaymentTransactionData
67
+ ): SendPaymentRequest {
68
+ let amount: SendPaymentRequest['amount'];
69
+ if (isMPTokenAmount(data.Amount)) {
70
+ throw new Error("Current implemented signer doesn't have support for MPT");
71
+ } else if (isIssuedCurrencyAmount(data.Amount)) {
72
+ amount = data.Amount;
73
+ } else if (typeof data.Amount === 'string') {
74
+ amount = data.Amount;
75
+ } else {
76
+ throw new Error(
77
+ "There is an unexpected type for Amount. current signer doesn't have support for that."
78
+ );
79
+ }
80
+
81
+ return {
82
+ amount,
83
+ destination: data.Destination,
84
+ destinationTag: data.DestinationTag,
85
+ memos: fromPaymentTransactionMemoToGemWalletMemo(data.Memos),
86
+ flags: data.Flags,
87
+ };
88
+ }
@@ -0,0 +1,35 @@
1
+ import type { XRPLActions } from '@rango-dev/wallets-core/namespaces/xrpl';
2
+
3
+ import { on } from '@gemwallet/api';
4
+ import { ChangeAccountSubscriberBuilder } from '@rango-dev/wallets-core/namespaces/common';
5
+ import { utils } from '@rango-dev/wallets-core/namespaces/xrpl';
6
+
7
+ type WalletChangedEventPayload = {
8
+ wallet: {
9
+ publicAddress: string;
10
+ };
11
+ };
12
+
13
+ export function changeAccountSubscriberBuilder() {
14
+ // `true` instead of ProviderAPI is just a workaround. we don't need to have instance here.
15
+ return new ChangeAccountSubscriberBuilder<
16
+ WalletChangedEventPayload,
17
+ true,
18
+ XRPLActions
19
+ >()
20
+ .getInstance(() => true)
21
+ .format(async (_, payload) => [
22
+ utils.formatAddressToCAIP(payload.wallet.publicAddress),
23
+ ])
24
+ .addEventListener((_, callback) => {
25
+ on('walletChanged', callback);
26
+ })
27
+ .removeEventListener((_instance, _callback) => {
28
+ /*
29
+ * TODO: gem wallet doesn't have support for unsubscribing.
30
+ * Making a variable and keep the callback refrence then here make it `undefined` is a quick fix
31
+ * but it makes new bugs, where if two subscribers added at once, we will loose the track of the first one and it will be staled.
32
+ */
33
+ })
34
+ .build();
35
+ }
@@ -0,0 +1,2 @@
1
+ export { namespace } from './namespace.js';
2
+ export { Signer } from './singer.js';
@@ -0,0 +1,64 @@
1
+ import type { XRPLActions } from '@rango-dev/wallets-core/namespaces/xrpl';
2
+
3
+ import { getAddress } from '@gemwallet/api';
4
+ import { ActionBuilder, NamespaceBuilder } from '@rango-dev/wallets-core';
5
+ import {
6
+ builders as commonBuilders,
7
+ standardizeAndThrowError,
8
+ } from '@rango-dev/wallets-core/namespaces/common';
9
+ import { builders, utils } from '@rango-dev/wallets-core/namespaces/xrpl';
10
+ import { Client } from 'xrpl';
11
+
12
+ import { WALLET_ID, XRPL_PUBLIC_SERVER } from '../../constants.js';
13
+
14
+ import { changeAccountSubscriberBuilder } from './hooks.js';
15
+
16
+ const [changeAccountSubscriber, changeAccountCleanup] =
17
+ changeAccountSubscriberBuilder();
18
+
19
+ const connect = builders
20
+ .connect()
21
+ .action(async function () {
22
+ const response = await getAddress();
23
+
24
+ if (response.type === 'reject') {
25
+ throw new Error('User has rejected the request.');
26
+ }
27
+ if (!response.result?.address) {
28
+ throw new Error(`Couldn't access to your wallet address.`);
29
+ }
30
+
31
+ return [utils.formatAddressToCAIP(response.result.address)];
32
+ })
33
+ .before(changeAccountSubscriber)
34
+ .or(changeAccountCleanup)
35
+ .or(standardizeAndThrowError)
36
+ .build();
37
+
38
+ const accountLines = new ActionBuilder<XRPLActions, 'accountLines'>(
39
+ 'accountLines'
40
+ )
41
+ .action(async (_, account, options) => {
42
+ const client = new Client(XRPL_PUBLIC_SERVER);
43
+ await client.connect();
44
+
45
+ const response = await client.request({
46
+ command: 'account_lines',
47
+ ledger_index: 'current',
48
+ account: account,
49
+ peer: options?.peer,
50
+ });
51
+
52
+ await client.disconnect();
53
+ return response.result.lines;
54
+ })
55
+ .build();
56
+ const disconnect = commonBuilders
57
+ .disconnect<XRPLActions>()
58
+ .after(changeAccountCleanup)
59
+ .build();
60
+ export const namespace = new NamespaceBuilder<XRPLActions>('XRPL', WALLET_ID)
61
+ .action(connect)
62
+ .action(accountLines)
63
+ .action(disconnect)
64
+ .build();
@@ -0,0 +1,61 @@
1
+ import type { XrplTransaction } from 'rango-types/mainApi';
2
+
3
+ import { sendPayment, setTrustline } from '@gemwallet/api';
4
+ import { type GenericSigner, SignerError } from 'rango-types';
5
+
6
+ import {
7
+ fromPaymentTransactionDataToGemWalletRequest,
8
+ fromTrustSetTransactionDataToGemWalletRequest,
9
+ } from './helpers.js';
10
+
11
+ export class Signer implements GenericSigner<XrplTransaction> {
12
+ async signMessage(): Promise<string> {
13
+ throw SignerError.UnimplementedError('signMessage');
14
+ }
15
+
16
+ async signAndSendTx(tx: XrplTransaction): Promise<{ hash: string }> {
17
+ if (tx.data.TransactionType === 'TrustSet') {
18
+ const result = await setTrustline(
19
+ fromTrustSetTransactionDataToGemWalletRequest(tx.data)
20
+ );
21
+
22
+ if (result.type === 'reject') {
23
+ throw new Error('The request has been rejected', {
24
+ cause: result,
25
+ });
26
+ }
27
+
28
+ if (!result.result) {
29
+ throw new Error(
30
+ 'Unexpected error where the result is not returned. (type: UnreachableCode)'
31
+ );
32
+ }
33
+
34
+ return {
35
+ hash: result.result.hash,
36
+ };
37
+ } else if (tx.data.TransactionType === 'Payment') {
38
+ const result = await sendPayment(
39
+ fromPaymentTransactionDataToGemWalletRequest(tx.data)
40
+ );
41
+
42
+ if (result.type === 'reject') {
43
+ throw new Error('The request has been rejected', {
44
+ cause: result,
45
+ });
46
+ }
47
+
48
+ if (!result.result) {
49
+ throw new Error(
50
+ 'Unexpected error where the result is not returned. (type: UnreachableCode)'
51
+ );
52
+ }
53
+
54
+ return {
55
+ hash: result.result.hash,
56
+ };
57
+ }
58
+
59
+ throw new Error('Unsupported transaction type');
60
+ }
61
+ }
@@ -0,0 +1,20 @@
1
+ import { ProviderBuilder } from '@rango-dev/wallets-core';
2
+
3
+ import { info, WALLET_ID } from './constants.js';
4
+ import { namespace as xrpl } from './namespaces/xrpl/mod.js';
5
+ import { checkInstallationOnLoad } from './utils.js';
6
+
7
+ const buildProvider = () =>
8
+ new ProviderBuilder(WALLET_ID)
9
+ .init(function (context) {
10
+ const [, setState] = context.state();
11
+ const setInstallState = (result: boolean) =>
12
+ setState('installed', result);
13
+
14
+ checkInstallationOnLoad().then(setInstallState).catch(console.error);
15
+ })
16
+ .config('metadata', info)
17
+ .add('xrpl', xrpl)
18
+ .build();
19
+
20
+ export { buildProvider };
package/src/signer.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { SignerFactory } from 'rango-types';
2
+
3
+ import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
4
+
5
+ export default async function getSigners(): Promise<SignerFactory> {
6
+ const { Signer: XrplSigner } = await import('./namespaces/xrpl/mod.js');
7
+ const signers = new DefaultSignerFactory();
8
+ signers.registerSigner(TxType.XRPL, new XrplSigner());
9
+ return signers;
10
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { isInstalled } from '@gemwallet/api';
2
+
3
+ export async function checkInstallationOnLoad(): Promise<boolean> {
4
+ return new Promise((resolve, reject) => {
5
+ window.addEventListener('load', () => {
6
+ isInstalled()
7
+ .then((response) => {
8
+ if (response.result.isInstalled) {
9
+ resolve(true);
10
+ } else {
11
+ resolve(false);
12
+ }
13
+ })
14
+ .catch(reject);
15
+ });
16
+ });
17
+ }