Skip to content

Commit d9544ce

Browse files
committed
chore(ts-sdk-sui): added new functions
Signed-off-by: kaancaglan <[email protected]>
1 parent 1b72804 commit d9544ce

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

ts-sdk-sui/src/Sui.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export const readCoinBalances = (contractAddress: string, address: string) =>
387387
})
388388
return coins
389389
})
390-
390+
391391
export const getAllCoinsUnique = (address: string) =>
392392
Effect.gen(function*() {
393393
const client = (yield* PublicClient).client
@@ -430,6 +430,58 @@ export const readCoinBalances = (contractAddress: string, address: string) =>
430430
return result
431431
})
432432

433+
export const getCoinName = (address: string) =>
434+
Effect.gen(function*() {
435+
const client = (yield* PublicClient).client
436+
437+
const name = yield* Effect.tryPromise({
438+
try: async () => {
439+
const result = await client.getCoinMetadata({ coinType: address })
440+
return result?.name
441+
},
442+
catch: err =>
443+
new ReadCoinError({
444+
cause: extractErrorDetails(err as ReadCoinError),
445+
}),
446+
})
447+
return name
448+
})
449+
450+
export const getCoinDecimals = (address: string) =>
451+
Effect.gen(function*() {
452+
const client = (yield* PublicClient).client
453+
454+
const decimals = yield* Effect.tryPromise({
455+
try: async () => {
456+
const result = await client.getCoinMetadata({ coinType: address })
457+
return result?.decimals
458+
},
459+
catch: err =>
460+
new ReadCoinError({
461+
cause: extractErrorDetails(err as ReadCoinError),
462+
}),
463+
})
464+
return decimals
465+
})
466+
467+
export const readCoinSymbol = (address: string) =>
468+
Effect.gen(function*() {
469+
const client = (yield* PublicClient).client
470+
471+
const symbol = yield* Effect.tryPromise({
472+
try: async () => {
473+
const result = await client.getCoinMetadata({ coinType: address })
474+
return result?.symbol
475+
},
476+
catch: err =>
477+
new ReadCoinError({
478+
cause: extractErrorDetails(err as ReadCoinError),
479+
}),
480+
})
481+
return symbol
482+
})
483+
484+
433485
// /**
434486
// * Read the balance of an ERC20 token for a specific address
435487
// *

0 commit comments

Comments
 (0)